use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class AccumuloAddUserIT method userNotAddedCanNotInsert.
/**
* Ensure a user that has not been added to the Rya instance can not interact with it.
*/
@Test
public void userNotAddedCanNotInsert() throws Exception {
final String user = testInstance.createUniqueUser();
final SecurityOperations secOps = super.getConnector().securityOperations();
final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));
// Install the instance of Rya.
userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
// Create the user that will not be added to the instance of Rya, but will try to scan it.
secOps.createLocalUser(user, new PasswordToken(user));
// Try to add a statement the Rya instance with the unauthorized user. This should fail.
boolean securityExceptionThrown = false;
Sail sail = null;
SailConnection sailConn = null;
try {
final AccumuloRdfConfiguration userCConf = makeRyaConfig(getRyaInstanceName(), user, user, getInstanceName(), getZookeepers());
sail = RyaSailFactory.getInstance(userCConf);
sailConn = sail.getConnection();
final ValueFactory vf = sail.getValueFactory();
sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
} catch (final RuntimeException e) {
final Throwable cause = e.getCause();
if (cause instanceof AccumuloSecurityException) {
securityExceptionThrown = true;
}
} finally {
if (sailConn != null) {
sailConn.close();
}
if (sail != null) {
sail.shutDown();
}
}
assertTrue(securityExceptionThrown);
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class AccumuloAddUserIT method addUserTwice.
/**
* Ensure nothing happens if you try to add a user that is already there.
*/
@Test
public void addUserTwice() throws Exception {
final String user = testInstance.createUniqueUser();
final SecurityOperations secOps = super.getConnector().securityOperations();
final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));
// Create the user that will not be added to the instance of Rya, but will try to scan it.
secOps.createLocalUser(user, new PasswordToken(user));
// Install the instance of Rya.
userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
// Add the user.
userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);
userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);
// Ensure the Rya instance's details only contain the username of the user who installed the instance.
final ImmutableList<String> expectedUsers = ImmutableList.<String>builder().add(ADMIN_USER).add(user).build();
final RyaDetails details = userAClient.getGetInstanceDetails().getDetails(getRyaInstanceName()).get();
assertEquals(expectedUsers, details.getUsers());
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class AccumuloStorageTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
connector = new MockInstance(instance).getConnector(user, new PasswordToken(pwd.getBytes()));
connector.tableOperations().create(table);
SecurityOperations secOps = connector.securityOperations();
secOps.createLocalUser(user, new PasswordToken(pwd.getBytes()));
secOps.grantTablePermission(user, table, TablePermission.READ);
secOps.grantTablePermission(user, table, TablePermission.WRITE);
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class AccumuloStorage method setStoreLocation.
@Override
public void setStoreLocation(final String location, final Job job) throws IOException {
conf = job.getConfiguration();
setLocationFromUri(location, job);
if (!conf.getBoolean(AccumuloOutputFormat.class.getSimpleName() + ".configured", false)) {
try {
AccumuloOutputFormat.setConnectorInfo(job, user, new PasswordToken(userP.getBytes(StandardCharsets.UTF_8)));
} catch (final AccumuloSecurityException e) {
throw new RuntimeException(e);
}
AccumuloOutputFormat.setDefaultTableName(job, table);
AccumuloOutputFormat.setZooKeeperInstance(job, inst, zookeepers);
final BatchWriterConfig config = new BatchWriterConfig();
config.setMaxLatency(10, TimeUnit.SECONDS);
config.setMaxMemory(10 * 1000 * 1000);
config.setMaxWriteThreads(10);
AccumuloOutputFormat.setBatchWriterOptions(job, config);
}
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project incubator-rya by apache.
the class AccumuloStorage method setLocation.
@Override
public void setLocation(final String location, final Job job) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Set Location[" + location + "] for job[" + job.getJobName() + "]");
}
conf = job.getConfiguration();
setLocationFromUri(location, job);
if (!ConfiguratorBase.isConnectorInfoSet(AccumuloInputFormat.class, conf)) {
try {
AccumuloInputFormat.setConnectorInfo(job, user, new PasswordToken(userP.getBytes(StandardCharsets.UTF_8)));
} catch (final AccumuloSecurityException e) {
throw new RuntimeException(e);
}
AccumuloInputFormat.setInputTableName(job, table);
AccumuloInputFormat.setScanAuthorizations(job, authorizations);
if (!mock) {
AccumuloInputFormat.setZooKeeperInstance(job, inst, zookeepers);
} else {
AccumuloInputFormat.setMockInstance(job, inst);
}
}
if (columnFamilyColumnQualifierPairs.size() > 0) {
AccumuloInputFormat.fetchColumns(job, columnFamilyColumnQualifierPairs);
}
logger.info("Set ranges[" + ranges + "] for job[" + job.getJobName() + "] on table[" + table + "] " + "for columns[" + columnFamilyColumnQualifierPairs + "] with authorizations[" + authorizations + "]");
if (ranges.size() == 0) {
throw new IOException("Accumulo Range must be specified");
}
AccumuloInputFormat.setRanges(job, ranges);
}
Aggregations