【发布时间】:2016-11-11 10:28:30
【问题描述】:
通过自动注销,我的意思是当会话到期时,浏览器将自行重定向到注销 url,而用户无需单击任何将他重定向到注销 url 的链接。
这是我的安全配置:
导入 org.springframework.beans.factory.annotation.Autowired;导入 org.springframework.boot.autoconfigure.security.SecurityProperties;导入 org.springframework.context.annotation.Bean;导入 org.springframework.context.annotation.Configuration;导入 org.springframework.core.annotation.Order;导入 org.springframework.security.access.vote.RoleVoter;导入 org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;导入 org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;导入 org.springframework.security.config.annotation.web.builders.HttpSecurity;导入 org.springframework.security.config.annotation.web.builders.WebSecurity;导入 org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;导入 org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;导入 org.springframework.security.config.http.SessionCreationPolicy;
/** * Created by plato on 5/5/2016. */
@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 公共类 SecurityConfig 扩展 WebSecurityConfigurerAdapter {
@Autowired
DatabaseAuthenticationProvider authenticationProvider;
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/js/**", "/css/**", "/img/**", "/templates/**", "/thymeleaf/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin()
.loginPage("/login")
.failureUrl("/login?failed=true")
.defaultSuccessUrl("/login-success")
.and().logout()
.logoutSuccessUrl("/")
.and().authorizeRequests()
.antMatchers("/admin**", "/api/admin/**").hasAuthority("ADMIN")
.antMatchers("/**")
.permitAll()
.anyRequest().authenticated()
.and().csrf().disable()
.sessionManagement()
.maximumSessions(1)
.expiredUrl("/login?expired-session")
.and()
.invalidSessionUrl("/?invalid-session");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider).eraseCredentials(true);
}
}
【问题讨论】:
-
会话已超时,没有更多信息,您希望注销后会发生什么?
标签: java spring spring-security spring-boot