shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ssiev...@apache.org
Subject svn commit: r1355468 - in /shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistence.java test/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistenceTest.java
Date Fri, 29 Jun 2012 16:49:02 GMT
Author: ssievers
Date: Fri Jun 29 16:49:01 2012
New Revision: 1355468

URL: http://svn.apache.org/viewvc?rev=1355468&view=rev
Log:
SHINDIG-1810 | OAuth2TokenPersistence setSecret fails if no encrypter | Patch from Brian Lillie.
 Thanks!

Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistence.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistenceTest.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistence.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistence.java?rev=1355468&r1=1355467&r2=1355468&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistence.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistence.java
Fri Jun 29 16:49:01 2012
@@ -183,16 +183,12 @@ public class OAuth2TokenPersistence impl
 
   public void setEncryptedMacSecret(final byte[] encryptedSecret) throws OAuth2EncryptionException
{
     this.encryptedMacSecret = encryptedSecret;
-    if (this.encrypter != null) {
-      this.macSecret = this.encrypter.decrypt(encryptedSecret);
-    }
+    this.macSecret = this.encrypter == null ? encryptedSecret : this.encrypter.decrypt(encryptedSecret);
   }
 
   public void setEncryptedSecret(final byte[] encryptedSecret) throws OAuth2EncryptionException
{
     this.encryptedSecret = encryptedSecret;
-    if (this.encrypter != null) {
-      this.secret = this.encrypter.decrypt(encryptedSecret);
-    }
+    this.secret = this.encrypter == null ? encryptedSecret : this.encrypter.decrypt(encryptedSecret);
   }
 
   public void setExpiresAt(final long expiresAt) {
@@ -217,13 +213,11 @@ public class OAuth2TokenPersistence impl
 
   public void setMacSecret(final byte[] secret) throws OAuth2RequestException {
     this.macSecret = secret;
-    if (this.encrypter != null) {
-      try {
-        this.encryptedMacSecret = this.encrypter.encrypt(secret);
-      } catch (final OAuth2EncryptionException e) {
-        throw new OAuth2RequestException(OAuth2Error.SECRET_ENCRYPTION_PROBLEM,
-                "OAuth2TokenPersistence could not encrypt the mac secret", e);
-      }
+    try {
+      this.encryptedMacSecret = this.encrypter == null ? secret : this.encrypter.encrypt(secret);
+    } catch (final OAuth2EncryptionException e) {
+      throw new OAuth2RequestException(OAuth2Error.SECRET_ENCRYPTION_PROBLEM,
+              "OAuth2TokenPersistence could not encrypt the mac secret", e);
     }
   }
 
@@ -241,7 +235,7 @@ public class OAuth2TokenPersistence impl
   public void setSecret(final byte[] secret) throws OAuth2RequestException {
     this.secret = secret;
     try {
-      this.encryptedSecret = this.encrypter.encrypt(secret);
+      this.encryptedSecret = this.encrypter == null ? secret : this.encrypter.encrypt(secret);
     } catch (final OAuth2EncryptionException e) {
       throw new OAuth2RequestException(OAuth2Error.SECRET_ENCRYPTION_PROBLEM,
               "OAuth2TokenPersistence could not encrypt the token secret", e);

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistenceTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistenceTest.java?rev=1355468&r1=1355467&r2=1355468&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistenceTest.java
(original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/persistence/OAuth2TokenPersistenceTest.java
Fri Jun 29 16:49:01 2012
@@ -18,14 +18,17 @@
  */
 package org.apache.shindig.gadgets.oauth2.persistence;
 
-import java.util.Map;
+import static org.junit.Assert.assertArrayEquals;
 
 import org.apache.shindig.gadgets.oauth2.MockUtils;
 import org.apache.shindig.gadgets.oauth2.OAuth2Message;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.Map;
+
 public class OAuth2TokenPersistenceTest extends MockUtils {
   private static OAuth2TokenPersistence accessToken;
   private static OAuth2TokenPersistence refreshToken;
@@ -564,24 +567,30 @@ public class OAuth2TokenPersistenceTest 
 
   @Test
   public void testSetSecret_2() throws Exception {
-    final OAuth2TokenPersistence fixture = new OAuth2TokenPersistence(MockUtils.getDummyEncrypter());
+    final OAuth2TokenPersistence fixture = new OAuth2TokenPersistence();
     fixture.setServiceName("");
-    fixture.setEncryptedSecret(new byte[] {});
     fixture.setUser("");
     fixture.setType(org.apache.shindig.gadgets.oauth2.OAuth2Token.Type.ACCESS);
     fixture.setIssuedAt(1L);
-    fixture.setEncryptedMacSecret(new byte[] {});
     fixture.setMacAlgorithm("");
     fixture.setScope("");
     fixture.setExpiresAt(1L);
-    fixture.setMacSecret(new byte[] {});
-    fixture.setSecret(new byte[] {});
     fixture.setGadgetUri("");
     fixture.setMacExt("");
     fixture.setTokenType("");
-    final byte[] secret = new byte[] {};
 
-    fixture.setSecret(secret);
+    byte[] secret = "abcdef".getBytes();
+    fixture.setEncryptedSecret( secret );
+    assertArrayEquals(secret, fixture.getSecret());
+    fixture.setEncryptedMacSecret(secret);
+    assertArrayEquals(secret, fixture.getMacSecret());
+
+    byte[] secret2 = "zyxwvu".getBytes();
+    fixture.setSecret( secret2 );
+    assertArrayEquals( secret2, fixture.getEncryptedSecret() );
+    fixture.setMacSecret( secret2 );
+    assertArrayEquals( secret2, fixture.getEncryptedMacSecret() );
+
   }
 
   @Test



Mime
View raw message