You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2013/04/19 19:52:54 UTC

svn commit: r1469971 - in /accumulo/trunk: ./ assemble/ core/ core/src/main/java/org/apache/accumulo/core/client/security/tokens/ core/src/test/java/org/apache/accumulo/core/client/security/tokens/ examples/ fate/src/main/java/org/apache/accumulo/fate/...

Author: kturner
Date: Fri Apr 19 17:52:52 2013
New Revision: 1469971

URL: http://svn.apache.org/r1469971
Log:
ACCUMULO-1314 made PasswordToken init work w/ multi-byte chars and clear intermediate byte buffer.  Made AuthToken props fail after destroyed

Added:
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/security/tokens/
      - copied from r1469967, accumulo/branches/1.5/core/src/test/java/org/apache/accumulo/core/client/security/tokens/
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/security/tokens/PasswordTokenTest.java
      - copied unchanged from r1469967, accumulo/branches/1.5/core/src/test/java/org/apache/accumulo/core/client/security/tokens/PasswordTokenTest.java
Modified:
    accumulo/trunk/   (props changed)
    accumulo/trunk/assemble/   (props changed)
    accumulo/trunk/core/   (props changed)
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/AuthenticationToken.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/PasswordToken.java
    accumulo/trunk/examples/   (props changed)
    accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java   (props changed)
    accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java   (props changed)
    accumulo/trunk/pom.xml   (props changed)
    accumulo/trunk/server/   (props changed)
    accumulo/trunk/src/   (props changed)

Propchange: accumulo/trunk/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5:r1469967,1469970

Propchange: accumulo/trunk/assemble/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/assemble:r1469967,1469970

Propchange: accumulo/trunk/core/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/core:r1469967,1469970

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/AuthenticationToken.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/AuthenticationToken.java?rev=1469971&r1=1469970&r2=1469971&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/AuthenticationToken.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/AuthenticationToken.java Fri Apr 19 17:52:52 2013
@@ -17,6 +17,7 @@
 package org.apache.accumulo.core.client.security.tokens;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -30,18 +31,26 @@ import org.apache.hadoop.io.Writable;
  * @since 1.5.0
  */
 public interface AuthenticationToken extends Writable, Destroyable, Cloneable {
-  public class Properties extends HashMap<String, char[]> implements Destroyable {
-    private static final long serialVersionUID = 507486847276806489L;
-    boolean destroyed = false;
+  public class Properties implements Destroyable, Map<String,char[]> {
+    
+    private boolean destroyed = false;
+    private HashMap<String,char[]> map = new HashMap<String,char[]>();
+    
+    private void checkDestroyed() {
+      if (destroyed)
+        throw new IllegalStateException();
+    }
     
     public char[] put(String key, CharSequence value) {
+      checkDestroyed();
       char[] toPut = new char[value.length()];
       for (int i = 0; i < value.length(); i++)
         toPut[i] = value.charAt(i);
-      return this.put(key, toPut);
+      return map.put(key, toPut);
     }
     
     public void putAllStrings(Map<String, ? extends CharSequence> map) {
+      checkDestroyed();
       for (Map.Entry<String,? extends CharSequence> entry : map.entrySet()) {
         put(entry.getKey(), entry.getValue());
       }
@@ -61,6 +70,78 @@ public interface AuthenticationToken ext
     public boolean isDestroyed() {
       return destroyed;
     }
+    
+    @Override
+    public int size() {
+      checkDestroyed();
+      return map.size();
+    }
+    
+    @Override
+    public boolean isEmpty() {
+      checkDestroyed();
+      return map.isEmpty();
+    }
+    
+    @Override
+    public boolean containsKey(Object key) {
+      checkDestroyed();
+      return map.containsKey(key);
+    }
+    
+    @Override
+    public boolean containsValue(Object value) {
+      checkDestroyed();
+      return map.containsValue(value);
+    }
+    
+    @Override
+    public char[] get(Object key) {
+      checkDestroyed();
+      return map.get(key);
+    }
+    
+    @Override
+    public char[] put(String key, char[] value) {
+      checkDestroyed();
+      return map.put(key, value);
+    }
+    
+    @Override
+    public char[] remove(Object key) {
+      checkDestroyed();
+      return map.remove(key);
+    }
+    
+    @Override
+    public void putAll(Map<? extends String,? extends char[]> m) {
+      checkDestroyed();
+      map.putAll(m);
+    }
+    
+    @Override
+    public void clear() {
+      checkDestroyed();
+      map.clear();
+    }
+    
+    @Override
+    public Set<String> keySet() {
+      checkDestroyed();
+      return map.keySet();
+    }
+    
+    @Override
+    public Collection<char[]> values() {
+      checkDestroyed();
+      return map.values();
+    }
+    
+    @Override
+    public Set<java.util.Map.Entry<String,char[]>> entrySet() {
+      checkDestroyed();
+      return map.entrySet();
+    }
   }
   
   public static class TokenProperty implements Comparable<TokenProperty> {

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/PasswordToken.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/PasswordToken.java?rev=1469971&r1=1469970&r2=1469971&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/PasswordToken.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/security/tokens/PasswordToken.java Fri Apr 19 17:52:52 2013
@@ -55,7 +55,7 @@ public class PasswordToken implements Au
    * Password tokens created with this constructor will store the password as UTF-8 bytes.
    */
   public PasswordToken(CharSequence password) {
-    this.password = password.toString().getBytes(Constants.UTF8);
+    setPassword(CharBuffer.wrap(password));
   }
   
   /**
@@ -123,15 +123,29 @@ public class PasswordToken implements Au
     }
   }
   
+  private void setPassword(CharBuffer charBuffer) {
+    // encode() kicks back a C-string, which is not compatible with the old passwording system
+    ByteBuffer bb = Constants.UTF8.encode(charBuffer);
+    // create array using byter buffer length
+    this.password = new byte[bb.remaining()];
+    bb.get(this.password);
+    if (!bb.isReadOnly()) {
+      // clear byte buffer
+      bb.rewind();
+      while (bb.remaining() > 0) {
+        bb.put((byte) 0);
+      }
+    }
+  }
+
   @Override
   public void init(Properties properties) {
     if (properties.containsKey("password")){
-      // encode() kicks back a C-string, which is not compatible with the old passwording system
-      this.password = new byte[properties.get("password").length];
-      Constants.UTF8.encode(CharBuffer.wrap(properties.get("password"))).get(this.password, 0, this.password.length);
+      setPassword(CharBuffer.wrap(properties.get("password")));
     }else
       throw new IllegalArgumentException("Missing 'password' property");
   }
+
   
   @Override
   public Set<TokenProperty> getProperties() {

Propchange: accumulo/trunk/examples/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/examples:r1469967,1469970

Propchange: accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java:r1469967,1469970

Propchange: accumulo/trunk/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java:r1469967,1469970

Propchange: accumulo/trunk/pom.xml
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/pom.xml:r1469967,1469970

Propchange: accumulo/trunk/server/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/server:r1469967,1469970

Propchange: accumulo/trunk/src/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.5/src:r1469967,1469970