我正在使用Spring OAuth2与SSO架构师一起开发一个Spring Web应用程序
单点登录时一切正常,但我不知道如何单点注销(1 个应用程序注销,其他应用程序也注销)。目前,似乎每个具有 mimium 配置的应用程序(如下面的代码片段)都在使用不同的会话存储,并且在身份验证成功后,它将经过身份验证的会话保存在自己的会话存储中,并且每个后续请求都会被 cookie 中的会话拦截。因此,当 sso 服务器注销时,它无法使其他应用程序会话存储上的相关会话失效。任何人都可以向我建议一些单点注销策略吗?
Web 客户端应用程序.yml 文件:
security:
oauth2:
client:
clientId: metlife_monitor
clientSecret: password
accessTokenUri: http://localhost:8668/sso-server/oauth/token
userAuthorizationUri: http://localhost:8668/sso-server/oauth/authorize
tokenName: oauth_token
resource:
userInfoUri: http://localhost:8688/api/me
Web 应用程序类:
@SpringBootApplication
@EnableOAuth2Sso
@EnableJdbcHttpSession
public class Application extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**", "/error**", "/webjars/**").permitAll()
.anyRequest().authenticated()
.and().logout()
.logoutUrl("/logout")
.logoutSuccessUrl("http://localhost:8668/sso-server/logout")
.invalidateHttpSession(true)
.deleteCookies("client-session", "JSESSIONID")
.permitAll()
.and().csrf().disable()
;
}
public static void main(String[] args) {
SpringApplication.run(App1Application.class, args);
}
}
单点登录(SSO)服务器和中央认证服务器(CAS)是有区别的。如果您的身份验证服务器不管理任何会话,它将不再是SSO服务器,而只是成为CAS。
在您的情况下,您可以让SSO服务器管理会话,它还可以分发会话id,资源服务器将在为请求提供服务之前与其进行验证。不过,这确实导致了一个健谈的系统。如果您可以在会话到期后有一点延迟,那么您可以制作非常短的令牌,这些令牌连接到SSO,并且不必在每次请求时验证令牌,您只需要在仍然有有效会话的情况下刷新令牌。
如果可以,请考虑使用Keycloak。它还具有用于Java和Javascript应用程序的适配器。