You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good Morning. I am sharing a combination of checks which are working and which are not. Ideally, your code, as per the video should work for Spring Boot 3.1.2
PS: I am using Spring Cloud Config
NOT WORKING
(1) With requestMatcher(UN_SECURED_URLs).permitAll()
(2) With direct URL/ indirect URL
(3) With WebSecurityCustomizer @bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
// .requestMatchers(UN_SECURED_URLs).permitAll()
// .requestMatchers(SECURED_URLs).authenticated()
.anyRequest().authenticated()) // permitAll())
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class)
.logout(logout -> logout
.logoutUrl("/security/api/v1/logout").addLogoutHandler(logoutHandler)
.logoutSuccessHandler((request, response, authentication) -> SecurityContextHolder.clearContext())
.logoutSuccessUrl("http://nopaper.work"))
.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().requestMatchers(UN_SECURED_URLs);
}
Good Morning. I am sharing a combination of checks which are working and which are not. Ideally, your code, as per the video should work for Spring Boot 3.1.2
PS: I am using Spring Cloud Config
NOT WORKING
(1) With requestMatcher(UN_SECURED_URLs).permitAll()
(2) With direct URL/ indirect URL
(3) With WebSecurityCustomizer
@bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
// .requestMatchers(UN_SECURED_URLs).permitAll()
// .requestMatchers(SECURED_URLs).authenticated()
.anyRequest().authenticated()) // permitAll())
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class)
.logout(logout -> logout
.logoutUrl("/security/api/v1/logout").addLogoutHandler(logoutHandler)
.logoutSuccessHandler((request, response, authentication) -> SecurityContextHolder.clearContext())
.logoutSuccessUrl("http://nopaper.work"))
.build();
}
WORKING:
(1) With anyRequest - Permit All
return http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
// .requestMatchers(UN_SECURED_URLs).permitAll()
// .requestMatchers(SECURED_URLs).authenticated()
.anyRequest().permitAll()) // WORKING
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class)
.logout(logout -> logout
.logoutUrl("/security/api/v1/logout").addLogoutHandler(logoutHandler)
.logoutSuccessHandler((request, response, authentication) -> SecurityContextHolder.clearContext())
.logoutSuccessUrl("http://nopaper.work"))
.build();
}
(2) With requestMatchers("/**") - Permit All
return http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
// .requestMatchers(UN_SECURED_URLs).permitAll()
// .requestMatchers(SECURED_URLs).authenticated()
.anyRequest().permitAll()) // WORKING
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class)
.logout(logout -> logout
.logoutUrl("/security/api/v1/logout").addLogoutHandler(logoutHandler)
.logoutSuccessHandler((request, response, authentication) -> SecurityContextHolder.clearContext())
.logoutSuccessUrl("http://nopaper.work"))
.build();
}
The text was updated successfully, but these errors were encountered: