Skip to content

Commit

Permalink
Swagger with Spring Security 3
Browse files Browse the repository at this point in the history
  • Loading branch information
abh1navv committed Oct 9, 2024
1 parent 3419a7a commit e94deaa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package com.baeldung.swagger.config;//package com.baeldung.swagger.config;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
//import org.springframework.security.web.SecurityFilterChain;
//
//
//@Configuration
////@EnableWebSecurity
//public class SecurityConfig {
//
// @Bean
// public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//
// http.authorizeHttpRequests(authorizeRequests ->
// authorizeRequests
// .requestMatchers("/swagger-ui/**").permitAll()
// .requestMatchers("/v3/api-docs/**").permitAll()
// );
//
// return http.build();
// }
//
// @Bean
// public WebSecurityCustomizer webSecurityCustomizer() {
// return (web) -> web.ignoring().requestMatchers("/swagger-ui/**", "/v3/api-docs/**");
// }
//
//}
package com.baeldung.swagger.config;package com.baeldung.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.web.SecurityFilterChain;


@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http.authorizeHttpRequests(authorizeRequests ->
authorizeRequests
.requestMatchers("/swagger-ui/**").permitAll()
.requestMatchers("/v3/api-docs/**").permitAll()
);

return http.build();
}

@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().requestMatchers("/swagger-ui/**", "/v3/api-docs/**");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class SwaggerConfig {
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("public")
.pathsToMatch("/**")
.build();
.group("public")
.pathsToMatch("/**")
.build();
}
}

0 comments on commit e94deaa

Please sign in to comment.