accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1440568 [1/3] - in /accumulo/trunk: proxy/examples/python/ proxy/examples/ruby/ proxy/src/main/java/org/apache/accumulo/proxy/ proxy/src/main/java/org/apache/accumulo/proxy/thrift/ proxy/src/main/thrift/ proxy/src/test/java/org/apache/accu...
Date Wed, 30 Jan 2013 18:07:37 GMT
Author: ecn
Date: Wed Jan 30 18:07:36 2013
New Revision: 1440568

URL: http://svn.apache.org/viewvc?rev=1440568&view=rev
Log:
ACCUMULO-996 expose user tokens in the proxy

Modified:
    accumulo/trunk/proxy/examples/python/TestClient.py
    accumulo/trunk/proxy/examples/ruby/test_client.rb
    accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
    accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java
    accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/thrift/AccumuloProxy.java
    accumulo/trunk/proxy/src/main/thrift/proxy.thrift
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
    accumulo/trunk/test/src/main/java/org/apache/accumulo/test/functional/BloomFilterTest.java

Modified: accumulo/trunk/proxy/examples/python/TestClient.py
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/examples/python/TestClient.py?rev=1440568&r1=1440567&r2=1440568&view=diff
==============================================================================
--- accumulo/trunk/proxy/examples/python/TestClient.py (original)
+++ accumulo/trunk/proxy/examples/python/TestClient.py Wed Jan 30 18:07:36 2013
@@ -30,17 +30,17 @@ protocol = TCompactProtocol.TCompactProt
 client = AccumuloProxy.Client(protocol)
 transport.open()
 
-userpass = UserPass("root","secret")
+login = client.login(UserPass("root","secret"))
 
-print client.listTables(userpass)
+print client.listTables(login)
 
 testtable = "pythontest"
-if not client.tableExists(userpass, testtable):
-    client.createTable(userpass, testtable, True, TimeType.MILLIS)
+if not client.tableExists(login, testtable):
+    client.createTable(login, testtable, True, TimeType.MILLIS)
 
 row1 = {'a':[ColumnUpdate('a','a',value='value1'), ColumnUpdate('b','b',value='value2')]}
-client.updateAndFlush(userpass, testtable, row1)
+client.updateAndFlush(login, testtable, row1)
 
-cookie = client.createScanner(userpass, testtable, None)
+cookie = client.createScanner(login, testtable, None)
 for entry in client.nextK(cookie, 10).results:
    print entry

Modified: accumulo/trunk/proxy/examples/ruby/test_client.rb
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/examples/ruby/test_client.rb?rev=1440568&r1=1440567&r2=1440568&view=diff
==============================================================================
--- accumulo/trunk/proxy/examples/ruby/test_client.rb (original)
+++ accumulo/trunk/proxy/examples/ruby/test_client.rb Wed Jan 30 18:07:36 2013
@@ -30,7 +30,7 @@ us = UserPass.new({'username'=> 'root', 
 transport.open()
 
 # Test if the server is up
-puts "Server is up? #{proxy.ping(us)}"
+login = proxy.login(us)
 
 # print out a table list
 puts "List of tables: #{proxy.listTables(us).inspect}"

Modified: accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java?rev=1440568&r1=1440567&r2=1440568&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java (original)
+++ accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java Wed Jan
30 18:07:36 2013
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
+import java.util.Random;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
@@ -63,6 +64,7 @@ import org.apache.accumulo.core.security
 import org.apache.accumulo.core.security.ColumnVisibility;
 import org.apache.accumulo.core.security.SystemPermission;
 import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.security.tokens.SecurityToken;
 import org.apache.accumulo.core.security.tokens.UserPassToken;
 import org.apache.accumulo.core.util.ByteBufferUtil;
 import org.apache.accumulo.core.util.TextUtil;
@@ -128,6 +130,8 @@ public class ProxyServer implements Accu
 
   protected Cache<UUID,ScannerPlusIterator> scannerCache;
   protected Cache<UUID,BatchWriter> writerCache;
+  protected Cache<ByteBuffer, SecurityToken> tokenCache;
+  private Random random = new Random();
   
   public ProxyServer(Properties props) {
     String useMock = props.getProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance");
@@ -140,10 +144,14 @@ public class ProxyServer implements Accu
     scannerCache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000).removalListener(new
CloseScanner()).build();
     
     writerCache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000).removalListener(new
CloseWriter()).build();
+    tokenCache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000).build();
   }
   
-  protected Connector getConnector(UserPass userpass) throws Exception {
-    Connector connector = instance.getConnector(new UserPassToken(userpass.getUsername(),
userpass.bufferForPassword()));
+  protected Connector getConnector(ByteBuffer login) throws Exception {
+    SecurityToken user = tokenCache.getIfPresent(login);
+    if (user == null)
+      throw new org.apache.accumulo.proxy.thrift.AccumuloSecurityException("unknown user");
+    Connector connector = instance.getConnector(user);
     return connector;
   }
   
@@ -170,46 +178,41 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public boolean ping(UserPass userpass) throws TException {
-    return true;
-  }
-  
-  @Override
-  public int addConstraint(UserPass userpass, String tableName, String constraintClassName)
throws TException {
+  public int addConstraint(ByteBuffer login, String tableName, String constraintClassName)
throws TException {
     try {
-      return getConnector(userpass).tableOperations().addConstraint(tableName, constraintClassName);
+      return getConnector(login).tableOperations().addConstraint(tableName, constraintClassName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void addSplits(UserPass userpass, String tableName, Set<ByteBuffer> splits)
throws TException {
+  public void addSplits(ByteBuffer login, String tableName, Set<ByteBuffer> splits)
throws TException {
     try {
       SortedSet<Text> sorted = new TreeSet<Text>();
       for (ByteBuffer split : splits) {
         sorted.add(ByteBufferUtil.toText(split));
       }
-      getConnector(userpass).tableOperations().addSplits(tableName, sorted);
+      getConnector(login).tableOperations().addSplits(tableName, sorted);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void clearLocatorCache(UserPass userpass, String tableName) throws TException {
+  public void clearLocatorCache(ByteBuffer login, String tableName) throws TException {
     try {
-      getConnector(userpass).tableOperations().clearLocatorCache(tableName);
+      getConnector(login).tableOperations().clearLocatorCache(tableName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void compactTable(UserPass userpass, String tableName, ByteBuffer start, ByteBuffer
end, List<org.apache.accumulo.proxy.thrift.IteratorSetting> iterators, boolean flush,
+  public void compactTable(ByteBuffer login, String tableName, ByteBuffer start, ByteBuffer
end, List<org.apache.accumulo.proxy.thrift.IteratorSetting> iterators, boolean flush,
       boolean wait) throws TException {
     try {
-      getConnector(userpass).tableOperations().compact(tableName, ByteBufferUtil.toText(start),
ByteBufferUtil.toText(end), getIteratorSettings(iterators),
+      getConnector(login).tableOperations().compact(tableName, ByteBufferUtil.toText(start),
ByteBufferUtil.toText(end), getIteratorSettings(iterators),
           flush, wait);
     } catch (Exception e) {
       throw translateException(e);
@@ -217,10 +220,10 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void cancelCompaction(UserPass userpass, String tableName) throws org.apache.accumulo.proxy.thrift.AccumuloSecurityException,
+  public void cancelCompaction(ByteBuffer login, String tableName) throws org.apache.accumulo.proxy.thrift.AccumuloSecurityException,
       org.apache.accumulo.proxy.thrift.TableNotFoundException, org.apache.accumulo.proxy.thrift.AccumuloException,
TException {
     try {
-      getConnector(userpass).tableOperations().cancelCompaction(tableName);
+      getConnector(login).tableOperations().cancelCompaction(tableName);
     } catch (Exception e) {
       throw translateException(e);
     }
@@ -237,57 +240,57 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void createTable(UserPass userpass, String tableName, boolean versioningIter, org.apache.accumulo.proxy.thrift.TimeType
timeType) throws TException {
+  public void createTable(ByteBuffer login, String tableName, boolean versioningIter, org.apache.accumulo.proxy.thrift.TimeType
timeType) throws TException {
     try {
       if (timeType == null)
         timeType = org.apache.accumulo.proxy.thrift.TimeType.MILLIS;
       
-      getConnector(userpass).tableOperations().create(tableName, versioningIter, TimeType.valueOf(timeType.toString()));
+      getConnector(login).tableOperations().create(tableName, versioningIter, TimeType.valueOf(timeType.toString()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void deleteTable(UserPass userpass, String tableName) throws TException {
+  public void deleteTable(ByteBuffer login, String tableName) throws TException {
     try {
-      getConnector(userpass).tableOperations().delete(tableName);
+      getConnector(login).tableOperations().delete(tableName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void deleteRows(UserPass userpass, String tableName, ByteBuffer start, ByteBuffer
end) throws TException {
+  public void deleteRows(ByteBuffer login, String tableName, ByteBuffer start, ByteBuffer
end) throws TException {
     try {
-      getConnector(userpass).tableOperations().deleteRows(tableName, ByteBufferUtil.toText(start),
ByteBufferUtil.toText(end));
+      getConnector(login).tableOperations().deleteRows(tableName, ByteBufferUtil.toText(start),
ByteBufferUtil.toText(end));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public boolean tableExists(UserPass userpass, String tableName) throws TException {
+  public boolean tableExists(ByteBuffer login, String tableName) throws TException {
     try {
-      return getConnector(userpass).tableOperations().exists(tableName);
+      return getConnector(login).tableOperations().exists(tableName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void flushTable(UserPass userpass, String tableName, ByteBuffer startRow, ByteBuffer
endRow, boolean wait) throws TException {
+  public void flushTable(ByteBuffer login, String tableName, ByteBuffer startRow, ByteBuffer
endRow, boolean wait) throws TException {
     try {
-      getConnector(userpass).tableOperations().flush(tableName, ByteBufferUtil.toText(startRow),
ByteBufferUtil.toText(endRow), wait);
+      getConnector(login).tableOperations().flush(tableName, ByteBufferUtil.toText(startRow),
ByteBufferUtil.toText(endRow), wait);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public Map<String,Set<String>> getLocalityGroups(UserPass userpass, String
tableName) throws TException {
+  public Map<String,Set<String>> getLocalityGroups(ByteBuffer login, String tableName)
throws TException {
     try {
-      Map<String,Set<Text>> groups = getConnector(userpass).tableOperations().getLocalityGroups(tableName);
+      Map<String,Set<Text>> groups = getConnector(login).tableOperations().getLocalityGroups(tableName);
       Map<String,Set<String>> ret = new HashMap<String,Set<String>>();
       for (String key : groups.keySet()) {
         ret.put(key, new HashSet<String>());
@@ -302,17 +305,18 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public ByteBuffer getMaxRow(UserPass userpass, String tableName, Set<ByteBuffer>
auths, ByteBuffer startRow, boolean startinclusive,
+  public ByteBuffer getMaxRow(ByteBuffer login, String tableName, Set<ByteBuffer> auths,
ByteBuffer startRow, boolean startinclusive,
       ByteBuffer endRow, boolean endinclusive) throws TException {
     try {
-      Connector connector = getConnector(userpass);
+      Connector connector = getConnector(login);
       Text startText = ByteBufferUtil.toText(startRow);
       Text endText = ByteBufferUtil.toText(endRow);
       Authorizations auth;
       if (auths != null) {
         auth = getAuthorizations(auths);
       } else {
-        auth = connector.securityOperations().getUserAuthorizations(userpass.getUsername());
+        SecurityToken token = tokenCache.getIfPresent(login);
+        auth = connector.securityOperations().getUserAuthorizations(token.getPrincipal());
       }
       Text max = connector.tableOperations().getMaxRow(tableName, auth, startText, startinclusive,
endText, endinclusive);
       return TextUtil.getByteBuffer(max);
@@ -322,11 +326,11 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public Map<String,String> getTableProperties(UserPass userpass, String tableName)
throws TException {
+  public Map<String,String> getTableProperties(ByteBuffer login, String tableName)
throws TException {
     try {
       Map<String,String> ret = new HashMap<String,String>();
       
-      for (Map.Entry<String,String> entry : getConnector(userpass).tableOperations().getProperties(tableName))
{
+      for (Map.Entry<String,String> entry : getConnector(login).tableOperations().getProperties(tableName))
{
         ret.put(entry.getKey(), entry.getValue());
       }
       return ret;
@@ -336,9 +340,9 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public List<ByteBuffer> getSplits(UserPass userpass, String tableName, int maxSplits)
throws TException {
+  public List<ByteBuffer> getSplits(ByteBuffer login, String tableName, int maxSplits)
throws TException {
     try {
-      Collection<Text> splits = getConnector(userpass).tableOperations().getSplits(tableName,
maxSplits);
+      Collection<Text> splits = getConnector(login).tableOperations().getSplits(tableName,
maxSplits);
       List<ByteBuffer> ret = new ArrayList<ByteBuffer>();
       for (Text split : splits) {
         ret.add(TextUtil.getByteBuffer(split));
@@ -350,79 +354,79 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public Set<String> listTables(UserPass userpass) throws TException {
+  public Set<String> listTables(ByteBuffer login) throws TException {
     try {
-      return getConnector(userpass).tableOperations().list();
+      return getConnector(login).tableOperations().list();
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public Map<String,Integer> listConstraints(UserPass userpass, String arg2) throws
TException {
+  public Map<String,Integer> listConstraints(ByteBuffer login, String arg2) throws
TException {
     try {
-      return getConnector(userpass).tableOperations().listConstraints(arg2);
+      return getConnector(login).tableOperations().listConstraints(arg2);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void mergeTablets(UserPass userpass, String tableName, ByteBuffer start, ByteBuffer
end) throws TException {
+  public void mergeTablets(ByteBuffer login, String tableName, ByteBuffer start, ByteBuffer
end) throws TException {
     try {
-      getConnector(userpass).tableOperations().merge(tableName, ByteBufferUtil.toText(start),
ByteBufferUtil.toText(end));
+      getConnector(login).tableOperations().merge(tableName, ByteBufferUtil.toText(start),
ByteBufferUtil.toText(end));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void offlineTable(UserPass userpass, String tableName) throws TException {
+  public void offlineTable(ByteBuffer login, String tableName) throws TException {
     try {
-      getConnector(userpass).tableOperations().offline(tableName);
+      getConnector(login).tableOperations().offline(tableName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void onlineTable(UserPass userpass, String tableName) throws TException {
+  public void onlineTable(ByteBuffer login, String tableName) throws TException {
     try {
-      getConnector(userpass).tableOperations().online(tableName);
+      getConnector(login).tableOperations().online(tableName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void removeConstraint(UserPass userpass, String tableName, int number) throws TException
{
+  public void removeConstraint(ByteBuffer login, String tableName, int number) throws TException
{
     try {
-      getConnector(userpass).tableOperations().removeConstraint(tableName, number);
+      getConnector(login).tableOperations().removeConstraint(tableName, number);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void removeTableProperty(UserPass userpass, String tableName, String property) throws
TException {
+  public void removeTableProperty(ByteBuffer login, String tableName, String property) throws
TException {
     try {
-      getConnector(userpass).tableOperations().removeProperty(tableName, property);
+      getConnector(login).tableOperations().removeProperty(tableName, property);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void renameTable(UserPass userpass, String oldTableName, String newTableName) throws
TException {
+  public void renameTable(ByteBuffer login, String oldTableName, String newTableName) throws
TException {
     try {
-      getConnector(userpass).tableOperations().rename(oldTableName, newTableName);
+      getConnector(login).tableOperations().rename(oldTableName, newTableName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void setLocalityGroups(UserPass userpass, String tableName, Map<String,Set<String>>
groupStrings) throws TException {
+  public void setLocalityGroups(ByteBuffer login, String tableName, Map<String,Set<String>>
groupStrings) throws TException {
     try {
       Map<String,Set<Text>> groups = new HashMap<String,Set<Text>>();
       for (String key : groupStrings.keySet()) {
@@ -431,62 +435,62 @@ public class ProxyServer implements Accu
           groups.get(key).add(new Text(val));
         }
       }
-      getConnector(userpass).tableOperations().setLocalityGroups(tableName, groups);
+      getConnector(login).tableOperations().setLocalityGroups(tableName, groups);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void setTableProperty(UserPass userpass, String tableName, String property, String
value) throws TException {
+  public void setTableProperty(ByteBuffer login, String tableName, String property, String
value) throws TException {
     try {
-      getConnector(userpass).tableOperations().setProperty(tableName, property, value);
+      getConnector(login).tableOperations().setProperty(tableName, property, value);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public Map<String,String> tableIdMap(UserPass userpass) throws TException {
+  public Map<String,String> tableIdMap(ByteBuffer login) throws TException {
     try {
-      return getConnector(userpass).tableOperations().tableIdMap();
+      return getConnector(login).tableOperations().tableIdMap();
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public Map<String,String> getSiteConfiguration(UserPass userpass) throws TException
{
+  public Map<String,String> getSiteConfiguration(ByteBuffer login) throws TException
{
     try {
-      return getConnector(userpass).instanceOperations().getSiteConfiguration();
+      return getConnector(login).instanceOperations().getSiteConfiguration();
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public Map<String,String> getSystemConfiguration(UserPass userpass) throws TException
{
+  public Map<String,String> getSystemConfiguration(ByteBuffer login) throws TException
{
     try {
-      return getConnector(userpass).instanceOperations().getSystemConfiguration();
+      return getConnector(login).instanceOperations().getSystemConfiguration();
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public List<String> getTabletServers(UserPass userpass) throws TException {
+  public List<String> getTabletServers(ByteBuffer login) throws TException {
     try {
-      return getConnector(userpass).instanceOperations().getTabletServers();
+      return getConnector(login).instanceOperations().getTabletServers();
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public List<org.apache.accumulo.proxy.thrift.ActiveScan> getActiveScans(UserPass
userpass, String tserver) throws TException {
+  public List<org.apache.accumulo.proxy.thrift.ActiveScan> getActiveScans(ByteBuffer
login, String tserver) throws TException {
     List<org.apache.accumulo.proxy.thrift.ActiveScan> result = new ArrayList<org.apache.accumulo.proxy.thrift.ActiveScan>();
     try {
-      List<ActiveScan> activeScans = getConnector(userpass).instanceOperations().getActiveScans(tserver);
+      List<ActiveScan> activeScans = getConnector(login).instanceOperations().getActiveScans(tserver);
       for (ActiveScan scan : activeScans) {
         org.apache.accumulo.proxy.thrift.ActiveScan pscan = new org.apache.accumulo.proxy.thrift.ActiveScan();
         pscan.client = scan.getClient();
@@ -534,10 +538,10 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public List<org.apache.accumulo.proxy.thrift.ActiveCompaction> getActiveCompactions(UserPass
userpass, String tserver) throws TException {
+  public List<org.apache.accumulo.proxy.thrift.ActiveCompaction> getActiveCompactions(ByteBuffer
login, String tserver) throws TException {
     try {
       List<org.apache.accumulo.proxy.thrift.ActiveCompaction> result = new ArrayList<org.apache.accumulo.proxy.thrift.ActiveCompaction>();
-      List<ActiveCompaction> active = getConnector(userpass).instanceOperations().getActiveCompactions(tserver);
+      List<ActiveCompaction> active = getConnector(login).instanceOperations().getActiveCompactions(tserver);
       for (ActiveCompaction comp : active) {
         org.apache.accumulo.proxy.thrift.ActiveCompaction pcomp = new org.apache.accumulo.proxy.thrift.ActiveCompaction();
         pcomp.age = comp.getAge();
@@ -570,148 +574,148 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void removeProperty(UserPass userpass, String property) throws TException {
+  public void removeProperty(ByteBuffer login, String property) throws TException {
     try {
-      getConnector(userpass).instanceOperations().removeProperty(property);
+      getConnector(login).instanceOperations().removeProperty(property);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void setProperty(UserPass userpass, String property, String value) throws TException
{
+  public void setProperty(ByteBuffer login, String property, String value) throws TException
{
     try {
-      getConnector(userpass).instanceOperations().setProperty(property, value);
+      getConnector(login).instanceOperations().setProperty(property, value);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public boolean testClassLoad(UserPass userpass, String className, String asTypeName) throws
TException {
+  public boolean testClassLoad(ByteBuffer login, String className, String asTypeName) throws
TException {
     try {
-      return getConnector(userpass).instanceOperations().testClassLoad(className, asTypeName);
+      return getConnector(login).instanceOperations().testClassLoad(className, asTypeName);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public boolean authenticateUser(UserPass userpass, String user, ByteBuffer password) throws
TException {
+  public boolean authenticateUser(ByteBuffer login, String user, ByteBuffer password) throws
TException {
     try {
-      return getConnector(userpass).securityOperations().authenticateUser(new UserPassToken(user,
password.array()));
+      return getConnector(login).securityOperations().authenticateUser(new UserPassToken(user,
password.array()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void changeUserAuthorizations(UserPass userpass, String user, Set<ByteBuffer>
authorizations) throws TException {
+  public void changeUserAuthorizations(ByteBuffer login, String user, Set<ByteBuffer>
authorizations) throws TException {
     try {
       Set<String> auths = new HashSet<String>();
       for (ByteBuffer auth : authorizations) {
         auths.add(ByteBufferUtil.toString(auth));
       }
-      getConnector(userpass).securityOperations().changeUserAuthorizations(user, new Authorizations(auths.toArray(new
String[0])));
+      getConnector(login).securityOperations().changeUserAuthorizations(user, new Authorizations(auths.toArray(new
String[0])));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void changeUserPassword(UserPass userpass, String user, ByteBuffer password) throws
TException {
+  public void changeUserPassword(ByteBuffer login, String user, ByteBuffer password) throws
TException {
     try {
-      getConnector(userpass).securityOperations().changeUserPassword(new UserPassToken(user,
password.array()));
+      getConnector(login).securityOperations().changeUserPassword(new UserPassToken(user,
password.array()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void createUser(UserPass userpass, String user, ByteBuffer password) throws TException
{
+  public void createUser(ByteBuffer login, String user, ByteBuffer password) throws TException
{
     try {
-      getConnector(userpass).securityOperations().createUser(new UserPassToken(user, password));
+      getConnector(login).securityOperations().createUser(new UserPassToken(user, password));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void dropUser(UserPass userpass, String user) throws TException {
+  public void dropUser(ByteBuffer login, String user) throws TException {
     try {
-      getConnector(userpass).securityOperations().dropUser(user);
+      getConnector(login).securityOperations().dropUser(user);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public List<ByteBuffer> getUserAuthorizations(UserPass userpass, String user) throws
TException {
+  public List<ByteBuffer> getUserAuthorizations(ByteBuffer login, String user) throws
TException {
     try {
-      return getConnector(userpass).securityOperations().getUserAuthorizations(user).getAuthorizationsBB();
+      return getConnector(login).securityOperations().getUserAuthorizations(user).getAuthorizationsBB();
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void grantSystemPermission(UserPass userpass, String user, org.apache.accumulo.proxy.thrift.SystemPermission
perm) throws TException {
+  public void grantSystemPermission(ByteBuffer login, String user, org.apache.accumulo.proxy.thrift.SystemPermission
perm) throws TException {
     try {
-      getConnector(userpass).securityOperations().grantSystemPermission(user, SystemPermission.getPermissionById((byte)
perm.getValue()));
+      getConnector(login).securityOperations().grantSystemPermission(user, SystemPermission.getPermissionById((byte)
perm.getValue()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void grantTablePermission(UserPass userpass, String user, String table, org.apache.accumulo.proxy.thrift.TablePermission
perm) throws TException {
+  public void grantTablePermission(ByteBuffer login, String user, String table, org.apache.accumulo.proxy.thrift.TablePermission
perm) throws TException {
     try {
-      getConnector(userpass).securityOperations().grantTablePermission(user, table, TablePermission.getPermissionById((byte)
perm.getValue()));
+      getConnector(login).securityOperations().grantTablePermission(user, table, TablePermission.getPermissionById((byte)
perm.getValue()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public boolean hasSystemPermission(UserPass userpass, String user, org.apache.accumulo.proxy.thrift.SystemPermission
perm) throws TException {
+  public boolean hasSystemPermission(ByteBuffer login, String user, org.apache.accumulo.proxy.thrift.SystemPermission
perm) throws TException {
     try {
-      return getConnector(userpass).securityOperations().hasSystemPermission(user, SystemPermission.getPermissionById((byte)
perm.getValue()));
+      return getConnector(login).securityOperations().hasSystemPermission(user, SystemPermission.getPermissionById((byte)
perm.getValue()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public boolean hasTablePermission(UserPass userpass, String user, String table, org.apache.accumulo.proxy.thrift.TablePermission
perm) throws TException {
+  public boolean hasTablePermission(ByteBuffer login, String user, String table, org.apache.accumulo.proxy.thrift.TablePermission
perm) throws TException {
     try {
-      return getConnector(userpass).securityOperations().hasTablePermission(user, table,
TablePermission.getPermissionById((byte) perm.getValue()));
+      return getConnector(login).securityOperations().hasTablePermission(user, table, TablePermission.getPermissionById((byte)
perm.getValue()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public Set<String> listUsers(UserPass userpass) throws TException {
+  public Set<String> listUsers(ByteBuffer login) throws TException {
     try {
-      return getConnector(userpass).securityOperations().listUsers();
+      return getConnector(login).securityOperations().listUsers();
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void revokeSystemPermission(UserPass userpass, String user, org.apache.accumulo.proxy.thrift.SystemPermission
perm) throws TException {
+  public void revokeSystemPermission(ByteBuffer login, String user, org.apache.accumulo.proxy.thrift.SystemPermission
perm) throws TException {
     try {
-      getConnector(userpass).securityOperations().revokeSystemPermission(user, SystemPermission.getPermissionById((byte)
perm.getValue()));
+      getConnector(login).securityOperations().revokeSystemPermission(user, SystemPermission.getPermissionById((byte)
perm.getValue()));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void revokeTablePermission(UserPass userpass, String user, String table, org.apache.accumulo.proxy.thrift.TablePermission
perm) throws TException {
+  public void revokeTablePermission(ByteBuffer login, String user, String table, org.apache.accumulo.proxy.thrift.TablePermission
perm) throws TException {
     try {
-      getConnector(userpass).securityOperations().revokeTablePermission(user, table, TablePermission.getPermissionById((byte)
perm.getValue()));
+      getConnector(login).securityOperations().revokeTablePermission(user, table, TablePermission.getPermissionById((byte)
perm.getValue()));
     } catch (Exception e) {
       throw translateException(e);
     }
@@ -726,16 +730,17 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public String createScanner(UserPass userpass, String tableName, ScanOptions opts)
+  public String createScanner(ByteBuffer login, String tableName, ScanOptions opts)
       throws TException {
     try {
-      Connector connector = getConnector(userpass);
+      Connector connector = getConnector(login);
       
       Authorizations auth;
       if (opts != null && opts.isSetAuthorizations()) {
         auth = getAuthorizations(opts.authorizations);
       } else {
-        auth = connector.securityOperations().getUserAuthorizations(userpass.getUsername());
+        SecurityToken token = tokenCache.getIfPresent(login);
+        auth = connector.securityOperations().getUserAuthorizations(token.getPrincipal());
       }
       Scanner scanner = connector.createScanner(tableName, auth);
       
@@ -777,10 +782,10 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public String createBatchScanner(UserPass userpass, String tableName, BatchScanOptions
opts)
+  public String createBatchScanner(ByteBuffer login, String tableName, BatchScanOptions opts)
       throws TException {
     try {
-      Connector connector = getConnector(userpass);
+      Connector connector = getConnector(login);
       
             
       int threads = 10;
@@ -788,7 +793,8 @@ public class ProxyServer implements Accu
       if (opts != null && opts.isSetAuthorizations()) {
         auth = getAuthorizations(opts.authorizations);
       } else {
-        auth = connector.securityOperations().getUserAuthorizations(userpass.getUsername());
+        SecurityToken token = tokenCache.getIfPresent(login);
+        auth = connector.securityOperations().getUserAuthorizations(token.getPrincipal());
       }
       if (opts != null && opts.threads > 0)
         threads = opts.threads;
@@ -885,9 +891,9 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void updateAndFlush(UserPass userpass, String tableName, Map<ByteBuffer,List<ColumnUpdate>>
cells) throws TException {
+  public void updateAndFlush(ByteBuffer login, String tableName, Map<ByteBuffer,List<ColumnUpdate>>
cells) throws TException {
     try {
-      BatchWriter writer = getWriter(userpass, tableName, null);
+      BatchWriter writer = getWriter(login, tableName, null);
       addCellsToWriter(cells, writer);
       writer.flush();
       writer.close();
@@ -935,9 +941,9 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public String createWriter(UserPass userpass, String tableName, WriterOptions opts) throws
TException {
+  public String createWriter(ByteBuffer login, String tableName, WriterOptions opts) throws
TException {
     try {
-      BatchWriter writer = getWriter(userpass, tableName, opts);
+      BatchWriter writer = getWriter(login, tableName, opts);
       UUID uuid = UUID.randomUUID();
       writerCache.put(uuid, writer);
       return uuid.toString();
@@ -986,7 +992,7 @@ public class ProxyServer implements Accu
     }
   }
   
-  private BatchWriter getWriter(UserPass userpass, String tableName, WriterOptions opts)
throws Exception {
+  private BatchWriter getWriter(ByteBuffer login, String tableName, WriterOptions opts) throws
Exception {
     BatchWriterConfig cfg = new BatchWriterConfig();
     if (opts != null) {
       if (opts.maxMemory != 0)
@@ -998,7 +1004,7 @@ public class ProxyServer implements Accu
       if (opts.latencyMs != 0)
         cfg.setMaxLatency(opts.latencyMs, TimeUnit.MILLISECONDS);
     }
-    return getConnector(userpass).createBatchWriter(tableName, cfg);
+    return getConnector(login).createBatchWriter(tableName, cfg);
   }
   
   private IteratorSetting getIteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting
setting) {
@@ -1026,56 +1032,56 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void attachIterator(UserPass userpass, String tableName, org.apache.accumulo.proxy.thrift.IteratorSetting
setting, Set<org.apache.accumulo.proxy.thrift.IteratorScope> scopes) throws TException
{
+  public void attachIterator(ByteBuffer login, String tableName, org.apache.accumulo.proxy.thrift.IteratorSetting
setting, Set<org.apache.accumulo.proxy.thrift.IteratorScope> scopes) throws TException
{
     try {
-      getConnector(userpass).tableOperations().attachIterator(tableName, getIteratorSetting(setting),
getIteratorScopes(scopes));
+      getConnector(login).tableOperations().attachIterator(tableName, getIteratorSetting(setting),
getIteratorScopes(scopes));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void checkIteratorConflicts(UserPass userpass, String tableName, org.apache.accumulo.proxy.thrift.IteratorSetting
setting, Set<org.apache.accumulo.proxy.thrift.IteratorScope> scopes)
+  public void checkIteratorConflicts(ByteBuffer login, String tableName, org.apache.accumulo.proxy.thrift.IteratorSetting
setting, Set<org.apache.accumulo.proxy.thrift.IteratorScope> scopes)
       throws TException {
     try {
-      getConnector(userpass).tableOperations().checkIteratorConflicts(tableName, getIteratorSetting(setting),
getIteratorScopes(scopes));
+      getConnector(login).tableOperations().checkIteratorConflicts(tableName, getIteratorSetting(setting),
getIteratorScopes(scopes));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void cloneTable(UserPass userpass, String tableName, String newTableName, boolean
flush, Map<String,String> propertiesToSet,
+  public void cloneTable(ByteBuffer login, String tableName, String newTableName, boolean
flush, Map<String,String> propertiesToSet,
       Set<String> propertiesToExclude) throws TException {
     try {
-      getConnector(userpass).tableOperations().clone(tableName, newTableName, flush, propertiesToSet,
propertiesToExclude);
+      getConnector(login).tableOperations().clone(tableName, newTableName, flush, propertiesToSet,
propertiesToExclude);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void exportTable(UserPass userpass, String tableName, String exportDir) throws TException
{
+  public void exportTable(ByteBuffer login, String tableName, String exportDir) throws TException
{
     try {
-      getConnector(userpass).tableOperations().exportTable(tableName, exportDir);
+      getConnector(login).tableOperations().exportTable(tableName, exportDir);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public void importTable(UserPass userpass, String tableName, String importDir) throws TException
{
+  public void importTable(ByteBuffer login, String tableName, String importDir) throws TException
{
     try {
-      getConnector(userpass).tableOperations().importTable(tableName, importDir);
+      getConnector(login).tableOperations().importTable(tableName, importDir);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public org.apache.accumulo.proxy.thrift.IteratorSetting getIteratorSetting(UserPass userpass,
String tableName, String iteratorName, org.apache.accumulo.proxy.thrift.IteratorScope scope)
throws TException {
+  public org.apache.accumulo.proxy.thrift.IteratorSetting getIteratorSetting(ByteBuffer login,
String tableName, String iteratorName, org.apache.accumulo.proxy.thrift.IteratorScope scope)
throws TException {
     try {
-      IteratorSetting is = getConnector(userpass).tableOperations().getIteratorSetting(tableName,
iteratorName, getIteratorScope(scope));
+      IteratorSetting is = getConnector(login).tableOperations().getIteratorSetting(tableName,
iteratorName, getIteratorScope(scope));
       return new org.apache.accumulo.proxy.thrift.IteratorSetting(is.getPriority(), is.getName(),
is.getIteratorClass(), is.getOptions());
     } catch (Exception e) {
       throw translateException(e);
@@ -1083,9 +1089,9 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public Map<String,Set<org.apache.accumulo.proxy.thrift.IteratorScope>> listIterators(UserPass
userpass, String tableName) throws TException {
+  public Map<String,Set<org.apache.accumulo.proxy.thrift.IteratorScope>> listIterators(ByteBuffer
login, String tableName) throws TException {
     try {
-      Map<String,EnumSet<IteratorScope>> iterMap = getConnector(userpass).tableOperations().listIterators(tableName);
+      Map<String,EnumSet<IteratorScope>> iterMap = getConnector(login).tableOperations().listIterators(tableName);
       Map<String,Set<org.apache.accumulo.proxy.thrift.IteratorScope>> result
= new HashMap<String,Set<org.apache.accumulo.proxy.thrift.IteratorScope>>();
       for (Entry<String,EnumSet<IteratorScope>> entry : iterMap.entrySet()) {
         result.put(entry.getKey(), getProxyIteratorScopes(entry.getValue()));
@@ -1097,18 +1103,18 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void removeIterator(UserPass userpass, String tableName, String iterName, Set<org.apache.accumulo.proxy.thrift.IteratorScope>
scopes) throws TException {
+  public void removeIterator(ByteBuffer login, String tableName, String iterName, Set<org.apache.accumulo.proxy.thrift.IteratorScope>
scopes) throws TException {
     try {
-      getConnector(userpass).tableOperations().removeIterator(tableName, iterName, getIteratorScopes(scopes));
+      getConnector(login).tableOperations().removeIterator(tableName, iterName, getIteratorScopes(scopes));
     } catch (Exception e) {
       throw translateException(e);
     }
   }
   
   @Override
-  public Set<org.apache.accumulo.proxy.thrift.Range> splitRangeByTablets(UserPass userpass,
String tableName, org.apache.accumulo.proxy.thrift.Range range, int maxSplits) throws TException
{
+  public Set<org.apache.accumulo.proxy.thrift.Range> splitRangeByTablets(ByteBuffer
login, String tableName, org.apache.accumulo.proxy.thrift.Range range, int maxSplits) throws
TException {
     try {
-      Set<Range> ranges = getConnector(userpass).tableOperations().splitRangeByTablets(tableName,
getRange(range), maxSplits);
+      Set<Range> ranges = getConnector(login).tableOperations().splitRangeByTablets(tableName,
getRange(range), maxSplits);
       Set<org.apache.accumulo.proxy.thrift.Range> result = new HashSet<org.apache.accumulo.proxy.thrift.Range>();
       for (Range r : ranges) {
         result.add(getRange(r));
@@ -1136,9 +1142,9 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void importDirectory(UserPass userpass, String tableName, String importDir, String
failureDir, boolean setTime) throws TException {
+  public void importDirectory(ByteBuffer login, String tableName, String importDir, String
failureDir, boolean setTime) throws TException {
     try {
-      getConnector(userpass).tableOperations().importDirectory(tableName, importDir, failureDir,
setTime);
+      getConnector(login).tableOperations().importDirectory(tableName, importDir, failureDir,
setTime);
     } catch (Exception e) {
       throw translateException(e);
     }
@@ -1161,11 +1167,18 @@ public class ProxyServer implements Accu
   }
   
   @Override
-  public void pingTabletServer(UserPass userpass, String tserver) throws TException {
+  public void pingTabletServer(ByteBuffer login, String tserver) throws TException {
     try {
-      getConnector(userpass).instanceOperations().ping(tserver);
+      getConnector(login).instanceOperations().ping(tserver);
     } catch (Exception e) {
       throw translateException(e);
     }
   }
+
+  @Override
+  public ByteBuffer login(UserPass login) throws TException {
+    ByteBuffer result = ByteBuffer.wrap(Long.toHexString(random.nextLong()).getBytes());
+    tokenCache.put(result, new UserPassToken(login.getUsername(), login.getPassword()));
+    return result;
+  }
 }

Modified: accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java?rev=1440568&r1=1440567&r2=1440568&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java (original)
+++ accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java Wed
Jan 30 18:07:36 2013
@@ -59,30 +59,30 @@ public class TestProxyClient {
   public static void main(String[] args) throws Exception {
     
     TestProxyClient tpc = new TestProxyClient("localhost", 42424);
-    UserPass userpass = new UserPass();
-    userpass.setUsername("root");
-    userpass.setPassword("secret".getBytes());
+    UserPass userPass = new UserPass("root", ByteBuffer.wrap("secret".getBytes()));
+    
+    System.out.println("Logging in");
+    ByteBuffer login = tpc.proxy.login(userPass);
     
     System.out.println("Creating user: ");
-    if (!tpc.proxy().listUsers(userpass).contains("testuser")) {
-      tpc.proxy().createUser(userpass, "testuser", ByteBuffer.wrap("testpass".getBytes()));
+    if (!tpc.proxy().listUsers(login).contains("testuser")) {
+      tpc.proxy().createUser(login, "testuser", ByteBuffer.wrap("testpass".getBytes()));
     }
-    System.out.println("UserList: " + tpc.proxy().listUsers(userpass));
+    System.out.println("UserList: " + tpc.proxy().listUsers(login));
     
-    System.out.println("Pinging: " + tpc.proxy().ping(userpass));
-    System.out.println("Listing: " + tpc.proxy().listTables(userpass));
+    System.out.println("Listing: " + tpc.proxy().listTables(login));
     
     System.out.println("Deleting: ");
     String testTable = "testtableOMGOMGOMG";
     
     System.out.println("Creating: ");
     
-    if (tpc.proxy().tableExists(userpass, testTable))
-      tpc.proxy().deleteTable(userpass, testTable);
+    if (tpc.proxy().tableExists(login, testTable))
+      tpc.proxy().deleteTable(login, testTable);
     
-    tpc.proxy().createTable(userpass, testTable, true, TimeType.MILLIS);
+    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
     
-    System.out.println("Listing: " + tpc.proxy().listTables(userpass));
+    System.out.println("Listing: " + tpc.proxy().listTables(login));
     
     System.out.println("Writing: ");
     Date start = new Date();
@@ -97,16 +97,16 @@ public class TestProxyClient {
       mutations.put(ByteBuffer.wrap(result.getBytes()), Collections.singletonList(update));
       
       if (i % 1000 == 0) {
-        tpc.proxy().updateAndFlush(userpass, testTable, mutations);
+        tpc.proxy().updateAndFlush(login, testTable, mutations);
         mutations.clear();
       }
     }
-    tpc.proxy().updateAndFlush(userpass, testTable, mutations);
+    tpc.proxy().updateAndFlush(login, testTable, mutations);
     Date end = new Date();
     System.out.println(" End of writing: " + (end.getTime() - start.getTime()));
     
-    tpc.proxy().deleteTable(userpass, testTable);
-    tpc.proxy().createTable(userpass, testTable, true, TimeType.MILLIS);
+    tpc.proxy().deleteTable(login, testTable);
+    tpc.proxy().createTable(login, testTable, true, TimeType.MILLIS);
     
     // Thread.sleep(1000);
     
@@ -114,7 +114,7 @@ public class TestProxyClient {
     start = new Date();
     then = new Date();
     mutations.clear();
-    String writer = tpc.proxy().createWriter(userpass, testTable, null);
+    String writer = tpc.proxy().createWriter(login, testTable, null);
     for (int i = 0; i < maxInserts; i++) {
       String result = String.format(format, i);
       Key pkey = new Key();
@@ -141,7 +141,7 @@ public class TestProxyClient {
     IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class);
     RegExFilter.setRegexs(is, null, regex, null, null, false);
     
-    String cookie = tpc.proxy().createScanner(userpass, testTable, null);
+    String cookie = tpc.proxy().createScanner(login, testTable, null);
     
     int i = 0;
     start = new Date();



Mime
View raw message