代码
@EnableOAuth2Sso // 开启单点登录功能
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
登出
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
// 首页所有人都可以访问
.antMatchers("/").permitAll()
//其他要认证后才可以访问,如 /member
.anyRequest().authenticated()
.and()
.logout()
//当前应用退出后,会交给某个处理
// 请求认证服务器将用户进行退出
.logoutSuccessUrl("http://localhost:7001/auth/logout")
.and()
.csrf().disable()
;
}
在核心配置类加入@EnableOAuth2Sso注解即可
注意:@EnableOAuth2Sso注解的单点登录是基于session的 这样token过期也不会掉线 只有清除掉浏览器中的session才会失效 所以并不是特别好用 不建议使用