我用新的spring资源服务器创建了一个资源服务器。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
我将有两个不同的提供者,所以我创建了一个 JwtIssuerAuthenticationManagerResolver
.
JwtIssuerAuthenticationManagerResolver resolver =
new JwtIssuerAuthenticationManagerResolver(
"http://localhost:8180/auth/realms/externalauth",
"http://localhost:8080/auth/realms/myauth");
...
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2ResourceServer(oauth2 ->
oauth2.authenticationManagerResolver(resolver));
}
我想在令牌被认为是有效令牌之后,获取它并提取和设置securitycontext。
我试过了 BearerTokenResolver
但没用,我也试过了 implements Converter<Jwt, AbstractAuthenticationToken>
.
但我得到了一个错误:
If an authenticationManagerResolver() is configured, then it takes precedence over any jwt() or opaqueToken() configuration.
提前谢谢
暂无答案!
目前还没有任何答案,快来回答吧!