Search in sources :

Example 6 with NamespacePermission

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);
}
Also used : AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) NamespacePermission(org.apache.accumulo.core.security.NamespacePermission)

Example 7 with NamespacePermission

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();
}
Also used : SystemPermission(org.apache.accumulo.core.security.SystemPermission) Authorizations(org.apache.accumulo.core.security.Authorizations) FileWriter(java.io.FileWriter) TablePermission(org.apache.accumulo.core.security.TablePermission) File(java.io.File) NamespacePermission(org.apache.accumulo.core.security.NamespacePermission)

Example 8 with NamespacePermission

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();
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NamespacePermission(org.apache.accumulo.core.security.NamespacePermission)

Aggregations

NamespacePermission (org.apache.accumulo.core.security.NamespacePermission)8 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)5 SystemPermission (org.apache.accumulo.core.security.SystemPermission)2 TablePermission (org.apache.accumulo.core.security.TablePermission)2 KeeperException (org.apache.zookeeper.KeeperException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)1