@Override
protected void configure(HttpSecurity http) throws Exception {
http
......
.authorizeRequests()
.antMatchers("/logout_success").permitAll()
.anyRequest()
.authenticated()
.and()
.logout()
.logoutSuccessHandler(customLogoutSuccessHandler())
.permitAll()
......
}
......
public LogoutSuccessHandler customLogoutSuccessHandler() {
CustomLogoutSuccessHandler customLogoutSuccessHandler = new CustomLogoutSuccessHandler();
customLogoutSuccessHandler.setDefaultTargetUrl("/logout_success");
//邮件服务
customLogoutSuccessHandler.setEmailService(emailService);
customLogoutSuccessHandler.setSmsService(smsService);
customLogoutSuccessHandler.setWeChatService(weChatService);
return customLogoutSuccessHandler;
}
......
注意 antMatchers("/logout_success").permitAll() 的顺序,一定要放在 anyRequest().authenticated() 之前。