MyCustomHandler.java (WSO2 APIM 3.2.0) 中使用的相关依赖项 .jar 文件的添加位置
where to add related dependencies .jar files used in MyCustomHandler.java (WSO2 APIM 3.2.0)
我已经扩展了抽象处理程序 class 并在 wso2 apim 中编写了我自己的自定义处理程序 class。
我也能够获取此自定义处理程序的日志。对于令牌验证,我在我的项目中使用了一些 okta 依赖项(okta-jwt-verifier 和 okta-jwt-verifier-impl)。我在 /repository/components/lib 文件夹中添加了 myCustomHandler.jar 和上述依赖项的其他 2 个 jar。启动服务器后,我没有收到任何错误,但是当我点击 API 请求时,我收到以下运行时错误,
java.lang.IllegalStateException: No `interface com.okta.jwt.AccessTokenVerifier$Builder` implementation found on the classpath. Have you remembered to include the okta-jwt-verifier-impl.jar in your runtime classpath?
at com.okta.jwt.JwtVerifiers.lambda$loadService(JwtVerifiers.java:60) ~[okta-jwt-verifier-0.5.0.jar:0.5.0]
at java.util.Optional.orElseThrow(Optional.java:408) ~[?:?]
at com.okta.jwt.JwtVerifiers.loadService(JwtVerifiers.java:60) ~[okta-jwt-verifier-0.5.0.jar:0.5.0]
at com.okta.jwt.JwtVerifiers.accessTokenVerifierBuilder(JwtVerifiers.java:51) ~[okta-jwt-verifier-0.5.0.jar:0.5.0]
at org.wso2.carbon.test.CustomAPIAuthenticationHandler.authenticate(CustomAPIAuthenticationHandler.java:44) ~[MCM_Custom_handler.jar:?]
at org.wso2.carbon.test.CustomAPIAuthenticationHandler.handleRequest(CustomAPIAuthenticationHandler.java:24) ~[MCM_Custom_handler.jar:?]
at org.apache.synapse.rest.API.process(API.java:373)
我的代码部分出现错误,
AccessTokenVerifier jwtVerifier = JwtVerifiers.accessTokenVerifierBuilder()
.setIssuer("https://{{myDomain}}/oauth2/default").setAudience("api://default")
.setConnectionTimeout(Duration.ofSeconds(1)) // defaults to 1s
.setRetryMaxAttempts(2) // defaults to 2
.setRetryMaxElapsed(Duration.ofSeconds(10)) // defaults to 10s
.build();
我认为 wso2apim 无法以某种方式找到我提供的 jar 和 /lib 文件夹,它正在其他目录中搜索它,因为它是运行时依赖项...
或者这可能是一些我不知道的 OKTA 问题 :(
你能帮我解决这个问题吗?,我已经卡住了 1 周了,但没有得到任何突破提前谢谢
我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.test</groupId>
<artifactId>org.wso2.carbon.test</artifactId>
<packaging>bundle</packaging>
<version>1.0-SNAPSHOT</version>
<name>org.wso2.carbon.test.authenticator</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</pluginRepository>
<pluginRepository>
<id>wso2.snapshots</id>
<name>WSO2 Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>org.wso2.carbon.test</Bundle-SymbolicName>
<Bundle-Name>org.wso2.carbon.test</Bundle-Name>
<Import-Package>
com.okta.jwt,
*; resolution:=optional
</Import-Package>
<Export-Package>
org.wso2.carbon.test.*,
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.synapse</groupId>
<artifactId>synapse-core</artifactId>
<version>2.1.7-wso2v183</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.synapse</groupId>
<artifactId>synapse-commons</artifactId>
<version>2.1.7-wso2v183</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.gateway</artifactId>
<version>6.7.206</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier-impl</artifactId>
<version>0.5.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
我遵循的参考资料
确保为您使用 okta-jwt-verifier 和 okta-jwt-verifier-impl 依赖项实现的项目更新 pom 文件。您应该像下面那样在 pom.xml
中添加依赖项。仅检查 using jar 的版本。
<dependencies>
<!-- add to have class path -->
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier-impl</artifactId>
<version>0.4.0</version>
</dependency>
</dependencies>
当我创建一个带有 eclipse 插件的 OSGI 包时,我的问题就解决了,其中包含令牌验证所需的所有外部 jar。
要遵循的步骤。
- 在 eclipse 中创建一个 osgi 项目select 选择添加外部 jar 并添加所需的 jar。
- 导出包 mybundle.jar
- 将此包复制到 /component/dropins/ 目录
- 将您的项目myCustomHandler.jar复制到/component/lib目录
- Restart/Start服务器
如果您收到任何冲突错误,只需从捆绑包中删除这些 jar,如果您收到任何 class 未找到错误,请将这些 jar 添加到捆绑包中并导出。
我已经扩展了抽象处理程序 class 并在 wso2 apim 中编写了我自己的自定义处理程序 class。 我也能够获取此自定义处理程序的日志。对于令牌验证,我在我的项目中使用了一些 okta 依赖项(okta-jwt-verifier 和 okta-jwt-verifier-impl)。我在 /repository/components/lib 文件夹中添加了 myCustomHandler.jar 和上述依赖项的其他 2 个 jar。启动服务器后,我没有收到任何错误,但是当我点击 API 请求时,我收到以下运行时错误,
java.lang.IllegalStateException: No `interface com.okta.jwt.AccessTokenVerifier$Builder` implementation found on the classpath. Have you remembered to include the okta-jwt-verifier-impl.jar in your runtime classpath?
at com.okta.jwt.JwtVerifiers.lambda$loadService(JwtVerifiers.java:60) ~[okta-jwt-verifier-0.5.0.jar:0.5.0]
at java.util.Optional.orElseThrow(Optional.java:408) ~[?:?]
at com.okta.jwt.JwtVerifiers.loadService(JwtVerifiers.java:60) ~[okta-jwt-verifier-0.5.0.jar:0.5.0]
at com.okta.jwt.JwtVerifiers.accessTokenVerifierBuilder(JwtVerifiers.java:51) ~[okta-jwt-verifier-0.5.0.jar:0.5.0]
at org.wso2.carbon.test.CustomAPIAuthenticationHandler.authenticate(CustomAPIAuthenticationHandler.java:44) ~[MCM_Custom_handler.jar:?]
at org.wso2.carbon.test.CustomAPIAuthenticationHandler.handleRequest(CustomAPIAuthenticationHandler.java:24) ~[MCM_Custom_handler.jar:?]
at org.apache.synapse.rest.API.process(API.java:373)
我的代码部分出现错误,
AccessTokenVerifier jwtVerifier = JwtVerifiers.accessTokenVerifierBuilder()
.setIssuer("https://{{myDomain}}/oauth2/default").setAudience("api://default")
.setConnectionTimeout(Duration.ofSeconds(1)) // defaults to 1s
.setRetryMaxAttempts(2) // defaults to 2
.setRetryMaxElapsed(Duration.ofSeconds(10)) // defaults to 10s
.build();
我认为 wso2apim 无法以某种方式找到我提供的 jar 和 /lib 文件夹,它正在其他目录中搜索它,因为它是运行时依赖项... 或者这可能是一些我不知道的 OKTA 问题 :( 你能帮我解决这个问题吗?,我已经卡住了 1 周了,但没有得到任何突破提前谢谢
我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.test</groupId>
<artifactId>org.wso2.carbon.test</artifactId>
<packaging>bundle</packaging>
<version>1.0-SNAPSHOT</version>
<name>org.wso2.carbon.test.authenticator</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</pluginRepository>
<pluginRepository>
<id>wso2.snapshots</id>
<name>WSO2 Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>org.wso2.carbon.test</Bundle-SymbolicName>
<Bundle-Name>org.wso2.carbon.test</Bundle-Name>
<Import-Package>
com.okta.jwt,
*; resolution:=optional
</Import-Package>
<Export-Package>
org.wso2.carbon.test.*,
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.synapse</groupId>
<artifactId>synapse-core</artifactId>
<version>2.1.7-wso2v183</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.synapse</groupId>
<artifactId>synapse-commons</artifactId>
<version>2.1.7-wso2v183</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.gateway</artifactId>
<version>6.7.206</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier-impl</artifactId>
<version>0.5.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
我遵循的参考资料
确保为您使用 okta-jwt-verifier 和 okta-jwt-verifier-impl 依赖项实现的项目更新 pom 文件。您应该像下面那样在 pom.xml
中添加依赖项。仅检查 using jar 的版本。
<dependencies>
<!-- add to have class path -->
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>com.okta.jwt</groupId>
<artifactId>okta-jwt-verifier-impl</artifactId>
<version>0.4.0</version>
</dependency>
</dependencies>
当我创建一个带有 eclipse 插件的 OSGI 包时,我的问题就解决了,其中包含令牌验证所需的所有外部 jar。 要遵循的步骤。
- 在 eclipse 中创建一个 osgi 项目select 选择添加外部 jar 并添加所需的 jar。
- 导出包 mybundle.jar
- 将此包复制到 /component/dropins/ 目录
- 将您的项目myCustomHandler.jar复制到/component/lib目录
- Restart/Start服务器
如果您收到任何冲突错误,只需从捆绑包中删除这些 jar,如果您收到任何 class 未找到错误,请将这些 jar 添加到捆绑包中并导出。