I have a Spring Boot application with the following configuration
@Configuration
@EnableWebSecurity
open class WebSecurityConfig : WebSecurityConfigurerAdapter() {
override fun configure(http:HttpSecurity) {
http
.authorizeRequests()
.antMatchers("/css/**", "/js/**", "/fonts/**")
.permitAll().and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.logout()
.logoutSuccessUrl("/login")
.permitAll()
.and().csrf().disable()
}
@Autowired
fun configureGlobal(auth:AuthenticationManagerBuilder) {
auth
.inMemoryAuthentication()
.withUser("[email protected]").password("test").roles("USER")
}
}
When I try to log out, I get the error
There was an unexpected error (type=Method Not Allowed, status=405). Request method 'POST' not supported
How can I fix it?
How to reproduce
gradle bootRunhttp://localhost:8080, enter [email protected] and test as user name and password, respectively.Update 1: This doesn't work, either.
http
.authorizeRequests()
.antMatchers("/css/**", "/js/**", "/fonts/**", "/logout")
.permitAll().and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf().disable()
I'm not familiar with Thymeleaf, but at least this will give you some idea.
The problem is not your SecurityConfig but the
th:action="@{/logout}"
(not redirect to /logout, check Network tab in Chrome or Firefox).
If I replace it with
action="/logout"
Then it work perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With