小木偶MO 2021-08-27 13:14 采纳率: 75%
浏览 33
已结题

关于Spring GateWay OAuth2ResourceServer 配置ServerHttpSecurity中的hasRole 无效的问题

我知道从security升级到5.2.X版本之后配置 jwtAuthenticationConverter这个可以解决,但是我现在的security版本为5.1.8,没有JwtGrantedAuthoritiesConverter这个类,而且我这个整体还不能升级,要怎么配置呢
5.2以上版本这样配置,但是我现在这个版本要怎么弄呢,cloud版本为Greenwitch.SR6

    @Bean
    public Converter<Jwt, ? extends Mono<? extends AbstractAuthenticationToken>> jwtAuthenticationConverter() {
        JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
        jwtGrantedAuthoritiesConverter.setAuthorityPrefix(AuthConstants.AUTHORITY_PREFIX);
        jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName(AuthConstants.JWT_AUTHORITIES_KEY);

        JwtAuthenticationConverter jwtAuthenticationConverter = new JwtAuthenticationConverter();
        jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(jwtGrantedAuthoritiesConverter);
        return new ReactiveJwtAuthenticationConverterAdapter(jwtAuthenticationConverter);
    }
  • 写回答

1条回答 默认 最新

  • 编号灬9527 2021-08-27 13:24
    关注

    hasRole无效?UserDetails.getAuthorities() 他在判断是否有角色的时候 可是有前缀的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 7月22日
  • 已采纳回答 7月14日
  • 修改了问题 8月27日
  • 创建了问题 8月27日