You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2007/11/26 18:29:05 UTC
svn commit: r598354 - in /incubator/abdera/java/trunk: build/
extensions/oauth/ extensions/oauth/src/ extensions/oauth/src/main/
extensions/oauth/src/main/java/ extensions/oauth/src/main/java/org/
extensions/oauth/src/main/java/org/apache/ extensions/o...
Author: jmsnell
Date: Mon Nov 26 09:28:50 2007
New Revision: 598354
URL: http://svn.apache.org/viewvc?rev=598354&view=rev
Log:
OAuth implementation contributed by David Calavera
https://issues.apache.org/jira/browse/ABDERA-81
A few slight modifications were made: rename OAuthCredentians to OAuthCredentials and support extension methods
Added:
incubator/abdera/java/trunk/extensions/oauth/
incubator/abdera/java/trunk/extensions/oauth/pom.xml
incubator/abdera/java/trunk/extensions/oauth/src/
incubator/abdera/java/trunk/extensions/oauth/src/main/
incubator/abdera/java/trunk/extensions/oauth/src/main/java/
incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/
incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/
incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/
incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/
incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/
incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthCredentials.java
incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthScheme.java
incubator/abdera/java/trunk/extensions/oauth/src/test/
incubator/abdera/java/trunk/extensions/oauth/src/test/java/
incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/
incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/
incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/
incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/
incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/
incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/OAuthSchemeTest.java
incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/TestSuite.java
Modified:
incubator/abdera/java/trunk/build/build.xml
Modified: incubator/abdera/java/trunk/build/build.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/build.xml?rev=598354&r1=598353&r2=598354&view=diff
==============================================================================
--- incubator/abdera/java/trunk/build/build.xml (original)
+++ incubator/abdera/java/trunk/build/build.xml Mon Nov 26 09:28:50 2007
@@ -707,6 +707,10 @@
<param name="ext" value="wsse" />
</antcall>
+ <antcall target="compile.extension">
+ <param name="ext" value="oauth" />
+ </antcall>
+
</target>
<target name="compile.extension">
@@ -775,6 +779,10 @@
<param name="ext" value="wsse" />
</antcall>
+ <antcall target="dist.extension">
+ <param name="ext" value="oauth" />
+ </antcall>
+
</target>
<target name="dist.extension">
@@ -817,6 +825,10 @@
<antcall target="test.extension">
<param name="ext" value="wsse" />
</antcall>
+
+ <antcall target="test.extension">
+ <param name="ext" value="oauth" />
+ </antcall>
</target>
@@ -860,6 +872,10 @@
<antcall target="retro.extension">
<param name="ext" value="wsse" />
+ </antcall>
+
+ <antcall target="retro.extension">
+ <param name="ext" value="oauth" />
</antcall>
</target>
Added: incubator/abdera/java/trunk/extensions/oauth/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/oauth/pom.xml?rev=598354&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/oauth/pom.xml (added)
+++ incubator/abdera/java/trunk/extensions/oauth/pom.xml Mon Nov 26 09:28:50 2007
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. The ASF licenses this file to You
+ under the Apache License, Version 2.0 (the "License"); you may not
+ use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. For additional information regarding
+ copyright in this work, please see the NOTICE file in the top level
+ directory of this distribution. -->
+<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">
+ <parent>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera</artifactId>
+ <version>0.4.0-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>abdera-extensions-oauth</artifactId>
+ <packaging>jar</packaging>
+ <name>Abdera Extensions - OAuth</name>
+ <version>0.4.0-incubating-SNAPSHOT</version>
+ <description>Atom Specification Extensions - OAuth</description>
+ <inceptionYear>2006</inceptionYear>
+ <url>http://incubator.apache.org/abdera</url>
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/extensions/oauth</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/abdera/java/trunk/extensions/oauth</developerConnection>
+ <url>http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/extensions/oauth</url>
+ </scm>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-core</artifactId>
+ <version>0.4.0-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-parser</artifactId>
+ <version>0.4.0-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-protocol</artifactId>
+ <version>0.4.0-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-client</artifactId>
+ <version>0.4.0-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthCredentials.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthCredentials.java?rev=598354&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthCredentials.java (added)
+++ incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthCredentials.java Mon Nov 26 09:28:50 2007
@@ -0,0 +1,137 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package oauth.src.main.java.org.apache.abdera.ext.oauth;
+
+import java.security.cert.Certificate;
+
+import org.apache.commons.httpclient.Credentials;
+
+/**
+ * OAuth credentials
+ *
+ * @see http://oauth.org
+ * @see http://oauth.googlecode.com/svn/spec/branches/1.0/drafts/7/spec.html
+ *
+ * @author David Calavera
+ */
+public class OAuthCredentials
+ implements Credentials {
+
+ private String consumerKey;
+ private String token;
+ private String signatureMethod;
+ private String realm;
+ private String version;
+ private Certificate cert;
+
+ public OAuthCredentians() {
+ super();
+ }
+
+ public OAuthCredentians(
+ String consumerKey,
+ String token,
+ String signatureMethod,
+ String realm) {
+ this(
+ consumerKey,
+ token,
+ signatureMethod,
+ realm,
+ "1.0");
+ }
+
+ public OAuthCredentians(
+ String consumerKey,
+ String token,
+ String signatureMethod,
+ String realm,
+ String version) {
+ this(
+ consumerKey,
+ token,
+ signatureMethod,
+ realm,
+ version,
+ null);
+ }
+
+ public OAuthCredentians(
+ String consumerKey,
+ String token,
+ String signatureMethod,
+ String realm,
+ String version,
+ Certificate cert) {
+ super();
+ this.consumerKey = consumerKey;
+ this.token = token;
+ this.signatureMethod = signatureMethod;
+ this.realm = realm;
+ this.version = version;
+ this.cert = cert;
+ }
+
+ public String getConsumerKey() {
+ return consumerKey;
+ }
+
+ public void setConsumerKey(String consumerKey) {
+ this.consumerKey = consumerKey;
+ }
+
+ public String getSignatureMethod() {
+ return signatureMethod;
+ }
+
+ public void setSignatureMethod(String signatureMethod) {
+ this.signatureMethod = signatureMethod;
+ }
+
+ public String getToken() {
+ return token;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+
+ public String getRealm() {
+ return realm;
+ }
+
+ public void setRealm(String realm) {
+ this.realm = realm;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public Certificate getCert() {
+ return cert;
+ }
+
+ public void setCert(Certificate cert) {
+ this.cert = cert;
+ }
+}
Added: incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthScheme.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthScheme.java?rev=598354&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthScheme.java (added)
+++ incubator/abdera/java/trunk/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthScheme.java Mon Nov 26 09:28:50 2007
@@ -0,0 +1,230 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package oauth.src.main.java.org.apache.abdera.ext.oauth;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.security.SecureRandom;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.util.Date;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.Mac;
+
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.auth.AuthScheme;
+import org.apache.commons.httpclient.auth.AuthenticationException;
+import org.apache.commons.httpclient.auth.RFC2617Scheme;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.OptionsMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+
+/**
+ * OAuth Scheme implementation for use with HTTP Commons AbderaClient
+ *
+ * @see http://oauth.org
+ * @see http://oauth.googlecode.com/svn/spec/branches/1.0/drafts/7/spec.html
+ *
+ * @author David Calavera
+ */
+public class OAuthScheme
+ extends RFC2617Scheme
+ implements AuthScheme {
+
+ private enum OAUTH_KEYS {
+ OAUTH_CONSUMER_KEY,
+ OAUTH_TOKEN,
+ OAUTH_SIGNATURE_METHOD,
+ OAUTH_TIMESTAMP,
+ OAUTH_NONCE,
+ OAUTH_VERSION,
+ OAUTH_SIGNATURE;
+
+ public String toLowerCase() {
+ return this.toString().toLowerCase();
+ }
+ }
+ private final int NONCE_LENGTH = 16;
+
+ public static void register(
+ AbderaClient abderaClient,
+ boolean exclusive) {
+ AbderaClient.registerScheme("OAuth", OAuthScheme.class);
+ if (exclusive)
+ ((AbderaClient)abderaClient).setAuthenticationSchemePriority("OAuth");
+ else
+ ((AbderaClient)abderaClient).setAuthenticationSchemeDefaults();
+ }
+
+ public String authenticate(
+ Credentials credentials,
+ String method,
+ String uri)
+ throws AuthenticationException {
+ return authenticate(credentials, resolveMethod(method, uri) );
+ }
+
+ public String authenticate(
+ Credentials credentials,
+ HttpMethod method)
+ throws AuthenticationException {
+ if (credentials instanceof OAuthCredentials) {
+
+ OAuthCredentials oauthCredentials = (OAuthCredentials) credentials;
+ String nonce = generateNonce();
+ long timestamp = new Date().getTime()/1000;
+
+ String signature = generateSignature(oauthCredentials, method, nonce, timestamp);
+
+ return "OAuth realm=\"" + oauthCredentials.getRealm() + "\", " +
+ OAUTH_KEYS.OAUTH_CONSUMER_KEY.toLowerCase() + "=\"" + oauthCredentials.getConsumerKey() + "\", " +
+ OAUTH_KEYS.OAUTH_TOKEN.toLowerCase() + "=\"" + oauthCredentials.getToken() + "\", " +
+ OAUTH_KEYS.OAUTH_SIGNATURE_METHOD.toLowerCase() + "=\"" + oauthCredentials.getSignatureMethod() + "\", " +
+ OAUTH_KEYS.OAUTH_SIGNATURE.toLowerCase() + "=\"" + signature + "\", " +
+ OAUTH_KEYS.OAUTH_TIMESTAMP.toLowerCase() + "=\"" + timestamp + "\", " +
+ OAUTH_KEYS.OAUTH_NONCE.toLowerCase() + "=\"" + nonce + "\", " +
+ OAUTH_KEYS.OAUTH_VERSION.toLowerCase() + "=\"" + oauthCredentials.getVersion() + "\"";
+ } else {
+ return null;
+ }
+ }
+
+ private HttpMethod resolveMethod(
+ String method,
+ String uri)
+ throws AuthenticationException {
+ if (method.equalsIgnoreCase("get")) {
+ return new GetMethod(uri);
+ } else if (method.equalsIgnoreCase("post")) {
+ return new PostMethod(uri);
+ } else if (method.equalsIgnoreCase("put")) {
+ return new PutMethod(uri);
+ } else if (method.equalsIgnoreCase("delete")) {
+ return new DeleteMethod(uri);
+ } else if (method.equalsIgnoreCase("head")) {
+ return new HeadMethod(uri);
+ } else if (method.equalsIgnoreCase("options")) {
+ return new OptionsMethod(uri);
+ } else {
+ //throw new AuthenticationException("unsupported http method : " + method);
+ return new MethodHelper.ExtensionMethod(method,uri);
+ }
+ }
+
+ private String generateSignature(
+ OAuthCredentials credentials,
+ HttpMethod method,
+ String nonce,
+ long timestamp)
+ throws AuthenticationException{
+ try {
+ String baseString = method.getName().toUpperCase() + method.getURI().toString() +
+ OAUTH_KEYS.OAUTH_CONSUMER_KEY.toLowerCase() + "=" + credentials.getConsumerKey() +
+ OAUTH_KEYS.OAUTH_TOKEN.toLowerCase() + "=" + credentials.getToken() +
+ OAUTH_KEYS.OAUTH_SIGNATURE_METHOD.toLowerCase() + "=" + credentials.getSignatureMethod() +
+ OAUTH_KEYS.OAUTH_TIMESTAMP.toLowerCase() + "=" + timestamp +
+ OAUTH_KEYS.OAUTH_NONCE.toLowerCase() + "=" + nonce +
+ OAUTH_KEYS.OAUTH_VERSION.toLowerCase() + "=" + credentials.getVersion();
+ return sign(
+ credentials.getSignatureMethod(),
+ URLEncoder.encode(baseString, "UTF-8"),
+ credentials.getCert() );
+ } catch (URIException e) {
+ throw new AuthenticationException(e.getMessage(), e);
+ } catch (UnsupportedEncodingException e) {
+ throw new AuthenticationException(e.getMessage(), e);
+ }
+ }
+
+ private String generateNonce() throws AuthenticationException {
+ try {
+ SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
+ byte[] temp = new byte[NONCE_LENGTH];
+ sr.nextBytes(temp);
+ String n = new String(Hex.encodeHex(temp));
+ return n;
+ } catch (Exception e) {
+ throw new AuthenticationException(e.getMessage(),e);
+ }
+ }
+
+ private String sign(
+ String method,
+ String baseString,
+ Certificate cert)
+ throws AuthenticationException {
+ if (method.equalsIgnoreCase("HMAC-MD5") || method.equalsIgnoreCase("HMAC-SHA1")) {
+ try {
+ String[] tokens = method.split("-");
+ String methodName = tokens[0].substring(0,1).toUpperCase() + tokens[0].substring(1).toLowerCase() + tokens[1];
+ KeyGenerator kg = KeyGenerator.getInstance( methodName );
+
+ Mac mac = Mac.getInstance(kg.getAlgorithm());
+ mac.init( kg.generateKey() );
+ byte[] result = mac.doFinal(baseString.getBytes());
+
+ return new String(Base64.encodeBase64(result));
+ } catch (Exception e) {
+ throw new AuthenticationException(e.getMessage(), e);
+ }
+ } else if (method.equalsIgnoreCase("md5")) {
+ return new String(Base64.encodeBase64(DigestUtils.md5( baseString )));
+ } else if (method.equalsIgnoreCase("sha1")) {
+ return new String(Base64.encodeBase64(DigestUtils.sha( baseString )));
+ } else if (method.equalsIgnoreCase("RSA-SHA1")) {
+ if (cert == null) {
+ throw new AuthenticationException("a cert is mandatory to use SHA1 with RSA");
+ }
+ try {
+ Cipher cipher = Cipher.getInstance("SHA1withRSA");
+ cipher.init(Cipher.ENCRYPT_MODE, cert);
+ byte[] result = cipher.doFinal( baseString.getBytes() );
+ return new String(Base64.encodeBase64( result ));
+ } catch (Exception e) {
+ throw new AuthenticationException(e.getMessage(), e);
+ }
+ } else {
+ throw new AuthenticationException("unsupported algorithm method: " + method );
+ }
+ }
+
+ public String getSchemeName() {
+ return "OAuth";
+ }
+
+ public boolean isComplete() {
+ return true;
+ }
+
+ public boolean isConnectionBased() {
+ return true;
+ }
+
+}
Added: incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/OAuthSchemeTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/OAuthSchemeTest.java?rev=598354&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/OAuthSchemeTest.java (added)
+++ incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/OAuthSchemeTest.java Mon Nov 26 09:28:50 2007
@@ -0,0 +1,60 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package oauth.src.test.java.org.apache.abdera.ext.oauth;
+
+import oauth.src.main.java.org.apache.abdera.ext.oauth.OAuthCredentials;
+import oauth.src.main.java.org.apache.abdera.ext.oauth.OAuthScheme;
+
+import org.apache.commons.httpclient.auth.AuthenticationException;
+
+import junit.framework.TestCase;
+
+
+public class OAuthSchemeTest extends TestCase {
+
+ OAuthScheme scheme = new OAuthScheme();
+ OAuthCredentials credentials;
+
+ public void testAuthenticate() {
+
+ credentials =
+ new OAuthCredentials(
+ "dpf43f3p2l4k3l03",
+ "nnch734d00sl2jdk",
+ "HMAC-SHA1",
+ "http://photos.example.net/");
+
+ try {
+ String header =
+ scheme.authenticate(
+ credentials,
+ "get",
+ "http://photos.example.net?file=vacation.jpg");
+ assertNotNull( header );
+
+ String regex = "OAuth realm=\"[^\"]+\", oauth_consumer_key=\"[^\"]+\", " +
+ "oauth_token=\"[^\"]+\", oauth_signature_method=\"[^\"]+\", oauth_signature=\"[^\"]+\", " +
+ "oauth_timestamp=\"[^\"]+\", oauth_nonce=\"[^\"]+\"(, oauth_version=\"[^\"]+\")?";
+
+ assertTrue( header.matches( regex ));
+ } catch (AuthenticationException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
Added: incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/TestSuite.java?rev=598354&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/TestSuite.java (added)
+++ incubator/abdera/java/trunk/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/TestSuite.java Mon Nov 26 09:28:50 2007
@@ -0,0 +1,29 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package oauth.src.test.java.org.apache.abdera.ext.oauth;
+
+
+public class TestSuite extends junit.framework.TestSuite {
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(new TestSuite());
+ }
+
+ public TestSuite() {
+ addTestSuite(OAuthSchemeTest.class);
+ }
+}