33import org .springframework .context .annotation .Bean ;
44import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
55import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
6- import org .springframework .security .config .annotation .web .configuration .WebSecurityCustomizer ;
76import org .springframework .security .config .http .SessionCreationPolicy ;
87import org .springframework .security .core .userdetails .User ;
98import org .springframework .security .core .userdetails .UserDetails ;
1211
1312@ EnableWebSecurity
1413public class SecurityConfig {
14+ private static final String [] PERMITTED_PATTERNS = {
15+ "/api/swagger/**" ,
16+ "/api/swagger-ui/**" ,
17+ "/api/swagger-ui.html" ,
18+ "/api/swagger-ui-custom.html" ,
19+ "/webjars/**" ,
20+ "/api/swagger-resources/**" ,
21+ "/api/configuration/**" ,
22+ "/api/api-docs/**"
23+ };
24+
25+ private static final String COMMON_ROLE = "ROLE_USER" ;
26+
27+ private static final String COMMON_PASSWORD = "{noop}secret" ;
28+
1529 @ Bean
1630 public SecurityFilterChain securityFilterChain (final HttpSecurity http ) throws Exception {
1731 http
1832 .csrf ().disable ()
19- .authorizeRequests ().anyRequest ().authenticated ()
33+ .authorizeRequests ()
34+ .antMatchers (PERMITTED_PATTERNS ).permitAll ()
35+ .anyRequest ().authenticated ()
2036 .and ()
2137 .httpBasic ()
2238 .and ()
@@ -29,35 +45,25 @@ public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws E
2945 @ Bean
3046 public InMemoryUserDetailsManager userDetailsManager () {
3147 final UserDetails paul = User .withUsername ("paul" )
32- .password ("{noop}secret" )
33- .authorities ("ROLE_USER" )
48+ .password (COMMON_PASSWORD )
49+ .authorities (COMMON_ROLE )
3450 .build ();
3551
3652 final UserDetails john = User .withUsername ("john" )
37- .password ("{noop}secret" )
38- .authorities ("ROLE_USER" )
53+ .password (COMMON_PASSWORD )
54+ .authorities (COMMON_ROLE )
3955 .build ();
4056
4157 final UserDetails ringo = User .withUsername ("ringo" )
42- .password ("{noop}secret" )
43- .authorities ("ROLE_USER" )
58+ .password (COMMON_PASSWORD )
59+ .authorities (COMMON_ROLE )
4460 .build ();
4561
4662 final UserDetails george = User .withUsername ("george" )
47- .password ("{noop}secret" )
48- .authorities ("ROLE_USER" )
63+ .password (COMMON_PASSWORD )
64+ .authorities (COMMON_ROLE )
4965 .build ();
5066
5167 return new InMemoryUserDetailsManager (paul , john , ringo , george );
5268 }
53-
54- @ Bean
55- public WebSecurityCustomizer webSecurityCustomizer () {
56- return web -> web
57- .ignoring ()
58- .antMatchers ("/" )
59- .antMatchers ("/api/swagger/**”,”/api/swagger-ui/**”,”/api/swagger-ui.html”," +
60- "/api/swagger-ui-custom.html" , "/webjars/**" , "/api/swagger-resources/**" ,
61- "/api/configuration/**”, ”/api/api-docs/**" );
62- }
6369}
0 commit comments