Spring Security WSO2 IS集成-弄清楚如何分配权限/自定义wso2令牌

用户名

我在这个问题上呆了几天。

所以我想做的就是给ROLES分配spring安全框架。我的目标是解码通过openid从WSO2 Identity Server 5.0获得的令牌并分配角色,以便我可以基于角色(AUTHORITIES)授权请求

这是我在简单的Spring Boot应用程序中的SecurityConfig

@Profile(“ oauth”)
@
Configuration @EnableResourceServer
公共类SecurityConfig {

}

因此,使用此配置,我能够解码令牌。

但是,在调试模式下,当我向简单的Spring Boot应用程序发出带有id_token的请求时,我收到了一条错误消息:

java.lang.ClassCastException
java.lang.String无法转换为java.util.Collection

它发生在DefaultAccessTokenConverter类中,尤其是在将地图对象转换为String []角色时的代码行中

public OAuth2Authentication extractAuthentication(Map<String, ?> map) {
    ...
    if (user==null && map.containsKey(AUTHORITIES)) {
        @SuppressWarnings("unchecked")
        String[] roles = ((Collection<String>)map.get(AUTHORITIES)).toArray(new String[0]);
        authorities = AuthorityUtils.createAuthorityList(roles);
    }
    OAuth2Request request = new OAuth2Request(parameters, clientId, authorities, true, scope, resourceIds, null, null,
            null);
    return new OAuth2Authentication(request, user);
}

这是我的WSO2解码令牌

{
“ auth_time”:1464819792,“ exp”:1464823490,
“ azp”:“ U1PXsuyV_tdBERmZIoHHnqoGkWIa”,
“ authorities”:“ [\” ROLE_ADMIN \“,\”批准人\“,\”内部\ /每个人\“]”
“ at_hash”:“ Hh2LUZl3Bp6yDqyZt4r6Gg”,
aud ”:[
“ U1PXsuyV_tdBERmZIoHHnqoGkWIa”
],
“ iss”:“ https:// localhost:9443 / oauth2 / token ”,“ locality”:“ [\” ROLE “ iat”:1464819890}

看来Spring希望使用String而不是String对象的Array(在授权值的开头和结尾都有双引号。

AUD格式似乎是春天的期待是什么。

因此,我可以考虑以下两种选择:
1.在Spring Oauth2中编写一些配置(我还没有弄清楚)
。2.配置WSO2 Identity Server(这是我一直在尝试的操作)。

有一些资源说我们可以在WSO2碳中实现我们自己的JWTTokenGenerator。通过查看代码,看来这是在索赔中生成双引号的地方。

org.wso2.carbon.identity.oauth2.authcontext.JWTTokenGenerator

我希望还有其他人正在经历这一过程。

非常感谢你。

用户名

谢谢!那也可以!但是为了便于实施,我们使用了5.2.0 Beta版,该版本生成字符串数组。Ť

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章