【问题标题】:How to Logout from Oauth2 SSO Server如何从 Oauth2 SSO 服务器注销
【发布时间】:2015-07-09 15:43:28
【问题描述】:

我找到了关于 SSO https://github.com/dsyer/spring-security-angular/tree/master/oauth2 配置的教程

oauth2-authserver

@Configuration
@Order(-10)
protected static class LoginConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http
            .formLogin().loginPage("/login").permitAll()
        .and()
            .requestMatchers().antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
        .and()
            .authorizeRequests().anyRequest().authenticated()
            .and().sessionManagement();
        // @formatter:on
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.parentAuthenticationManager(authenticationManager);
    }
}

oauth2-ui

@Override
    public void configure(HttpSecurity http) throws Exception {
        http.logout().and().antMatcher("/**").authorizeRequests()
                .antMatchers("/index.html", "/home.html", "/", "/login").permitAll()
                .anyRequest().authenticated().and().csrf()
                .csrfTokenRepository(csrfTokenRepository()).and()
                .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);
    }

我的 authserver 只需要一次登录验证,所以当用户已经通过身份验证并重定向到 oauth2-ui 应用程序时,服务器中的身份验证登录已过期。 所以当 oauth2-ui 中的用户注销并再次尝试登录时,用户必须再次输入用户名和密码,因为服务器中的身份验证已过期。

对不起,我的英语不好,提前谢谢!

【问题讨论】:

    标签: java single-sign-on spring-security-oauth2 spring-cloud


    【解决方案1】:

    如果您阅读博客https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-v,它实际上解释了实现与您正在执行的相同类型安全性的方式(实际上您只是实现了几乎相同的 jwt 版本。如果您想要实际的代码博客使用同一 repo 的 oauth2-vanilla 版本)......最后,明确指出“这是一个臭名昭著的棘手问题”(如博客中所写)。实际上,同一系列博客有一个新版本可以解决您的问题https://github.com/dsyer/spring-security-angular/tree/master/double。在这里,您可以看到如何在 spring-session 和实际存储会话的 redis 服务器的帮助下实现注销。一切顺利!如有任何澄清,请随时联系

    【讨论】:

    • 谢谢你的帮助,我实际上是使用双项目实现的!
    • “臭名昭著的棘手问题”可能是真的,但事实是,如果您使用最基本的 Spring Boot MVC 应用程序添加注销链接以发布到 /logout,您将无法获得本地注销(忘记全局注销)。
    猜你喜欢
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 2010-12-12
    • 1970-01-01
    相关资源
    最近更新 更多