forked from mtusi2026/mtusi2026lab2
add public swagger ui
This commit is contained in:
@@ -77,6 +77,11 @@ public class SecurityConfig {
|
|||||||
.authenticationEntryPoint(bearerAuthenticationEntryPoint))
|
.authenticationEntryPoint(bearerAuthenticationEntryPoint))
|
||||||
.authorizeHttpRequests(authorize -> authorize
|
.authorizeHttpRequests(authorize -> authorize
|
||||||
.requestMatchers(HttpMethod.GET, "/health/**").permitAll()
|
.requestMatchers(HttpMethod.GET, "/health/**").permitAll()
|
||||||
|
.requestMatchers(
|
||||||
|
"/swagger-ui.html",
|
||||||
|
"/swagger-ui/**",
|
||||||
|
"/v3/api-docs/**"
|
||||||
|
).permitAll()
|
||||||
.requestMatchers(HttpMethod.POST, "/api/v1/users").permitAll()
|
.requestMatchers(HttpMethod.POST, "/api/v1/users").permitAll()
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.addFilterBefore(apiAuthenticationFilter, AnonymousAuthenticationFilter.class);
|
.addFilterBefore(apiAuthenticationFilter, AnonymousAuthenticationFilter.class);
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ public class ApiAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
private boolean isPublicRequest(HttpServletRequest request) {
|
private boolean isPublicRequest(HttpServletRequest request) {
|
||||||
String path = request.getRequestURI();
|
String path = request.getRequestURI();
|
||||||
return path.startsWith("/health/")
|
return path.startsWith("/health/")
|
||||||
|
|| path.equals("/swagger-ui.html")
|
||||||
|
|| path.startsWith("/swagger-ui/")
|
||||||
|
|| path.equals("/v3/api-docs")
|
||||||
|
|| path.startsWith("/v3/api-docs/")
|
||||||
|| (HttpMethod.POST.matches(request.getMethod())
|
|| (HttpMethod.POST.matches(request.getMethod())
|
||||||
&& "/api/v1/users".equals(path));
|
&& "/api/v1/users".equals(path));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user