【问题标题】:Custom JWT Generation Gives Exception in WSO2 3.2.0自定义 JWT 生成在 WSO2 3.2.0 中出现异常
【发布时间】: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/libdropins 目录中删除现有的JAR,并将JAR 仅放在<apim>/repository/components/dropins 目录中并尝试该方案? (修改后重启服务器)

标签: jwt wso2 wso2-am


【解决方案1】:

根据共享信息,构建的 JAR 工件已放置在 <apim>/repository/components/lib 目录中。

执行以下步骤来克服该行为

  • 转到<apim>/repository/components/lib 目录并删除自定义 JWT 生成器 JAR
  • 移至<apim>/repository/components/dropins 目录并删除自定义 JWT 生成器包 JAR(这是一个 OSGi 包,在启动期间为位于 /lib 目录下的 JAR 创建)
  • 仅将构建的 JAR 工件放在 <apim>/repository/components/dropins 中并重新启动 API Manager 服务器

重启后,尝试调用 API。

【讨论】:

  • 我也尝试了你的建议。但仍然有同样的问题:(还是谢谢你
  • 您在调用API时是否还在观察空指针异常?它是相同的痕迹还是现在从不同的位置抛出?
  • 很遗憾。事件我下载了一个新版本的 WSO 并将新编译的 jar 放入 /repository/components/dropins 文件夹,仍然观察空指针。
猜你喜欢
  • 2020-10-17
  • 2016-01-15
  • 2021-11-08
  • 1970-01-01
  • 1970-01-01
  • 2019-12-06
  • 1970-01-01
  • 2022-12-09
  • 1970-01-01
相关资源
最近更新 更多