【发布时间】:2017-04-24 22:22:07
【问题描述】:
这是我使用 Spring Boot 和 Spring Security 的代码。问题是当我曾经注销(使用Thymleaf)时,注销对我不起作用。
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private DataSource dataSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select username as principal, password as credentials,active from users where username=?")
.authoritiesByUsernameQuery("select username as principal,roles as role from users_roles where username=?")
.rolePrefix("ROLE_")
.passwordEncoder(new Md5PasswordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/login");
http
.authorizeRequests()
.antMatchers("/index1").permitAll();
http
.authorizeRequests()
.antMatchers("/user").hasRole("USER")
.and()
.logout();
http
.authorizeRequests()
.antMatchers("/adpage").hasRole("ADMIN");
http
.exceptionHandling().accessDeniedPage("/403");
http
.logout().permitAll();
}
}
使用 Thymleaf 链接:
<li><a th:href="@{/login?logout}">logout</a></li>
【问题讨论】:
-
除注销外一切正常,我的意思是当我单击注销链接时会话不会过期,例如我是用户,我注册(登录),因此我注销我仍然得到访问用户页面
-
查看我对stackoverflow.com/questions/40885178/… 的回答。您必须使用 HTTP
POST,并且 URL 仅为/logout。
标签: spring spring-security thymeleaf logout