role在访问资源时在密钥斗篷中出错

role在访问资源时在密钥斗篷中出错

本文介绍了!role在访问资源时在密钥斗篷中出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Keycloak保护了我的其余api.身份验证后,当我尝试访问rest API时,我得到:

I have secured my rest api with Keycloak. After authentication, when I try to access rest API , I get:

在配置中,我将角色指定为*:

In configuration I have specified role as *:

    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    context.setSecurityHandler(securityHandler);
    securityHandler.addRole("*");
    ConstraintMapping constraintMapping = new ConstraintMapping();
    constraintMapping.setPathSpec("/*");
    Constraint constraint = new Constraint();

    constraint.setAuthenticate(true);
    constraint.setRoles(new String[]{"*"});

我假设通过使用'*'指定任何角色是错误的,还是该错误意味着有所不同?

Was my assumption of specifying any role by using '*' wrong or does the error mean something different?

我在JettyKeycloakAuthentciator日志中看到以下日志:

I see following logs in JettyKeycloakAuthentciator logs:

推荐答案

设置任何角色的正确方法是:

Turns out the correct way to set any role is:

constraint.setRoles(new String[]{"**"});

双* ,而不是单*

我也删除了这一行:

securityHandler.addRole("*");

这篇关于!role在访问资源时在密钥斗篷中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:06