use of org.apache.accumulo.core.security.TablePermission in project accumulo by apache.
the class UserPermissionsCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException {
final String user = cl.getOptionValue(userOpt.getOpt(), shellState.getConnector().whoami());
String delim = "";
shellState.getReader().print("System permissions: ");
for (SystemPermission p : SystemPermission.values()) {
if (p != null && shellState.getConnector().securityOperations().hasSystemPermission(user, p)) {
shellState.getReader().print(delim + "System." + p.name());
delim = ", ";
}
}
shellState.getReader().println();
boolean runOnce = true;
for (String n : shellState.getConnector().namespaceOperations().list()) {
delim = "";
for (NamespacePermission p : NamespacePermission.values()) {
if (p != null && shellState.getConnector().securityOperations().hasNamespacePermission(user, n, p)) {
if (runOnce) {
shellState.getReader().print("\nNamespace permissions (" + n + "): ");
runOnce = false;
}
shellState.getReader().print(delim + "Namespace." + p.name());
delim = ", ";
}
}
runOnce = true;
}
shellState.getReader().println();
runOnce = true;
for (String t : shellState.getConnector().tableOperations().list()) {
delim = "";
for (TablePermission p : TablePermission.values()) {
if (shellState.getConnector().securityOperations().hasTablePermission(user, t, p) && p != null) {
if (runOnce) {
shellState.getReader().print("\nTable permissions (" + t + "): ");
runOnce = false;
}
shellState.getReader().print(delim + "Table." + p.name());
delim = ", ";
}
}
runOnce = true;
}
shellState.getReader().println();
return 0;
}
use of org.apache.accumulo.core.security.TablePermission in project accumulo by apache.
the class MockSecurityOperations method grantTablePermission.
@Override
public void grantTablePermission(String principal, String tableName, TablePermission permission) throws AccumuloException, AccumuloSecurityException {
if (acu.users.get(principal) == null)
throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
MockTable table = acu.tables.get(tableName);
if (table == null)
throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST);
EnumSet<TablePermission> perms = table.userPermissions.get(principal);
if (perms == null)
table.userPermissions.put(principal, EnumSet.of(permission));
else
perms.add(permission);
}
use of org.apache.accumulo.core.security.TablePermission in project accumulo by apache.
the class MockSecurityOperations method hasTablePermission.
@Override
public boolean hasTablePermission(String principal, String tableName, TablePermission perm) throws AccumuloException, AccumuloSecurityException {
MockTable table = acu.tables.get(tableName);
if (table == null)
throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST);
EnumSet<TablePermission> perms = table.userPermissions.get(principal);
if (perms == null)
return false;
return perms.contains(perm);
}
use of org.apache.accumulo.core.security.TablePermission in project accumulo by apache.
the class ZKPermHandler method grantTablePermission.
@Override
public void grantTablePermission(String user, String table, TablePermission permission) throws AccumuloSecurityException {
Set<TablePermission> tablePerms;
byte[] serializedPerms = zooCache.get(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table);
if (serializedPerms != null)
tablePerms = ZKSecurityTool.convertTablePermissions(serializedPerms);
else
tablePerms = new TreeSet<>();
try {
if (tablePerms.add(permission)) {
synchronized (zooCache) {
zooCache.clear(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table);
ZooReaderWriter.getInstance().putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, ZKSecurityTool.convertTablePermissions(tablePerms), NodeExistsPolicy.OVERWRITE);
}
}
} catch (KeeperException e) {
log.error("{}", e.getMessage(), e);
throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e);
} catch (InterruptedException e) {
log.error("{}", e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.accumulo.core.security.TablePermission in project accumulo by apache.
the class ZKSecurityTool method convertTablePermissions.
public static byte[] convertTablePermissions(Set<TablePermission> tablepermissions) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(tablepermissions.size());
DataOutputStream out = new DataOutputStream(bytes);
try {
for (TablePermission tp : tablepermissions) out.writeByte(tp.getId());
} catch (IOException e) {
log.error("{}", e.getMessage(), e);
// this is impossible with ByteArrayOutputStream; crash hard if this happens
throw new RuntimeException(e);
}
return bytes.toByteArray();
}
Aggregations