有一个模块,其中启用了 spring 安全性。在这个模块中有这个配置允许我执行单点登录和 将登录的用户保存在内存中。在 customSuccessHandler 中,我更改令牌的值并保存它(覆盖 sso 返回的令牌)。然后我将新令牌发送到 Angular 页面。
@Configuration
@EnableWebSecurity(debug = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler;
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().and().cors().disable().authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
.redirectionEndpoint()
.baseUri("/baseUri")
.and()
.authorizationEndpoint()
.baseUri("/oauth2/authorize")
.authorizationRequestRepository(customAuthorizationRequestRepository())
.and()
.successHandler(customAuthenticationSuccessHandler);
}
@Bean
public AuthorizationRequestRepository<OAuth2AuthorizationRequest> customAuthorizationRequestRepository() {
return new HttpSessionOAuth2AuthorizationRequestRepository();
}
}
现在有另一个模块包含一些我想要保护的 API。我想发送之前的令牌(来自 angular)并验证它发送到存储用户信息(访问令牌、委托人等)的模块。
实际上,如果我不更改令牌(所以我使用 sso 返回的令牌),我可以通过设置属性来自动验证它:
spring.security.oauth2.resourceserver.jwt.jwk-set-uri= https://example.provider.com/oauth2/key/jwks
我可以在我的服务器上复制类似的东西吗?