while (iter.hasNext()) {
Entry<Key,Value> entry = iter.next();
Key k = entry.getKey();
seen++;
if (!auths.contains(k.getColumnVisibilityData()) && !ambiguousAuths)
throw new AccumuloException("Got data I should not be capable of seeing: " + k + " table " + tableName);
}
if (!canRead && !ambiguousZone)
throw new AccumuloException("Was able to read when I shouldn't have had the perm with connection user " + conn.whoami() + " table " + tableName);
for (Entry<String,Integer> entry : WalkingSecurity.get(state).getAuthsMap().entrySet()) {
if (auths.contains(entry.getKey().getBytes(Constants.UTF8)))
seen = seen - entry.getValue();
}
if (seen != 0 && !ambiguousAuths)
throw new AccumuloException("Got mismatched amounts of data");
} catch (TableNotFoundException tnfe) {
if (tableExists)
throw new AccumuloException("Accumulo and test suite out of sync: table " + tableName, tnfe);
return;
} catch (AccumuloSecurityException ae) {
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
if (canRead && !ambiguousZone)
throw new AccumuloException("Table read permission out of sync with Accumulo: table " + tableName, ae);
else
return;
}
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.BAD_AUTHORIZATIONS)) {
if (ambiguousAuths)
return;
else
throw new AccumuloException("Mismatched authorizations! ", ae);
}
throw new AccumuloException("Unexpected exception!", ae);
} catch (RuntimeException re) {
if (re.getCause() instanceof AccumuloSecurityException
&& ((AccumuloSecurityException) re.getCause()).getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
if (canRead && !ambiguousZone)
throw new AccumuloException("Table read permission out of sync with Accumulo: table " + tableName, re.getCause());
else
return;
}
if (re.getCause() instanceof AccumuloSecurityException
&& ((AccumuloSecurityException) re.getCause()).getSecurityErrorCode().equals(SecurityErrorCode.BAD_AUTHORIZATIONS)) {
if (ambiguousAuths)
return;
else
throw new AccumuloException("Mismatched authorizations! ", re.getCause());
}
throw new AccumuloException("Unexpected exception!", re);
} finally {
if (scan != null) {
scan.close();
scan = null;
}
}
break;
}
case WRITE:
boolean canWrite = WalkingSecurity.get(state).canWrite(WalkingSecurity.get(state).getTabCredentials(), tableName);
boolean ambiguousZone = WalkingSecurity.get(state).inAmbiguousZone(conn.whoami(), tp);
String key = WalkingSecurity.get(state).getLastKey() + "1";
Mutation m = new Mutation(new Text(key));
for (String s : WalkingSecurity.get(state).getAuthsArray()) {
m.put(new Text(), new Text(), new ColumnVisibility(s), new Value("value".getBytes(Constants.UTF8)));
}
BatchWriter writer = null;
try {
try {
writer = conn.createBatchWriter(tableName, new BatchWriterConfig().setMaxMemory(9000l).setMaxWriteThreads(1));
} catch (TableNotFoundException tnfe) {
if (tableExists)
throw new AccumuloException("Table didn't exist when it should have: " + tableName);
return;
}
boolean works = true;
try {
writer.addMutation(m);
writer.close();
} catch (MutationsRejectedException mre) {
// Currently no method for detecting reason for mre. Waiting on ACCUMULO-670
// For now, just wait a second and go again if they can write!
if (!canWrite)
return;
if (ambiguousZone) {
Thread.sleep(1000);
try {
writer = conn.createBatchWriter(tableName, new BatchWriterConfig().setMaxWriteThreads(1));
writer.addMutation(m);
writer.close();
writer = null;
} catch (MutationsRejectedException mre2) {
throw new AccumuloException("Mutation exception!", mre2);
}
}
}
if (works)
for (String s : WalkingSecurity.get(state).getAuthsArray())
WalkingSecurity.get(state).increaseAuthMap(s, 1);
} finally {
if (writer != null) {
writer.close();
writer = null;
}
}
break;
case BULK_IMPORT:
key = WalkingSecurity.get(state).getLastKey() + "1";
SortedSet<Key> keys = new TreeSet<Key>();
for (String s : WalkingSecurity.get(state).getAuthsArray()) {
Key k = new Key(key, "", "", s);
keys.add(k);
}
Path dir = new Path("/tmp", "bulk_" + UUID.randomUUID().toString());
Path fail = new Path(dir.toString() + "_fail");
FileSystem fs = WalkingSecurity.get(state).getFs();
FileSKVWriter f = FileOperations.getInstance().openWriter(dir + "/securityBulk." + RFile.EXTENSION, fs, fs.getConf(),
AccumuloConfiguration.getDefaultConfiguration());
f.startDefaultLocalityGroup();
fs.mkdirs(fail);
for (Key k : keys)
f.append(k, new Value("Value".getBytes(Constants.UTF8)));
f.close();
try {
conn.tableOperations().importDirectory(tableName, dir.toString(), fail.toString(), true);
} catch (TableNotFoundException tnfe) {
if (tableExists)
throw new AccumuloException("Table didn't exist when it should have: " + tableName);
return;
} catch (AccumuloSecurityException ae) {
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
if (WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
throw new AccumuloException("Bulk Import failed when it should have worked: " + tableName);
return;
} else if (ae.getSecurityErrorCode().equals(SecurityErrorCode.BAD_CREDENTIALS)) {
if (WalkingSecurity.get(state).userPassTransient(conn.whoami()))
return;
}
throw new AccumuloException("Unexpected exception!", ae);
}
for (String s : WalkingSecurity.get(state).getAuthsArray())
WalkingSecurity.get(state).increaseAuthMap(s, 1);
fs.delete(dir, true);
fs.delete(fail, true);
if (!WalkingSecurity.get(state).canBulkImport(WalkingSecurity.get(state).getTabCredentials(), tableName))
throw new AccumuloException("Bulk Import succeeded when it should have failed: " + dir + " table " + tableName);
break;
case ALTER_TABLE:
AlterTable.renameTable(conn, state, tableName, tableName + "plus",
WalkingSecurity.get(state).canAlterTable(WalkingSecurity.get(state).getTabCredentials(), tableName), tableExists);
break;