【发布时间】:2021-09-07 10:36:05
【问题描述】:
我正在尝试使用 CustomGatewayJWTGenerator 将自定义角色添加到现有 JWT 令牌,如下所述: https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/passing-end-user-attributes-to-the-backend/passing-enduser-attributes-to-the-backend-using-jwt/ 但不幸的是,我收到如下所示的空指针错误(wso2am-3.2.0):
java.lang.NullPointerException: null
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.generateAndRetrieveJWTToken_aroundBody2(JWTValidator.java:214) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.generateAndRetrieveJWTToken(JWTValidator.java:195) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.authenticate_aroundBody0(JWTValidator.java:181) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.authenticate(JWTValidator.java:111) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.oauth.OAuthAuthenticator.authenticate_aroundBody4(OAuthAuthenticator.java:300) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
这也是我在 deployment.toml 中启用的相关属性
[apim.jwt]
enable = true
[apim.jwt.gateway_generator]
impl = "org.wso2.carbon.test.CustomGatewayJWTGenerator"
谢谢
【问题讨论】:
-
您能分享一下您使用的是 API Manager 3.2.0 GA 版本(还是 WUM 更新版本)?您是否在您的环境中应用了任何补丁?
-
@Athiththan 我正在使用 API Manager 3.2.0 GA。我只是从 Internet 上下载的,没有应用任何补丁或新更新。你认为任何更新都能解决这个问题吗?
-
共享轨迹与source code 不一致。我能够构建示例并成功调用 API。你能分享一下你下载包的链接吗?这样我就可以进行另一轮测试。此外,您还可以分享您在自定义 JWT 生成器上尝试的代码摘录吗?
-
我克隆并使用 maven clean build 构建,而没有触及来自 github.com/wso2/samples-apim 的任何内容。然后我将输出 jar 放到 repository/components/lib/ 并再次重新启动 WSO2。然后,当我通过 WSO2 使用有效令牌调用后端服务时,会引发异常。我刚从wso2.com/api-management/previous-releases直接下载了3.2.0 MacOS版本。
-
Ohhh ...您能否从
<apim>/repository/components/lib和dropins目录中删除现有的JAR,并将JAR 仅放在<apim>/repository/components/dropins目录中并尝试该方案? (修改后重启服务器)