String action = props.getProperty("task", "toggle");
String perm = props.getProperty("perm", "random");
String targetUser = WalkingSecurity.get(state).getSysUserName();
SystemPermission sysPerm;
if (perm.equals("random")) {
Random r = new Random();
int i = r.nextInt(SystemPermission.values().length);
sysPerm = SystemPermission.values()[i];
} else
sysPerm = SystemPermission.valueOf(perm);
boolean hasPerm = ws.hasSystemPermission(targetUser, sysPerm);
// toggle
if (!"take".equals(action) && !"give".equals(action)) {
if (hasPerm != conn.securityOperations().hasSystemPermission(targetUser, sysPerm))
throw new AccumuloException("Test framework and accumulo are out of sync!");
if (hasPerm)
action = "take";
else
action = "give";
}
if ("take".equals(action)) {
try {
conn.securityOperations().revokeSystemPermission(targetUser, sysPerm);
} catch (AccumuloSecurityException ae) {
switch (ae.getSecurityErrorCode()) {
case GRANT_INVALID:
if (sysPerm.equals(SystemPermission.GRANT))
return;
throw new AccumuloException("Got GRANT_INVALID when not dealing with GRANT", ae);
case PERMISSION_DENIED:
throw new AccumuloException("Test user doesn't have root", ae);
case USER_DOESNT_EXIST:
throw new AccumuloException("System user doesn't exist and they SHOULD.", ae);
default:
throw new AccumuloException("Got unexpected exception", ae);
}
}
ws.revokeSystemPermission(targetUser, sysPerm);
} else if ("give".equals(action)) {
try {
conn.securityOperations().grantSystemPermission(targetUser, sysPerm);
} catch (AccumuloSecurityException ae) {
switch (ae.getSecurityErrorCode()) {
case GRANT_INVALID:
if (sysPerm.equals(SystemPermission.GRANT))
return;
case PERMISSION_DENIED:
throw new AccumuloException("Test user doesn't have root", ae);
case USER_DOESNT_EXIST:
throw new AccumuloException("System user doesn't exist and they SHOULD.", ae);