accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject svn commit: r1445954 - in /accumulo/trunk/core/src: main/java/org/apache/accumulo/core/security/Authorizations.java test/java/org/apache/accumulo/core/security/AuthorizationsTest.java
Date Wed, 13 Feb 2013 22:03:41 GMT
Author: ctubbsii
Date: Wed Feb 13 22:03:41 2013
New Revision: 1445954

URL: http://svn.apache.org/r1445954
Log:
ACCUMULO-1051 Applied patch to consistently serialize Authorizations

Modified:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/security/AuthorizationsTest.java

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java?rev=1445954&r1=1445953&r2=1445954&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
Wed Feb 13 22:03:41 2013
@@ -23,9 +23,10 @@ import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.accumulo.core.data.ArrayByteSequence;
 import org.apache.accumulo.core.data.ByteSequence;
@@ -37,14 +38,14 @@ public class Authorizations implements I
   
   private static final long serialVersionUID = 1L;
   
-  private HashSet<ByteSequence> auths = new HashSet<ByteSequence>();
+  private Set<ByteSequence> auths = new TreeSet<ByteSequence>();
   private List<byte[]> authsList = new ArrayList<byte[]>();
   private List<byte[]> immutableList = Collections.unmodifiableList(authsList);
   
   private static final boolean[] validAuthChars = new boolean[256];
   
   public static final String HEADER = "!AUTH1:";
-
+  
   static {
     for (int i = 0; i < 256; i++) {
       validAuthChars[i] = false;
@@ -103,11 +104,11 @@ public class Authorizations implements I
    * @param authorizations
    *          a serialized authorizations string produced by {@link #getAuthorizationsArray()}
or {@link #serialize()}
    */
-
+  
   public Authorizations(byte[] authorizations) {
     
     ArgumentChecker.notNull(authorizations);
-
+    
     String authsString = new String(authorizations);
     if (authsString.startsWith(HEADER)) {
       // its the new format
@@ -140,7 +141,7 @@ public class Authorizations implements I
   public Authorizations(Charset charset, String... authorizations) {
     setAuthorizations(charset, authorizations);
   }
-
+  
   public Authorizations(String... authorizations) {
     setAuthorizations(authorizations);
   }
@@ -176,6 +177,7 @@ public class Authorizations implements I
     return ByteBufferUtil.toByteBuffers(immutableList);
   }
   
+  @Override
   public String toString() {
     StringBuilder sb = new StringBuilder();
     String sep = "";
@@ -196,6 +198,7 @@ public class Authorizations implements I
     return auths.contains(auth);
   }
   
+  @Override
   public boolean equals(Object o) {
     if (o == null) {
       return false;
@@ -210,6 +213,7 @@ public class Authorizations implements I
     return false;
   }
   
+  @Override
   public int hashCode() {
     int result = 0;
     for (ByteSequence b : auths)

Modified: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/security/AuthorizationsTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/security/AuthorizationsTest.java?rev=1445954&r1=1445953&r2=1445954&view=diff
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/security/AuthorizationsTest.java
(original)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/security/AuthorizationsTest.java
Wed Feb 13 22:03:41 2013
@@ -43,4 +43,12 @@ public class AuthorizationsTest {
     assertEquals(a, b);
   }
   
+  @Test
+  public void testSerialization() {
+    Authorizations a1 = new Authorizations("a", "b");
+    Authorizations a2 = new Authorizations("b", "a");
+    
+    assertEquals(a1, a2);
+    assertEquals(a1.serialize(), a2.serialize());
+  }
 }



Mime
View raw message