Search in sources :

Example 61 with PasswordToken

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;
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) File(java.io.File) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 62 with PasswordToken

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);
        }
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TablePermission(org.apache.accumulo.core.security.TablePermission)

Example 63 with PasswordToken

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();
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 64 with PasswordToken

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);
        }
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ClientService(org.apache.accumulo.core.client.impl.thrift.ClientService) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TTransportException(org.apache.thrift.transport.TTransportException) ResourceException(javax.resource.ResourceException) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) ServerClient(org.apache.accumulo.core.client.impl.ServerClient) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Example 65 with PasswordToken

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());
}
Also used : NullToken(org.apache.accumulo.core.client.security.tokens.NullToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) Credentials(org.apache.accumulo.core.client.impl.Credentials) Test(org.junit.Test)

Aggregations

PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)232 Test (org.junit.Test)104 Connector (org.apache.accumulo.core.client.Connector)96 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)53 Instance (org.apache.accumulo.core.client.Instance)46 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)43 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)40 Authorizations (org.apache.accumulo.core.security.Authorizations)38 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)32 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)30 Value (org.apache.accumulo.core.data.Value)30 Key (org.apache.accumulo.core.data.Key)29 Mutation (org.apache.accumulo.core.data.Mutation)29 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Scanner (org.apache.accumulo.core.client.Scanner)27 Configuration (org.apache.hadoop.conf.Configuration)27 IOException (java.io.IOException)26 BatchWriter (org.apache.accumulo.core.client.BatchWriter)26 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)24