代码之家  ›  专栏  ›  技术社区  ›  tryingToLearn

!访问资源时keyclaft中的角色错误

  •  0
  • tryingToLearn  · 技术社区  · 7 年前

    我用keychaft保护了我的其余API。认证后,当我尝试访问RESTAPI时,我得到:

    403错误。无法访问REST API。理由!角色。

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

        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[]{"*"});
    

    我假设通过使用 ‘*’ 错误还是错误意味着不同的东西?

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

    2018-05-24 12:55:52253[调试] [ers.preauthactionshandler(handleRequest)]-管理员请求 http://localhost:7100/api/v1/design/test 2018年5月24日12:55:52254 [debug][tokenrequestauthenticator(thenticatetoken)]-验证 访问令牌2018-05-24 12:55:52255[调试] [tokenrequestauthenticator(thenticatetoken)]-成功授权 2018-05-24 12:55:52255[调试] [JettyRequestAuthenticator(rauthentication)]-完成承载 身份验证。持票人角色:【uma_授权】2018-05-24 12:55:52255[调试][ters.requestauthenticator(eAuthentication)]- 用户'8F9381DF-2F7E-4F8-9EF5-2123B03DB3C9'调用 ’ http://localhost:7100/api/v1/design/test/设计/测试 '在客户端'我的服务器' 2018-05-24 12:55:52255[调试] [ters.requestauthenticator(authenticate)]-持票人已验证 2018-05-24 12:55:52255[调试] [验证操作handler(handledRequest)]- authenticatedActionsValve.invoke http://localhost:7100/api/v1/design/test/设计/测试

    1 回复  |  直到 7 年前
        1
  •  1
  •   tryingToLearn    7 年前

    事实证明,设置任何角色的正确方法是:

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

    双* 而不是 单曲*

    另外,我删除了这条线:

    securityHandler.addRole("*");