java - 资源服务器如何检查我使用 Spring Security 在另一台服务器中创建的 JWT 令牌?
问题描述
有一个模块启用了弹簧安全性。在此模块中,此配置允许我执行单点登录并将登录的用户保存在内存中。在 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。我想发送前一个令牌(来自角度)并验证它发送到存储用户信息(访问令牌、主体等)的模块。
实际上,如果我不更改令牌(所以我使用由 sso 返回的令牌),我可以自动验证它设置属性:
spring.security.oauth2.resourceserver.jwt.jwk-set-uri= https://example.provider.com/oauth2/key/jwks
我可以用我的服务器复制类似的东西吗?
解决方案
推荐阅读
- java - 查找所有整数 p 和 q 的优化方法,使得 2^p*3^q 具有给定的十进制长度
- pycharm - 当我们使用 Robot Framework 在 Pycharm 中执行回车时,如何保持相同的字体和颜色?
- java - 如何在 Jmeter 中使用 Maven 配置文件
- java - Neo4j 将两个不同的对象视为一个对象,因为它们扩展了相同的父对象
- c# - 垃圾收集器在收集可访问对象的实例属性或字段时的行为不明确
- r - 如何改变 facet_grid ggplot 的某些美学?
- json - 在 EF Core 中提取 JSON 实体时出现循环引用错误
- c# - 在 ListView Xamarin Forms 中创建虚线
- tkinter - 我不能在程序函数中使用变量
- go - 如何简化switch语句