Я настроил Spring Security для обработки системы входа / выхода из системы.
Если я войду в систему, а затем выйду из системы в течение 30 минут ( до истечения сеанса ), выход из системы будет работать.
Если я войду в систему, а затем выйду из системы через 31 минуту ( после истечения сеанса ), я получу эту ошибку в браузере:
HTTP Status 405 ? Method Not Allowed
Type Status Report
Message Request method 'POST' not supported
Description The method received in the request-line is known by the origin server but not supported by the target resource.
Кажется, проблема в CSRF система.В моей конфигурации включен, и я выполняю выход с помощью POST триггер запроса с помощью кнопки отправки.Так как система CSRF включена, внутри моих форм у меня есть эта строка:
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
Если я отключаю систему CSRF, все работает хорошо, и у меня нет ошибки, если я нажимаю кнопку выхода из системы после истечения сеанса.
Это мой класс конфигурации:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.formLogin()
.loginPage("/login")
.usernameParameter("userId")
.passwordParameter("password");
httpSecurity.formLogin()
.defaultSuccessUrl("/")
.failureHandler(new CustomAuthenticationFailureHandler());
httpSecurity.logout()
.logoutSuccessUrl("/login?logout");
httpSecurity.exceptionHandling()
.accessDeniedPage("/login?accessDenied");
httpSecurity.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/**/add").access("hasRole('ADMIN')")
.antMatchers("/**/market/**").access("hasRole('USER')");
}
}
Вот как я выполняю выход из системы:
<form method="post" action="<c:url value="/logout" />">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="submit" value="Logout">
</form>
Кто-нибудь нашел решение этой проблемы?
Спасибо