In my Spring project, I set the logout destination URL to "/ login? Logout" to display the login page with the message "You are logged out."
In the Spring Security configurator, I did the following:
@Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .authorizeRequests() .antMatchers("/error").permitAll() .anyRequest().fullyAuthenticated() .and() .formLogin() .loginPage("/login") .permitAll() .successHandler(loginSuccessHandler) .failureUrl("/login?error") .and() .httpBasic() .and() .logout() .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .permitAll() .logoutSuccessHandler(logoutSuccessHandler); }
And logoutSuccessHandler:
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { if (authentication != null) { Log.debug(authentication.getName() + " LOGOUT !!"); } setDefaultTargetUrl("/login?logout"); super.onLogoutSuccess(request, response, authentication); }
When I try to log out, I come to the "/ login" page (without logging out). I don’t understand why it redirects me to this page.
I think the application is trying to redirect me to "/ login? Logout", but since I'm no longer connected, Spring Security wants me to log in again.
When I try to access the "log logout" page during login, a good page is displayed.
I found a solution to this problem by adding the following:
.authorizeRequests() .antMatchers("/error","/login").permitAll()
Why doesn't loginPage("/login").permitAll() do this? Did I do something wrong?
java spring spring-security
Ylombardi
source share