gpt4 book ai didi

java - 如何从 Oauth2 SSO 服务器注销

转载 作者:行者123 更新时间:2023-11-30 11:04:39 26 4
gpt4 key购买 nike

我找到了有关 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 中注销并尝试再次登录时,用户必须再次输入用户名和密码,因为服务器中的身份验证已过期。

抱歉我的英语不好,提前致谢!

最佳答案

如果您阅读博客 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 和实际存储您的 session 的 redis 服务器的帮助下实现注销。一切顺利!如有任何疑问,请随时联系

关于java - 如何从 Oauth2 SSO 服务器注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29959255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com