use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class MaxOpenIT method run.
@Test
public void run() throws Exception {
final Connector c = getConnector();
final String tableName = getUniqueNames(1)[0];
final ClientConfiguration clientConf = cluster.getClientConfig();
c.tableOperations().create(tableName);
c.tableOperations().setProperty(tableName, Property.TABLE_MAJC_RATIO.getKey(), "10");
c.tableOperations().addSplits(tableName, TestIngest.getSplitPoints(0, NUM_TO_INGEST, NUM_TABLETS));
// the following loop should create three tablets in each map file
for (int i = 0; i < 3; i++) {
TestIngest.Opts opts = new TestIngest.Opts();
opts.timestamp = i;
opts.dataSize = 50;
opts.rows = NUM_TO_INGEST;
opts.cols = 1;
opts.random = i;
opts.setTableName(tableName);
if (clientConf.hasSasl()) {
opts.updateKerberosCredentials(clientConf);
} else {
opts.setPrincipal(getAdminPrincipal());
}
TestIngest.ingest(c, opts, new BatchWriterOpts());
c.tableOperations().flush(tableName, null, null, true);
FunctionalTestUtils.checkRFiles(c, tableName, NUM_TABLETS, NUM_TABLETS, i + 1, i + 1);
}
List<Range> ranges = new ArrayList<>(NUM_TO_INGEST);
for (int i = 0; i < NUM_TO_INGEST; i++) {
ranges.add(new Range(TestIngest.generateRow(i, 0)));
}
long time1 = batchScan(c, tableName, ranges, 1);
// run it again, now that stuff is cached on the client and sever
time1 = batchScan(c, tableName, ranges, 1);
long time2 = batchScan(c, tableName, ranges, NUM_TABLETS);
System.out.printf("Single thread scan time %6.2f %n", time1 / 1000.0);
System.out.printf("Multiple thread scan time %6.2f %n", time2 / 1000.0);
}
use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class PermissionsIT method testGrantedSystemPermission.
private void testGrantedSystemPermission(String tableNamePrefix, Connector root_conn, ClusterUser rootUser, Connector test_user_conn, ClusterUser testUser, SystemPermission perm) throws Exception {
String tableName, user, password = "password", namespace;
boolean passwordBased = testUser.getPassword() != null;
log.debug("Confirming that the presence of the {} permission properly permits the user", perm);
// test permission after granting it
switch(perm) {
case CREATE_TABLE:
tableName = tableNamePrefix + "__CREATE_TABLE_WITH_PERM_TEST__";
loginAs(testUser);
test_user_conn.tableOperations().create(tableName);
loginAs(rootUser);
if (!root_conn.tableOperations().list().contains(tableName))
throw new IllegalStateException("Should be able to create a table");
break;
case DROP_TABLE:
tableName = tableNamePrefix + "__DROP_TABLE_WITH_PERM_TEST__";
loginAs(rootUser);
root_conn.tableOperations().create(tableName);
loginAs(testUser);
test_user_conn.tableOperations().delete(tableName);
loginAs(rootUser);
if (root_conn.tableOperations().list().contains(tableName))
throw new IllegalStateException("Should be able to delete a table");
break;
case ALTER_TABLE:
tableName = tableNamePrefix + "__ALTER_TABLE_WITH_PERM_TEST__";
String table2 = tableName + "2";
loginAs(rootUser);
root_conn.tableOperations().create(tableName);
loginAs(testUser);
test_user_conn.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
loginAs(rootUser);
Map<String, String> properties = map(root_conn.tableOperations().getProperties(tableName));
if (!properties.get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw new IllegalStateException("Should be able to set a table property");
loginAs(testUser);
test_user_conn.tableOperations().removeProperty(tableName, Property.TABLE_BLOOM_ERRORRATE.getKey());
loginAs(rootUser);
properties = map(root_conn.tableOperations().getProperties(tableName));
if (properties.get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw new IllegalStateException("Should be able to remove a table property");
loginAs(testUser);
test_user_conn.tableOperations().rename(tableName, table2);
loginAs(rootUser);
if (root_conn.tableOperations().list().contains(tableName) || !root_conn.tableOperations().list().contains(table2))
throw new IllegalStateException("Should be able to rename a table");
break;
case CREATE_USER:
user = "__CREATE_USER_WITH_PERM_TEST__";
loginAs(testUser);
test_user_conn.securityOperations().createLocalUser(user, (passwordBased ? new PasswordToken(password) : null));
loginAs(rootUser);
if (passwordBased && !root_conn.securityOperations().authenticateUser(user, new PasswordToken(password)))
throw new IllegalStateException("Should be able to create a user");
break;
case DROP_USER:
user = "__DROP_USER_WITH_PERM_TEST__";
loginAs(rootUser);
root_conn.securityOperations().createLocalUser(user, (passwordBased ? new PasswordToken(password) : null));
loginAs(testUser);
test_user_conn.securityOperations().dropLocalUser(user);
loginAs(rootUser);
if (passwordBased && root_conn.securityOperations().authenticateUser(user, new PasswordToken(password)))
throw new IllegalStateException("Should be able to delete a user");
break;
case ALTER_USER:
user = "__ALTER_USER_WITH_PERM_TEST__";
loginAs(rootUser);
root_conn.securityOperations().createLocalUser(user, (passwordBased ? new PasswordToken(password) : null));
loginAs(testUser);
test_user_conn.securityOperations().changeUserAuthorizations(user, new Authorizations("A", "B"));
loginAs(rootUser);
if (root_conn.securityOperations().getUserAuthorizations(user).isEmpty())
throw new IllegalStateException("Should be able to alter a user");
break;
case SYSTEM:
// test for system permission would go here
break;
case CREATE_NAMESPACE:
namespace = "__CREATE_NAMESPACE_WITH_PERM_TEST__";
loginAs(testUser);
test_user_conn.namespaceOperations().create(namespace);
loginAs(rootUser);
if (!root_conn.namespaceOperations().list().contains(namespace))
throw new IllegalStateException("Should be able to create a namespace");
break;
case DROP_NAMESPACE:
namespace = "__DROP_NAMESPACE_WITH_PERM_TEST__";
loginAs(rootUser);
root_conn.namespaceOperations().create(namespace);
loginAs(testUser);
test_user_conn.namespaceOperations().delete(namespace);
loginAs(rootUser);
if (root_conn.namespaceOperations().list().contains(namespace))
throw new IllegalStateException("Should be able to delete a namespace");
break;
case ALTER_NAMESPACE:
namespace = "__ALTER_NAMESPACE_WITH_PERM_TEST__";
String namespace2 = namespace + "2";
loginAs(rootUser);
root_conn.namespaceOperations().create(namespace);
loginAs(testUser);
test_user_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
loginAs(rootUser);
Map<String, String> propies = map(root_conn.namespaceOperations().getProperties(namespace));
if (!propies.get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw new IllegalStateException("Should be able to set a table property");
loginAs(testUser);
test_user_conn.namespaceOperations().removeProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey());
loginAs(rootUser);
propies = map(root_conn.namespaceOperations().getProperties(namespace));
if (propies.get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw new IllegalStateException("Should be able to remove a table property");
loginAs(testUser);
test_user_conn.namespaceOperations().rename(namespace, namespace2);
loginAs(rootUser);
if (root_conn.namespaceOperations().list().contains(namespace) || !root_conn.namespaceOperations().list().contains(namespace2))
throw new IllegalStateException("Should be able to rename a table");
break;
case OBTAIN_DELEGATION_TOKEN:
ClientConfiguration clientConf = cluster.getClientConfig();
if (clientConf.hasSasl()) {
// TODO Try to obtain a delegation token with the permission
}
break;
case GRANT:
loginAs(rootUser);
root_conn.securityOperations().grantSystemPermission(testUser.getPrincipal(), SystemPermission.GRANT);
loginAs(testUser);
test_user_conn.securityOperations().grantSystemPermission(testUser.getPrincipal(), SystemPermission.CREATE_TABLE);
loginAs(rootUser);
assertTrue("Test user should have CREATE_TABLE", root_conn.securityOperations().hasSystemPermission(testUser.getPrincipal(), SystemPermission.CREATE_TABLE));
assertTrue("Test user should have GRANT", root_conn.securityOperations().hasSystemPermission(testUser.getPrincipal(), SystemPermission.GRANT));
root_conn.securityOperations().revokeSystemPermission(testUser.getPrincipal(), SystemPermission.CREATE_TABLE);
break;
default:
throw new IllegalArgumentException("Unrecognized System Permission: " + perm);
}
}
use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class PermissionsIT method testMissingSystemPermission.
private void testMissingSystemPermission(String tableNamePrefix, Connector root_conn, ClusterUser rootUser, Connector test_user_conn, ClusterUser testUser, SystemPermission perm) throws Exception {
String tableName, user, password = "password", namespace;
boolean passwordBased = testUser.getPassword() != null;
log.debug("Confirming that the lack of the {} permission properly restricts the user", perm);
// test permission prior to granting it
switch(perm) {
case CREATE_TABLE:
tableName = tableNamePrefix + "__CREATE_TABLE_WITHOUT_PERM_TEST__";
try {
loginAs(testUser);
test_user_conn.tableOperations().create(tableName);
throw new IllegalStateException("Should NOT be able to create a table");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || root_conn.tableOperations().list().contains(tableName))
throw e;
}
break;
case DROP_TABLE:
tableName = tableNamePrefix + "__DROP_TABLE_WITHOUT_PERM_TEST__";
loginAs(rootUser);
root_conn.tableOperations().create(tableName);
try {
loginAs(testUser);
test_user_conn.tableOperations().delete(tableName);
throw new IllegalStateException("Should NOT be able to delete a table");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.tableOperations().list().contains(tableName))
throw e;
}
break;
case ALTER_TABLE:
tableName = tableNamePrefix + "__ALTER_TABLE_WITHOUT_PERM_TEST__";
loginAs(rootUser);
root_conn.tableOperations().create(tableName);
try {
loginAs(testUser);
test_user_conn.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
throw new IllegalStateException("Should NOT be able to set a table property");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || map(root_conn.tableOperations().getProperties(tableName)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw e;
}
loginAs(rootUser);
root_conn.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
try {
loginAs(testUser);
test_user_conn.tableOperations().removeProperty(tableName, Property.TABLE_BLOOM_ERRORRATE.getKey());
throw new IllegalStateException("Should NOT be able to remove a table property");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !map(root_conn.tableOperations().getProperties(tableName)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw e;
}
String table2 = tableName + "2";
try {
loginAs(testUser);
test_user_conn.tableOperations().rename(tableName, table2);
throw new IllegalStateException("Should NOT be able to rename a table");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.tableOperations().list().contains(tableName) || root_conn.tableOperations().list().contains(table2))
throw e;
}
break;
case CREATE_USER:
user = "__CREATE_USER_WITHOUT_PERM_TEST__";
try {
loginAs(testUser);
test_user_conn.securityOperations().createLocalUser(user, (passwordBased ? new PasswordToken(password) : null));
throw new IllegalStateException("Should NOT be able to create a user");
} catch (AccumuloSecurityException e) {
AuthenticationToken userToken = testUser.getToken();
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || (userToken instanceof PasswordToken && root_conn.securityOperations().authenticateUser(user, userToken)))
throw e;
}
break;
case DROP_USER:
user = "__DROP_USER_WITHOUT_PERM_TEST__";
loginAs(rootUser);
root_conn.securityOperations().createLocalUser(user, (passwordBased ? new PasswordToken(password) : null));
try {
loginAs(testUser);
test_user_conn.securityOperations().dropLocalUser(user);
throw new IllegalStateException("Should NOT be able to delete a user");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.securityOperations().listLocalUsers().contains(user)) {
log.info("Failed to authenticate as {}", user);
throw e;
}
}
break;
case ALTER_USER:
user = "__ALTER_USER_WITHOUT_PERM_TEST__";
loginAs(rootUser);
root_conn.securityOperations().createLocalUser(user, (passwordBased ? new PasswordToken(password) : null));
try {
loginAs(testUser);
test_user_conn.securityOperations().changeUserAuthorizations(user, new Authorizations("A", "B"));
throw new IllegalStateException("Should NOT be able to alter a user");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.securityOperations().getUserAuthorizations(user).isEmpty())
throw e;
}
break;
case SYSTEM:
// test for system permission would go here
break;
case CREATE_NAMESPACE:
namespace = "__CREATE_NAMESPACE_WITHOUT_PERM_TEST__";
try {
loginAs(testUser);
test_user_conn.namespaceOperations().create(namespace);
throw new IllegalStateException("Should NOT be able to create a namespace");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || root_conn.namespaceOperations().list().contains(namespace))
throw e;
}
break;
case DROP_NAMESPACE:
namespace = "__DROP_NAMESPACE_WITHOUT_PERM_TEST__";
loginAs(rootUser);
root_conn.namespaceOperations().create(namespace);
try {
loginAs(testUser);
test_user_conn.namespaceOperations().delete(namespace);
throw new IllegalStateException("Should NOT be able to delete a namespace");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.namespaceOperations().list().contains(namespace))
throw e;
}
break;
case ALTER_NAMESPACE:
namespace = "__ALTER_NAMESPACE_WITHOUT_PERM_TEST__";
loginAs(rootUser);
root_conn.namespaceOperations().create(namespace);
try {
loginAs(testUser);
test_user_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
throw new IllegalStateException("Should NOT be able to set a namespace property");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || map(root_conn.namespaceOperations().getProperties(namespace)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw e;
}
loginAs(rootUser);
root_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
try {
loginAs(testUser);
test_user_conn.namespaceOperations().removeProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey());
throw new IllegalStateException("Should NOT be able to remove a namespace property");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !map(root_conn.namespaceOperations().getProperties(namespace)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw e;
}
String namespace2 = namespace + "2";
try {
loginAs(testUser);
test_user_conn.namespaceOperations().rename(namespace, namespace2);
throw new IllegalStateException("Should NOT be able to rename a namespace");
} catch (AccumuloSecurityException e) {
loginAs(rootUser);
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.namespaceOperations().list().contains(namespace) || root_conn.namespaceOperations().list().contains(namespace2))
throw e;
}
break;
case OBTAIN_DELEGATION_TOKEN:
ClientConfiguration clientConf = cluster.getClientConfig();
if (clientConf.hasSasl()) {
// TODO Try to obtain a delegation token without the permission
}
break;
case GRANT:
loginAs(testUser);
try {
test_user_conn.securityOperations().grantSystemPermission(testUser.getPrincipal(), SystemPermission.GRANT);
throw new IllegalStateException("Should NOT be able to grant System.GRANT to yourself");
} catch (AccumuloSecurityException e) {
// Expected
loginAs(rootUser);
assertFalse(root_conn.securityOperations().hasSystemPermission(testUser.getPrincipal(), SystemPermission.GRANT));
}
break;
default:
throw new IllegalArgumentException("Unrecognized System Permission: " + perm);
}
}
use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class TableIT method test.
@Test
public void test() throws Exception {
Assume.assumeThat(getClusterType(), CoreMatchers.is(ClusterType.MINI));
AccumuloCluster cluster = getCluster();
MiniAccumuloClusterImpl mac = (MiniAccumuloClusterImpl) cluster;
String rootPath = mac.getConfig().getDir().getAbsolutePath();
Connector c = getConnector();
TableOperations to = c.tableOperations();
String tableName = getUniqueNames(1)[0];
to.create(tableName);
TestIngest.Opts opts = new TestIngest.Opts();
VerifyIngest.Opts vopts = new VerifyIngest.Opts();
ClientConfiguration clientConfig = getCluster().getClientConfig();
if (clientConfig.hasSasl()) {
opts.updateKerberosCredentials(clientConfig);
vopts.updateKerberosCredentials(clientConfig);
} else {
opts.setPrincipal(getAdminPrincipal());
vopts.setPrincipal(getAdminPrincipal());
}
opts.setTableName(tableName);
TestIngest.ingest(c, opts, new BatchWriterOpts());
to.flush(tableName, null, null, true);
vopts.setTableName(tableName);
VerifyIngest.verifyIngest(c, vopts, new ScannerOpts());
Table.ID id = Table.ID.of(to.tableIdMap().get(tableName));
try (Scanner s = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
s.setRange(new KeyExtent(id, null, null).toMetadataRange());
s.fetchColumnFamily(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME);
assertTrue(Iterators.size(s.iterator()) > 0);
FileSystem fs = getCluster().getFileSystem();
assertTrue(fs.listStatus(new Path(rootPath + "/accumulo/tables/" + id)).length > 0);
to.delete(tableName);
assertEquals(0, Iterators.size(s.iterator()));
try {
assertEquals(0, fs.listStatus(new Path(rootPath + "/accumulo/tables/" + id)).length);
} catch (FileNotFoundException ex) {
// that's fine, too
}
assertNull(to.tableIdMap().get(tableName));
to.create(tableName);
TestIngest.ingest(c, opts, new BatchWriterOpts());
VerifyIngest.verifyIngest(c, vopts, new ScannerOpts());
to.delete(tableName);
}
}
use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class WriteAheadLogIT method test.
@Test
public void test() throws Exception {
Connector c = getConnector();
String tableName = getUniqueNames(1)[0];
c.tableOperations().create(tableName);
c.tableOperations().setProperty(tableName, Property.TABLE_SPLIT_THRESHOLD.getKey(), "750K");
TestIngest.Opts opts = new TestIngest.Opts();
VerifyIngest.Opts vopts = new VerifyIngest.Opts();
opts.setTableName(tableName);
ClientConfiguration clientConfig = cluster.getClientConfig();
if (clientConfig.hasSasl()) {
opts.updateKerberosCredentials(clientConfig);
vopts.updateKerberosCredentials(clientConfig);
} else {
opts.setPrincipal(getAdminPrincipal());
vopts.setPrincipal(getAdminPrincipal());
}
TestIngest.ingest(c, opts, new BatchWriterOpts());
vopts.setTableName(tableName);
VerifyIngest.verifyIngest(c, vopts, new ScannerOpts());
getCluster().getClusterControl().stopAllServers(ServerType.TABLET_SERVER);
getCluster().getClusterControl().startAllServers(ServerType.TABLET_SERVER);
VerifyIngest.verifyIngest(c, vopts, new ScannerOpts());
}
Aggregations