我有一个具有以下配置的Spring Boot应用程序
@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")
}
}
当我尝试注销时,出现错误
发生意外错误(类型=不允许使用方法,状态= 405)。请求方法“ POST”不受支持
我该如何解决?
如何繁殖
gradle bootRun
http://localhost:8080
,分别输入[email protected]
和test
作为用户名和密码。更新1:这也不起作用。
http
.authorizeRequests()
.antMatchers("/css/**", "/js/**", "/fonts/**", "/logout")
.permitAll().and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf().disable()
我不熟悉Thymeleaf,但至少这会让您有所了解。
问题不是您的SecurityConfig,而是
th:action =“ @ {/ logout}”
(不重定向到/ logout,请在Chrome或Firefox中选中“网络”标签)。
如果我替换为
action =“ / logout”
然后它完美地工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句