While we were using Spring Security 5.xx, SecurityContextHolder.getContext().getAuthentication().getName() was giving user name but after upgrading spring boot to 3.xx which uses spring security core 6.2.2 i am getting result as anonymousUser . This is how i did WebSecurityConfig
`@EnableWebSecurity
@Configuration
public class WebSecurityConfig {
@Bean
protected SecurityFilterChain noSecurity(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
http
.authorizeHttpRequests(authorizeHttpRequests ->
authorizeHttpRequests.requestMatchers(antMatcher("/**")).permitAll());
return http.build();
}
}`
Can someone please help. Not sure how i can bring in same behavior after spring boot upgrade. I have burned days on this one 🙁
I tried giving anonymous() as disabled but then SecurityContextHolder.getContext().getAuthentication() is coming as null