users@jersey.java.net

[Jersey] UnsupportedSignatureMethodException for PLAINTEXT or HMAC-SHA1

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Sun, 24 Jul 2011 17:37:09 -0700

I'm trying to use Jersey 1.8 OAuth for accessing a 3rd party RESTful API
and prepared the filter as:

         OAuthSecrets secrets = new
OAuthSecrets().consumerSecret("Nuut8XhKRA");
         OAuthParameters params = new OAuthParameters().
                 consumerKey("gsksu9qfv8qjrnr2679avr25").
                 signatureMethod("PLAINTEXT").
                 version("1.0");
         OAuthClientFilter oauthFilter = new
OAuthClientFilter(providers, params, secrets);

But getting:

Caused by:
com.sun.jersey.oauth.signature.UnsupportedSignatureMethodException:
PLAINTEXT
        at
com.sun.jersey.oauth.signature.OAuthSignature.getSignatureMethod(OAuthSignature.java:253)
        at
com.sun.jersey.oauth.signature.OAuthSignature.generate(OAuthSignature.java:91)
        at
com.sun.jersey.oauth.signature.OAuthSignature.sign(OAuthSignature.java:107)
        at
com.sun.jersey.oauth.client.OAuthClientFilter.handle(OAuthClientFilter.java:301)
        ... 32 more

Removing the signatureMethod gives:

Caused by:
com.sun.jersey.oauth.signature.UnsupportedSignatureMethodException:
HMAC-SHA1
        at
com.sun.jersey.oauth.signature.OAuthSignature.getSignatureMethod(OAuthSignature.java:253)
        at
com.sun.jersey.oauth.signature.OAuthSignature.generate(OAuthSignature.java:91)
        at
com.sun.jersey.oauth.signature.OAuthSignature.sign(OAuthSignature.java:107)
        at
com.sun.jersey.oauth.client.OAuthClientFilter.handle(OAuthClientFilter.java:301)
        ... 32 more

The app is created using Maven with the following dependencies:

         <dependency>
             <groupId>javax</groupId>
             <artifactId>javaee-web-api</artifactId>
             <version>6.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>com.sun.jersey</groupId>
             <artifactId>jersey-client</artifactId>
             <version>1.8</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
             <artifactId>oauth-signature</artifactId>
             <version>1.8</version>
         </dependency>
         <dependency>
             <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
             <artifactId>oauth-client</artifactId>
             <version>1.8</version>
         </dependency>

And the WAR structure is:

META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/lib/
WEB-INF/classes/
WEB-INF/classes/org/
WEB-INF/classes/org/glassfish/
WEB-INF/classes/org/glassfish/samples/
index.jsp
WEB-INF/lib/oauth-client-1.8.jar
WEB-INF/lib/jersey-core-1.8.jar
WEB-INF/lib/oauth-signature-1.8.jar
WEB-INF/classes/org/glassfish/samples/MyClient.class
WEB-INF/classes/org/glassfish/samples/TestServlet.class
META-INF/maven/
META-INF/maven/org.samples/
META-INF/maven/org.samples/JerseyOAuth/
META-INF/maven/org.samples/JerseyOAuth/pom.xml
META-INF/maven/org.samples/JerseyOAuth/pom.properties

How do I get support for these signatures in my application ?

-Arun
-- 
Blog: http://blogs.oracle.com/arungupta
Twitter: http://twitter.com/arungupta