accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject svn commit: r1438354 [6/12] - in /accumulo/trunk: ./ assemble/ bin/ conf/examples/1GB/native-standalone/ conf/examples/1GB/standalone/ conf/examples/2GB/native-standalone/ conf/examples/2GB/standalone/ conf/examples/3GB/native-standalone/ conf/examples...
Date Fri, 25 Jan 2013 07:04:29 GMT
Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/master/thrift/TabletServerStatus.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/master/thrift/TabletServerStatus.java?rev=1438354&r1=1438353&r2=1438354&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/master/thrift/TabletServerStatus.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/master/thrift/TabletServerStatus.java
Fri Jan 25 07:04:25 2013
@@ -1127,7 +1127,7 @@ import org.slf4j.LoggerFactory;
                 for (int _i1 = 0; _i1 < _map0.size; ++_i1)
                 {
                   String _key2; // required
-                  TableInfo _val3; // required
+                  TableInfo _val3; // optional
                   _key2 = iprot.readString();
                   _val3 = new TableInfo();
                   _val3.read(iprot);

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/AuthInfo.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/AuthInfo.java?rev=1438354&r1=1438353&r2=1438354&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/AuthInfo.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/AuthInfo.java
Fri Jan 25 07:04:25 2013
@@ -22,37 +22,32 @@
  */
 package org.apache.accumulo.core.security.thrift;
 
+import java.nio.ByteBuffer;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.thrift.protocol.TTupleProtocol;
 import org.apache.thrift.scheme.IScheme;
 import org.apache.thrift.scheme.SchemeFactory;
 import org.apache.thrift.scheme.StandardScheme;
-
 import org.apache.thrift.scheme.TupleScheme;
-import org.apache.thrift.protocol.TTupleProtocol;
-import org.apache.thrift.protocol.TProtocolException;
-import org.apache.thrift.EncodingUtils;
-import org.apache.thrift.TException;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.EnumMap;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.EnumSet;
-import java.util.Collections;
-import java.util.BitSet;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-@SuppressWarnings("all") public class AuthInfo implements org.apache.thrift.TBase<AuthInfo,
AuthInfo._Fields>, java.io.Serializable, Cloneable {
+/**
+ * @deprecated since 1.5, use {@link#UserPassToken} instead
+ */
+@SuppressWarnings("serial")
+public class AuthInfo implements org.apache.thrift.TBase<AuthInfo, AuthInfo._Fields>,
java.io.Serializable, Cloneable {
   private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("AuthInfo");
 
   private static final org.apache.thrift.protocol.TField USER_FIELD_DESC = new org.apache.thrift.protocol.TField("user",
org.apache.thrift.protocol.TType.STRING, (short)1);
   private static final org.apache.thrift.protocol.TField PASSWORD_FIELD_DESC = new org.apache.thrift.protocol.TField("password",
org.apache.thrift.protocol.TType.STRING, (short)2);
   private static final org.apache.thrift.protocol.TField INSTANCE_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("instanceId",
org.apache.thrift.protocol.TType.STRING, (short)3);
 
+  @SuppressWarnings("rawtypes")
   private static final Map<Class<? extends IScheme>, SchemeFactory> schemes =
new HashMap<Class<? extends IScheme>, SchemeFactory>();
   static {
     schemes.put(StandardScheme.class, new AuthInfoStandardSchemeFactory());
@@ -418,10 +413,12 @@ import org.slf4j.LoggerFactory;
     return _Fields.findByThriftId(fieldId);
   }
 
+  @SuppressWarnings("unchecked")
   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException
{
     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
   }
 
+  @SuppressWarnings("unchecked")
   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException
{
     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
   }
@@ -480,6 +477,7 @@ import org.slf4j.LoggerFactory;
   }
 
   private static class AuthInfoStandardSchemeFactory implements SchemeFactory {
+    @SuppressWarnings("unchecked")
     public AuthInfoStandardScheme getScheme() {
       return new AuthInfoStandardScheme();
     }
@@ -558,6 +556,7 @@ import org.slf4j.LoggerFactory;
   }
 
   private static class AuthInfoTupleSchemeFactory implements SchemeFactory {
+    @SuppressWarnings("unchecked")
     public AuthInfoTupleScheme getScheme() {
       return new AuthInfoTupleScheme();
     }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/SecurityErrorCode.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/SecurityErrorCode.java?rev=1438354&r1=1438353&r2=1438354&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/SecurityErrorCode.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/thrift/SecurityErrorCode.java
Fri Jan 25 07:04:25 2013
@@ -37,7 +37,13 @@ import org.apache.thrift.TEnum;
   GRANT_INVALID(6),
   BAD_AUTHORIZATIONS(7),
   INVALID_INSTANCEID(8),
-  TABLE_DOESNT_EXIST(9);
+  TABLE_DOESNT_EXIST(9),
+  UNSUPPORTED_OPERATION(10),
+  INVALID_TOKEN(11),
+  AUTHENTICATOR_FAILED(12),
+  AUTHORIZOR_FAILED(13),
+  PERMISSIONHANDLER_FAILED(14),
+  TOKEN_EXPIRED(15);
 
   private final int value;
 
@@ -78,6 +84,18 @@ import org.apache.thrift.TEnum;
         return INVALID_INSTANCEID;
       case 9:
         return TABLE_DOESNT_EXIST;
+      case 10:
+        return UNSUPPORTED_OPERATION;
+      case 11:
+        return INVALID_TOKEN;
+      case 12:
+        return AUTHENTICATOR_FAILED;
+      case 13:
+        return AUTHORIZOR_FAILED;
+      case 14:
+        return PERMISSIONHANDLER_FAILED;
+      case 15:
+        return TOKEN_EXPIRED;
       default:
         return null;
     }

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/AccumuloToken.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/AccumuloToken.java?rev=1438354&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/AccumuloToken.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/AccumuloToken.java
Fri Jan 25 07:04:25 2013
@@ -0,0 +1,14 @@
+package org.apache.accumulo.core.security.tokens;
+
+import javax.security.auth.Destroyable;
+
+import org.apache.thrift.TBase;
+import org.apache.thrift.TFieldIdEnum;
+
+/**
+ * Any AccumuloTokens created need to have an empty constructor as well
+ */
+public interface AccumuloToken<T extends TBase<?,?>, F extends TFieldIdEnum>
extends TBase<T, F>, Destroyable {
+  public String getPrincipal();
+  public boolean equals(AccumuloToken<?,?> token);
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/AccumuloToken.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/InstanceTokenWrapper.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/InstanceTokenWrapper.java?rev=1438354&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/InstanceTokenWrapper.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/InstanceTokenWrapper.java
Fri Jan 25 07:04:25 2013
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+/**
+ * Autogenerated by Thrift Compiler (0.9.0)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ *  @generated
+ */
+package org.apache.accumulo.core.security.tokens;
+
+import org.apache.accumulo.core.security.thrift.ThriftInstanceTokenWrapper;
+
+public class InstanceTokenWrapper {
+  private AccumuloToken<?,?> token; // required
+  private String instance; // required
+  private ThriftInstanceTokenWrapper tikw = null;
+  
+  public InstanceTokenWrapper(AccumuloToken<?,?> token, String instance) {
+    this.token = token;
+    this.instance = instance;
+  }
+  
+  public InstanceTokenWrapper(ThriftInstanceTokenWrapper credentials) {
+    this.token = TokenHelper.unwrap(credentials.token);
+    this.instance = credentials.instance;
+  }
+  
+  public String getInstance() {
+    return this.instance;
+  }
+  
+  public InstanceTokenWrapper setInstance(String instance) {
+    this.instance = instance;
+    tikw = null;
+    return this;
+  }
+  
+  public AccumuloToken<?,?> getToken() {
+    return this.token;
+  }
+  
+  public InstanceTokenWrapper setToken(AccumuloToken<?,?> token) {
+    this.token = token;
+    tikw = null;
+    return this;
+  }
+  
+  public ThriftInstanceTokenWrapper toThrift() {
+    if (tikw == null)
+      tikw = new ThriftInstanceTokenWrapper(TokenHelper.wrapper(token), token.getClass().getName(),
instance);
+    return tikw;
+  }
+  
+  public String getPrincipal() {
+    return token.getPrincipal();
+  }
+  
+  public String toString() {
+    return getPrincipal() + "[" + this.instance + "]-> " + token;
+  }
+  
+  public boolean equals(Object obj) {
+    if (!(obj instanceof InstanceTokenWrapper))
+      return false;
+    InstanceTokenWrapper itw = (InstanceTokenWrapper) obj;
+    return this.instance.equals(itw.instance) && this.token.equals(itw.token);
+  }
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/InstanceTokenWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/KerberosToken.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/KerberosToken.java?rev=1438354&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/KerberosToken.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/KerberosToken.java
Fri Jan 25 07:04:25 2013
@@ -0,0 +1,160 @@
+package org.apache.accumulo.core.security.tokens;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.nio.ByteBuffer;
+import java.security.GeneralSecurityException;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+
+import org.apache.accumulo.core.security.SecurityUtil;
+import org.apache.accumulo.core.security.thrift.ThriftKerberosToken;
+import org.apache.accumulo.core.util.ByteBufferUtil;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.ietf.jgss.GSSContext;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSManager;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public class KerberosToken extends ThriftKerberosToken implements AccumuloToken<ThriftKerberosToken,ThriftKerberosToken._Fields>
{
+  private static final long serialVersionUID = -3592193087970250922L;
+  
+  public KerberosToken() {
+    super();
+    System.setProperty("java.security.auth.login.config", "./conf/jaas.conf");
+
+  }
+  
+  /**
+   * Creats a kerberos token for the provided Principal using the provided keytab
+   * 
+   * @param principalConfig
+   *          This is the principals name in the format NAME/HOST@REALM. {@link org.apache.hadoop.security.SecurityUtil#HOSTNAME_PATTERN}
will automatically be
+   *          replaced by the systems host name.
+   * @param keyTabPath
+   *          Fully qualified path to the principal's keytab file
+   * @throws IOException 
+   */
+  public KerberosToken(String principalConfig, String keyTabPath, String destinationId) throws
IOException {
+    this();
+    SecurityUtil.login(principalConfig, keyTabPath);
+    UserGroupInformation.getLoginUser().doAs(new GetToken(destinationId));
+  }
+  
+  /**
+   * Creates a kerberos token using the arguments, using the jaas.conf idenity "Client"
+   * 
+   * @param username
+   *          users Kerberos username
+   * @param password
+   *          users Kerberos password
+   * @param destination
+   *          name of the Kerberos principal the Accumulo servers are
+   * @throws GeneralSecurityException
+   */
+  public KerberosToken(String username, char[] password, String destination) throws GeneralSecurityException
{
+    this(username, password, destination, "Client");
+  }
+  
+  /**
+   * Creates a kerberos token using the arguments, using the jaas.conf idenity specified
+   * 
+   * @param username
+   *          users Kerberos username
+   * @param password
+   *          users Kerberos password
+   * @param destination
+   *          name of the Kerberos principal the Accumulo servers are
+   * @param contextName
+   *          Identityof the users in the jaas.conf
+   * @throws GeneralSecurityException
+   */
+  public KerberosToken(String username, char[] password, String destination, String contextName)
throws GeneralSecurityException {
+    this();
+    LoginContext loginCtx = null;
+    // "Client" references the JAAS configuration in the jaas.conf file.
+    
+    loginCtx = new LoginContext(contextName, new LoginCallbackHandler(username, password));
+    loginCtx.login();
+    final Subject subject = loginCtx.getSubject();
+    
+    // The GSS context initiation has to be performed as a privileged action.
+    byte[] serviceTicket = Subject.doAs(subject, new GetToken(destination));
+    
+    user = username;
+    ticket = ByteBuffer.wrap(serviceTicket);
+  }
+  
+  class GetToken implements PrivilegedAction<byte[]> {
+    private final GSSContext context;
+    
+    public GetToken(String destination) {
+      try {
+        Oid oid = new Oid("1.2.840.113554.1.2.2");
+        GSSManager manager = GSSManager.getInstance();
+        GSSName serverName = manager.createName(destination, GSSName.NT_USER_NAME);
+        context = manager.createContext(serverName, oid, null, GSSContext.INDEFINITE_LIFETIME);
+      } catch (GSSException e1) {
+        // This is a well documented OID. If it does happen, you have a MASSIVE issue
+        throw new RuntimeException(e1);
+      }
+    }
+    
+    public byte[] run() {
+      try {
+        byte[] token = new byte[0];
+        // This is a one pass context initialization.
+        context.requestMutualAuth(false);
+        context.requestCredDeleg(false);
+        return context.initSecContext(token, 0, 0);
+        
+      } catch (GSSException e) {
+        e.printStackTrace();
+        return null;
+      }
+    }
+  }
+  
+  public String getPrincipal() {
+    return user;
+  }
+  
+  public byte[] getTicket() {
+    return ByteBufferUtil.toBytes(ticket);
+  }
+  
+  private void readObject(ObjectInputStream aInputStream) throws IOException, ClassNotFoundException
{
+    aInputStream.defaultReadObject();
+  }
+  
+  private void writeObject(ObjectOutputStream aOutputStream) throws IOException {
+    aOutputStream.defaultWriteObject();
+  }
+  
+  public void destroy() {
+    Arrays.fill(ticket.array(), (byte) 0);
+    ticket = null;
+  }
+  
+  @Override
+  public boolean isDestroyed() {
+    return ticket == null;
+  }
+  
+  public boolean equals(AccumuloToken<?,?> token) {
+    if (token instanceof KerberosToken) {
+      KerberosToken kt = (KerberosToken) token;
+      return this.user.equals(kt.user) && Arrays.equals(this.getTicket(), kt.getTicket());
+    } else
+      return false;
+  }
+  
+  public String toString() {
+    return "KerberosToken("+this.user+":"+new String(this.getTicket())+")";
+  }
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/KerberosToken.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/LoginCallbackHandler.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/LoginCallbackHandler.java?rev=1438354&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/LoginCallbackHandler.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/LoginCallbackHandler.java
Fri Jan 25 07:04:25 2013
@@ -0,0 +1,53 @@
+package org.apache.accumulo.core.security.tokens;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+public class LoginCallbackHandler implements CallbackHandler {
+  
+  public LoginCallbackHandler() {
+    super();
+  }
+  
+  public LoginCallbackHandler(String name, char[] password) {
+    super();
+    this.username = name;
+    this.password = password;
+  }
+  
+  public LoginCallbackHandler(char[] password) {
+    super();
+    this.password = password;
+  }
+  
+  private char[] password;
+  private String username;
+  
+  /**
+   * Handles the callbacks, and sets the user/password detail.
+   * 
+   * @param callbacks
+   *          the callbacks to handle
+   * @throws IOException
+   *           if an input or output error occurs.
+   */
+  public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
+    
+    for (int i = 0; i < callbacks.length; i++) {
+      if (callbacks[i] instanceof NameCallback && username != null) {
+        NameCallback nc = (NameCallback) callbacks[i];
+        nc.setName(username);
+      } else if (callbacks[i] instanceof PasswordCallback) {
+        PasswordCallback pc = (PasswordCallback) callbacks[i];
+        pc.setPassword(password);
+      } else {
+        throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
+      }
+    }
+  }
+}
\ No newline at end of file

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/LoginCallbackHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/PasswordUpdatable.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/PasswordUpdatable.java?rev=1438354&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/PasswordUpdatable.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/PasswordUpdatable.java
Fri Jan 25 07:04:25 2013
@@ -0,0 +1,7 @@
+package org.apache.accumulo.core.security.tokens;
+
+public interface PasswordUpdatable {
+  public void updatePassword(PasswordUpdatable newToken);
+  public void updatePassword(byte[] newPassword);
+  public byte[] getPassword();
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/PasswordUpdatable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/TokenHelper.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/TokenHelper.java?rev=1438354&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/TokenHelper.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/TokenHelper.java
Fri Jan 25 07:04:25 2013
@@ -0,0 +1,110 @@
+package org.apache.accumulo.core.security.tokens;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.accumulo.core.util.ByteBufferUtil;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.hadoop.io.WritableUtils;
+import org.apache.log4j.Logger;
+import org.apache.thrift.TDeserializer;
+import org.apache.thrift.TException;
+import org.apache.thrift.TSerializer;
+
+public class TokenHelper {
+  private static Logger log = Logger.getLogger(TokenHelper.class);
+  
+  public static ByteBuffer wrapper(AccumuloToken<?,?> token) {
+    return ByteBuffer.wrap(getBytes(token));
+  }
+  
+  private static byte[] getBytes(AccumuloToken<?,?> token) {
+    TSerializer serializer = new TSerializer();
+    ByteArrayOutputStream bout = null;
+    DataOutputStream out = null;
+    try {
+      bout = new ByteArrayOutputStream();
+      out = new DataOutputStream(bout);
+      WritableUtils.writeCompressedString(out, token.getClass().getCanonicalName());
+      
+      WritableUtils.writeCompressedByteArray(out, serializer.serialize(token));
+      return bout.toByteArray();
+    } catch (TException te) {
+      // This shouldn't happen
+      throw new RuntimeException(te);
+    } catch (IOException e) {
+      // This shouldn't happen
+      throw new RuntimeException(e);
+    } finally {
+      try {
+        if (bout != null)
+          bout.close();
+        if (out != null)
+          out.close();
+      } catch (IOException e) {
+        log.error(e);
+      }
+    }
+    
+  }
+  
+  public static String asBase64String(AccumuloToken<?,?> token2) {
+    return new String(Base64.encodeBase64(getBytes(token2)));
+  }
+  
+  public static AccumuloToken<?,?> fromBase64String(String token) {
+    return fromBytes(Base64.decodeBase64(token.getBytes()));
+  }
+  
+  private static AccumuloToken<?,?> fromBytes(byte[] token) {
+    TDeserializer deserializer = new TDeserializer();
+    String clazz = "";
+    ByteArrayInputStream bin = null;
+    DataInputStream in = null;
+    try {
+      try {
+        bin = new ByteArrayInputStream(token);
+        in = new DataInputStream(bin);
+        
+        clazz = WritableUtils.readCompressedString(in);
+        AccumuloToken<?,?> obj = (AccumuloToken<?,?>) Class.forName(clazz).newInstance();
+        
+        byte[] tokenBytes = WritableUtils.readCompressedByteArray(in);
+        deserializer.deserialize(obj, tokenBytes);
+        
+        return obj;
+      } catch (IOException e) {
+        // This shouldn't happen
+        throw new RuntimeException(e);
+      } catch (InstantiationException e) {
+        // This shouldn't happen
+        throw new RuntimeException(e);
+      } catch (IllegalAccessException e) {
+        // This shouldn't happen
+        throw new RuntimeException(e);
+      } catch (TException e) {
+        // This shouldn't happen
+        throw new RuntimeException(e);
+      }
+    } catch (ClassNotFoundException e) {
+      throw new RuntimeException("Unable to load class " + clazz, e);
+    } finally {
+      try {
+        if (bin != null)
+          bin.close();
+        if (in != null)
+          in.close();
+      } catch (IOException e) {
+        log.error(e);
+      }
+    }
+  }
+  
+  public static AccumuloToken<?,?> unwrap(ByteBuffer token) {
+    return fromBytes(ByteBufferUtil.toBytes(token));
+  }
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/TokenHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/UserPassToken.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/UserPassToken.java?rev=1438354&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/UserPassToken.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/UserPassToken.java
Fri Jan 25 07:04:25 2013
@@ -0,0 +1,75 @@
+package org.apache.accumulo.core.security.tokens;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+import org.apache.accumulo.core.security.thrift.AuthInfo;
+import org.apache.accumulo.core.security.thrift.ThriftUserPassToken;
+
+@SuppressWarnings("deprecation")
+public class UserPassToken extends ThriftUserPassToken implements AccumuloToken<ThriftUserPassToken,ThriftUserPassToken._Fields>,
PasswordUpdatable {
+  private static final long serialVersionUID = 7331872580391311737L;
+  
+  public UserPassToken() {
+    super();
+  }
+  
+  public UserPassToken(String user, ByteBuffer password) {
+    super(user, password);
+  }
+  
+  public UserPassToken(String user, byte[] password) {
+    super(user, ByteBuffer.wrap(password));
+  }
+  
+  public UserPassToken(String user, CharSequence password) {
+    this(user, password.toString().getBytes(Charset.forName("UTF-8")));
+  }
+  
+  public UserPassToken(ThriftUserPassToken upt) {
+    super(upt);
+  }
+  
+  public void destroy() {
+    Arrays.fill(password.array(), (byte) 0);
+    password = null;
+  }
+  
+  @Override
+  public boolean isDestroyed() {
+    return password == null;
+  }
+  
+  public static UserPassToken convertAuthInfo(AuthInfo credentials) {
+    return new UserPassToken(credentials.user, credentials.password);
+  }
+  
+  @Override
+  public String getPrincipal() {
+    return user;
+  }
+  
+  @Override
+  public void updatePassword(byte[] newPassword) {
+    this.password = ByteBuffer.wrap(Arrays.copyOf(newPassword, newPassword.length));
+  }
+  
+  @Override
+  public void updatePassword(PasswordUpdatable pu) {
+    updatePassword(pu.getPassword());
+  }
+  
+  public boolean equals(AccumuloToken<?,?> token) {
+    if (token instanceof UserPassToken) {
+      UserPassToken upt = (UserPassToken) token;
+      return this.user.equals(upt.user) && Arrays.equals(this.getPassword(), upt.getPassword());
+    } else {
+      System.out.println("Compared UserPassToken to " + token.getClass());
+      return false;
+    }  }
+  
+  public String toString() {
+    return "UserPassToken("+this.user+":"+new String(this.getPrincipal())+")";
+  }
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/security/tokens/UserPassToken.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message