Не вызывается onLogoutSuccess для SimpleUrlLogoutSuccessHandle - PullRequest
1 голос
/ 26 января 2020
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Autowired
    private DataSource dataSource; // get by Spring

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            // Here, you are making the public directory on the classpath root available without authentication (e..g. for css files)
            .antMatchers("/public/**", "/registration.html").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login.html")
            .successHandler((request, response, authentication) -> new DefaultRedirectStrategy().sendRedirect(request, response, "/welcome"))
            .failureUrl("/login-error.html")
            .permitAll()
            .and()
            .logout()
            .logoutSuccessHandler(new CustomLogoutSuccessHandler())
            .permitAll();
    }
}

Вот мой пользовательский обработчик: CustomLogoutSuccessHandler. java

public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler implements LogoutSuccessHandler {
    private static Logger logger = LogManager.getLogger(CustomLogoutSuccessHandler.class);

    @Override
    public void onLogoutSuccess(
            HttpServletRequest request,
            HttpServletResponse response,
            Authentication authentication)
            throws IOException, ServletException {
        logger.info("onLogoutSuccess:");
        response.sendRedirect(request.getContextPath() + "/login.html");
    }
}

В моем шаблоне (users.html) я добавляю такую ​​ссылку:

<p align="center"><a th:href="@{/logout.html}">Logout</a></p>

Но когда вы нажимаете на ссылку выхода из системы, метод onLogoutSuccess не вызывается в моем пользовательском классе обработчика.

Почему?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...