当我想要注销时,我调用此代码:
request.getSession().invalidate();
SecurityContextHolder.getContext().setAuthentication(null);
Run Code Online (Sandbox Code Playgroud)
但在它之后(在使用旧的oauth令牌的下一个请求中)我调用
SecurityContextHolder.getContext().getAuthentication();
我在那里看到我的老用户
怎么解决?
我正在尝试使用 Spring-boot 和 Dave Syer 示例通过 Spring Security Oauth2 实现 sso
我想使用我的自定义服务器提供商,它运行良好。
对于客户端,我希望用户在尝试访问客户端站点(例如 localhost:8080/)时进行身份验证(因此重定向到 OAuth2 url)并在身份验证后重定向回 index.html 文件。我还想在用户访问 index.html 文件中的链接时实现注销。
我想出了以下客户端 sso 客户端:
包 org.ikane; 导入 java.io.IOException; 导入 java.security.Principal; 导入 java.util.Arrays; 导入 javax.servlet.Filter; 导入 javax.servlet.FilterChain; 导入 javax.servlet.ServletException; 导入 javax.servlet.http.Cookie; 导入 javax.servlet.http.HttpServletRequest; 导入 javax.servlet.http.HttpServletResponse; 导入 org.apache.commons.lang3.StringUtils; 导入 org.slf4j.Logger; 导入 org.slf4j.LoggerFactory; 导入 org.springframework.boot.CommandLineRunner; 导入 org.springframework.boot.SpringApplication; 导入 org.springframework.boot.autoconfigure.SpringBootApplication; 导入 org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 导入 org.springframework.context.ConfigurableApplicationContext; 导入 org.springframework.core.env.ConfigurableEnvironment; 导入 org.springframework.security.config.annotation.web.builders.HttpSecurity; 导入 org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 导入 org.springframework.security.core.Authentication; 导入 org.springframework.security.core.context.SecurityContext; 导入 org.springframework.security.core.context.SecurityContextHolder; 导入 org.springframework.security.web.csrf.CsrfFilter; 导入 org.springframework.security.web.csrf.CsrfToken; 导入 org.springframework.security.web.csrf.CsrfTokenRepository; 导入 …
spring-security single-sign-on spring-boot spring-security-oauth2
参考oauth2 spring-guides项目中的注销流程,一旦用户首次使用用户名/密码进行了身份验证,则注销后下次将不要求提供凭据。
如何确保每次注销后都要求输入用户名/密码。
这就是我要实现的:
OAuth2服务器使用具有自动批准功能的“ authorization_code”授予类型发布JWT令牌。这具有html / angularjs表单来收集用户名/密码。
UI / Webfront-使用@EnableSSO。其所有端点均已通过身份验证,即,它没有用户单击以转到/ uaa服务器的任何未经授权的登录页面/ ui /链接。因此,点击http:// localhost:8080会 立即将您重定向到http:// localhost:9999 / uaa并显示自定义表单以收集用户名/密码。
使用上述方法,我无法锻炼注销流程。到UI应用程序的HTTP POST / logout清除了UI应用程序中的会话/身份验证,但用户再次自动登录(因为我选择了所有范围的自动批准),而无需再次询问用户名密码。
查看日志和网络呼叫,似乎所有“ oauth舞动”都成功地再次发生,而无需再次要求用户输入用户名/密码,并且似乎auth服务器记住了为客户端发布的最后一个auth令牌(使用org.springframework .security.oauth2.provider.code.InMemoryAuthorizationCodeServices?)。
我如何告诉认证服务器每次要求输入用户名/密码的代码/令牌-无状态。
还是在给定方案中实现注销的最佳方法是什么。
(要重新创建一些接近我的要求的内容,请permitAll()从UiApplication中删除一部分,然后autoApproval在上述启动项目的身份验证服务器中进行配置。)