use of org.apache.accumulo.core.security.NamespacePermission in project accumulo by apache.
the class MockSecurityOperations method hasNamespacePermission.
@Override
public boolean hasNamespacePermission(String principal, String namespace, NamespacePermission permission) throws AccumuloException, AccumuloSecurityException {
MockNamespace mockNamespace = acu.namespaces.get(namespace);
if (mockNamespace == null)
throw new AccumuloSecurityException(namespace, SecurityErrorCode.NAMESPACE_DOESNT_EXIST);
EnumSet<NamespacePermission> perms = mockNamespace.userPermissions.get(principal);
if (perms == null)
return false;
return perms.contains(permission);
}
use of org.apache.accumulo.core.security.NamespacePermission in project accumulo by apache.
the class Admin method printUserConfiguration.
private static void printUserConfiguration(Connector connector, String user, File outputDirectory) throws IOException, AccumuloException, AccumuloSecurityException {
File userScript = new File(outputDirectory, user + USER_FILE_SUFFIX);
FileWriter userWriter = new FileWriter(userScript);
userWriter.write(createUserFormat.format(new String[] { user }));
Authorizations auths = connector.securityOperations().getUserAuthorizations(user);
userWriter.write(userAuthsFormat.format(new String[] { user, auths.toString() }));
for (SystemPermission sp : SystemPermission.values()) {
if (connector.securityOperations().hasSystemPermission(user, sp)) {
userWriter.write(sysPermFormat.format(new String[] { sp.name(), user }));
}
}
for (String namespace : connector.namespaceOperations().list()) {
for (NamespacePermission np : NamespacePermission.values()) {
if (connector.securityOperations().hasNamespacePermission(user, namespace, np)) {
userWriter.write(nsPermFormat.format(new String[] { np.name(), namespace, user }));
}
}
}
for (String tableName : connector.tableOperations().list()) {
for (TablePermission perm : TablePermission.values()) {
if (connector.securityOperations().hasTablePermission(user, tableName, perm)) {
userWriter.write(tablePermFormat.format(new String[] { perm.name(), tableName, user }));
}
}
}
userWriter.close();
}
use of org.apache.accumulo.core.security.NamespacePermission in project accumulo by apache.
the class ZKSecurityTool method convertNamespacePermissions.
public static byte[] convertNamespacePermissions(Set<NamespacePermission> namespacepermissions) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(namespacepermissions.size());
DataOutputStream out = new DataOutputStream(bytes);
try {
for (NamespacePermission tnp : namespacepermissions) out.writeByte(tnp.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