use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class DemoDriver method startMiniAccumulo.
/**
* Setup a Mini Accumulo cluster that uses a temporary directory to store its data.
*
* @return A Mini Accumulo cluster.
*/
private static MiniAccumuloCluster startMiniAccumulo() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException {
final File miniDataDir = Files.createTempDir();
// Setup and start the Mini Accumulo.
final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(miniDataDir, "password");
accumulo.start();
// Store a connector to the Mini Accumulo.
final Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
accumuloConn = instance.getConnector("root", new PasswordToken("password"));
return accumulo;
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class AccumuloInstanceDriver method setUpTables.
/**
* Sets up all the tables and indices.
* @throws Exception
*/
public void setUpTables() throws Exception {
// Setup tables and permissions
log.info("Setting up " + driverName + " tables and permissions");
for (final String tableSuffix : TABLE_NAME_SUFFIXES) {
final String tableName = tablePrefix + tableSuffix;
tableList.add(tableName);
if (!connector.tableOperations().exists(tableName)) {
connector.tableOperations().create(tableName);
}
}
if (shouldCreateIndices) {
indices = Arrays.asList();
tableList.addAll(indices);
log.info("Setting up " + driverName + " indices");
for (final String index : indices) {
if (!connector.tableOperations().exists(index)) {
connector.tableOperations().create(index);
}
}
}
// Setup user with authorizations
log.info("Creating " + driverName + " user and authorizations");
secOps = connector.securityOperations();
if (!user.equals(ROOT_USER_NAME)) {
secOps.createLocalUser(user, new PasswordToken(userpwd));
}
addAuths(auth);
final TablePermission tablePermission = isReadOnly ? TablePermission.READ : TablePermission.WRITE;
for (final String tableSuffix : TABLE_NAME_SUFFIXES) {
log.info("Giving user: " + user + " " + tablePermission.toString() + " permissions on table " + tablePrefix + tableSuffix);
secOps.grantTablePermission(user, tablePrefix + tableSuffix, tablePermission);
}
if (shouldCreateIndices) {
for (final String index : indices) {
log.info("Giving user: " + user + " " + tablePermission.toString() + " permissions on table " + index);
secOps.grantTablePermission(user, index, tablePermission);
}
}
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class AccumuloInstanceDriver method setUpInstance.
/**
* Sets up the {@link MiniAccumuloCluster} or the {@link MockInstance} or
* distribution instance
* @throws Exception
*/
public void setUpInstance() throws Exception {
switch(instanceType) {
case DISTRIBUTION:
log.info("Setting up " + driverName + " distribution instance...");
if (instanceName == null) {
throw new IllegalArgumentException("Must specify instance name for distributed mode");
} else if (zooKeepers == null) {
throw new IllegalArgumentException("Must specify ZooKeeper hosts for distributed mode");
}
instance = new ZooKeeperInstance(instanceName, zooKeepers);
connector = instance.getConnector(user, new PasswordToken(userpwd));
log.info("Created connector to " + driverName + " distribution instance");
break;
case MINI:
log.info("Setting up " + driverName + " MiniAccumulo cluster...");
// Create and Run MiniAccumulo Cluster
tempDir = Files.createTempDir();
tempDir.deleteOnExit();
miniAccumuloCluster = new MiniAccumuloCluster(tempDir, userpwd);
copyHadoopHomeToTemp();
miniAccumuloCluster.getConfig().setInstanceName(instanceName);
log.info(driverName + " MiniAccumulo instance starting up...");
miniAccumuloCluster.start();
Thread.sleep(1000);
log.info(driverName + " MiniAccumulo instance started");
log.info("Creating connector to " + driverName + " MiniAccumulo instance...");
zooKeeperInstance = new ZooKeeperInstance(miniAccumuloCluster.getClientConfig());
instance = zooKeeperInstance;
connector = zooKeeperInstance.getConnector(user, new PasswordToken(userpwd));
log.info("Created connector to " + driverName + " MiniAccumulo instance");
break;
case MOCK:
log.info("Setting up " + driverName + " mock instance...");
mockInstance = new MockInstance(instanceName);
instance = mockInstance;
connector = mockInstance.getConnector(user, new PasswordToken(userpwd));
log.info("Created connector to " + driverName + " mock instance");
break;
default:
throw new AccumuloException("Unexpected instance type: " + instanceType);
}
zooKeepers = instance.getZooKeepers();
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project teiid by teiid.
the class AccumuloConnectionImpl method checkTabletServerExists.
private void checkTabletServerExists(ZooKeeperInstance inst, String userName, String password) throws ResourceException {
ClientService.Client client = null;
try {
Pair<String, Client> pair = ServerClient.getConnection(new ClientContext(inst, new Credentials(userName, new PasswordToken(password)), inst.getConfiguration()), true, 10);
client = pair.getSecond();
} catch (TTransportException e) {
throw new ResourceException(AccumuloManagedConnectionFactory.UTIL.getString("no_tserver"), e);
} finally {
if (client != null) {
ServerClient.close(client);
}
}
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.
the class CredentialsTest method testToString.
@Test
public void testToString() {
Credentials creds = new Credentials(null, null);
assertEquals(Credentials.class.getName() + ":null:null:<hidden>", creds.toString());
creds = new Credentials("", new NullToken());
assertEquals(Credentials.class.getName() + "::" + NullToken.class.getName() + ":<hidden>", creds.toString());
creds = new Credentials("abc", null);
assertEquals(Credentials.class.getName() + ":abc:null:<hidden>", creds.toString());
creds = new Credentials("abc", new PasswordToken(""));
assertEquals(Credentials.class.getName() + ":abc:" + PasswordToken.class.getName() + ":<hidden>", creds.toString());
}
Aggregations