gpt4 book ai didi

java - 不支持的 SignatureMethod 异常 : HMAC-SHA1 exception in tomcat with jerseyoauth

转载 作者:行者123 更新时间:2023-11-30 09:12:16 25 4
gpt4 key购买 nike

这是我的pom

    <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>com.mkyong.common</groupId>
<artifactId>RESTfulExample</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>RESTfulExample Maven Webapp</name>
<url>http://maven.apache.org</url>

<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>

</repositories>
<properties>
<project.build.java.target>1.6</project.build.java.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Final</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.28</version>
</dependency>




<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.5</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>



<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-server</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-signature</artifactId>
<version>1.18</version>
</dependency>

<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-client</artifactId>
<version>1.18</version>
</dependency>


</dependencies>

<build>
<finalName>RESTfulExample</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<complianceLevel>1.6</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<!--<goal>test-compile</goal> -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

这是我的誓言过滤器类

public class OAuthAuthenticationFilter1 implements ContainerRequestFilter {
public ContainerRequest filter(ContainerRequest containerRequest) {
OAuthServerRequest request = new OAuthServerRequest(containerRequest);
OAuthParameters params = new OAuthParameters();
params.readRequest(request);
OAuthSecrets secrets = new OAuthSecrets();
OAuthParameters param=new OAuthParameters();
secrets.consumerSecret("OwnAccount");
param.consumerKey("OwnAccount");
try {
if(!OAuthSignature.verify(request, params, secrets)) {
throw new WebApplicationException(401);
}
} catch (OAuthSignatureException e) {
throw new WebApplicationException(e, 401);
}
return containerRequest;
}
}

这是我的客户

public class Sample1 {
public static final String HOSTNAME = "http://localhost:8080/RESTfulExample/rest/hello/planetext";
public static final String CONSUMER_KEY = "OwnAccount";
public static final String CONSUMER_SECRET = "OwnAccount";


/**
* @param args
*/
public static void main(String[] args) {
Client client = Client.create();
OAuthParameters params = new OAuthParameters().signatureMethod("HMAC-SHA1").consumerKey(CONSUMER_KEY);
OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET);
OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets);
WebResource res = client.resource(HOSTNAME );
res.addFilter(filter);
String responseString = res.get(String.class);
System.out.println(responseString);
}

}

我正在使用以下誓言和 Jersey pom 引用该网站 http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.sun.jersey.contribs.jersey-oauth%22

<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-server</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-signature</artifactId>
<version>1.18</version>
</dependency>

<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-client</artifactId>
<version>1.18</version>
</dependency>

当过滤器类的以下代码被调用时

try {
// exception is thrown from here

if(!OAuthSignature.verify(request, params, secrets)) {
throw new WebApplicationException(401);
}
} catch (OAuthSignatureException e) {
throw new WebApplicationException(e, 401);
}

我遇到了这个异常

com.sun.jersey.oauth.signature.UnsupportedSignatureMethodException:HMAC-SHA1 在 com.sun.jersey.oauth.signature.OAuthSignature.getSignatureMethod(OAuthSignature.java:257)

我正在使用 tomcat 7。

我在网上搜索但找不到 tomcat 的原因。我缺少什么?有人遇到过 tomcat 的问题吗?

最佳答案

当我将 jersey-server jar 更新到 1.18 时,我解决了这个问题。我之前使用的是 jersey-server 1.8 jar。

关于java - 不支持的 SignatureMethod 异常 : HMAC-SHA1 exception in tomcat with jerseyoauth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21677801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com