问题描述
有人知道为什么我需要下面的代码行才能让它工作吗?
我认为它应该通过 Configuration Bean 自动应用?
.jwtAuthenticationConverter(reactiveJwtAuthenticationConverter()) //
@Configuration
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
@Import(LabcubeOAuth2SecurityConfiguration.class)
public class RestServiceOAuthConfig {
@Bean
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange()
.pathMatchers("/api/v1/*/"+ ResourceType.SHARED.toString()).permitAll()
.pathMatchers("/api/v1/**").hasAnyAuthority(LabcubeOAuth2SecurityConfiguration.ALL_ACCESS_ScopE,LabcubeOAuth2SecurityConfiguration.ADMIN_ROLE,LabcubeOAuth2SecurityConfiguration.SUPPORT_ROLE)
.pathMatchers("/api/**").authenticated()
.and().oauth2ResourceServer().jwt()
.jwtAuthenticationConverter(reactiveJwtAuthenticationConverter()) //<-- WHY DO I NEED THIS LINE???
;
return http.build();
}
@Bean
public ReactiveJwtAuthenticationConverter reactiveJwtAuthenticationConverter(){
JwtGrantedAuthoritiesConverter grantedAuthoritiesConverterRoles = new JwtGrantedAuthoritiesConverter();
grantedAuthoritiesConverterRoles.setAuthoritiesClaimName("role");
grantedAuthoritiesConverterRoles.setAuthorityPrefix("");
JwtGrantedAuthoritiesConverter grantedAuthoritiesConverterScopes = new JwtGrantedAuthoritiesConverter();
grantedAuthoritiesConverterScopes.setAuthoritiesClaimName("scope");
grantedAuthoritiesConverterScopes.setAuthorityPrefix("");
ReactiveJwtAuthenticationConverter jwtAuthenticationConverter = new ReactiveJwtAuthenticationConverter();
jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(jwt -> Flux.fromStream(Stream.concat(grantedAuthoritiesConverterRoles.convert(jwt).stream(),grantedAuthoritiesConverterScopes.convert(jwt).stream())));
return jwtAuthenticationConverter;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)