OAuth2AuthenticationToken我正在尝试从被检测为 Spring Security 机构的角色声明中获取角色声明。在 OIDC 提供者端(在我的例子中是 Azure AD)定义了一个自定义角色,该角色嵌套在 中DefaultOidcUser,但不会自动添加到权限中:

我尝试像这样从 Jwt 令牌中提取它们
但是,当我这样做时,以下方法都不会被调用(无论是在登录期间,还是稍后,即使在默认配置中):
JwtGrantedAuthoritiesConverter.convert(Jwt)JwtAuthenticationConverter.convert(Jwt)JwtAuthenticationConverter.extractAuthorities(Jwt)我当前的配置是:
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@Import(SecurityProblemSupport.class)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.csrf()
<some more config that has nothing to do with oauth/oidc>
.and()
.oauth2Login()
.and()
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(jwtAuthenticationConverter())
.and()
.and()
.oauth2Client()
;
}
private JwtAuthenticationConverter jwtAuthenticationConverter() {
// create a custom JWT converter to map …Run Code Online (Sandbox Code Playgroud)