Search in sources :

Example 1 with TablePermission

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

Example 2 with TablePermission

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

Example 3 with TablePermission

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

Example 4 with TablePermission

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);
    }
}
Also used : TreeSet(java.util.TreeSet) TablePermission(org.apache.accumulo.core.security.TablePermission) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException)

Example 5 with TablePermission

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

Aggregations

TablePermission (org.apache.accumulo.core.security.TablePermission)12 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)5 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)3 TreeSet (java.util.TreeSet)2 NamespacePermission (org.apache.accumulo.core.security.NamespacePermission)2 SystemPermission (org.apache.accumulo.core.security.SystemPermission)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 ClusterUser (org.apache.accumulo.cluster.ClusterUser)1 Connector (org.apache.accumulo.core.client.Connector)1 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)1 Test (org.junit.Test)1