Search in sources :

Example 1 with TablePermission

use of org.apache.hadoop.hbase.security.access.TablePermission in project hbase by apache.

the class RestoreSnapshotHelper method restoreSnapshotAcl.

public static void restoreSnapshotAcl(SnapshotDescription snapshot, TableName newTableName, Configuration conf) throws IOException {
    if (snapshot.hasUsersAndPermissions() && snapshot.getUsersAndPermissions() != null) {
        LOG.info("Restore snapshot acl to table. snapshot: " + snapshot + ", table: " + newTableName);
        ListMultimap<String, Permission> perms = ShadedAccessControlUtil.toUserTablePermissions(snapshot.getUsersAndPermissions());
        try (Connection conn = ConnectionFactory.createConnection(conf)) {
            for (Entry<String, Permission> e : perms.entries()) {
                String user = e.getKey();
                TablePermission tablePerm = (TablePermission) e.getValue();
                AccessControlClient.grant(conn, newTableName, user, tablePerm.getFamily(), tablePerm.getQualifier(), tablePerm.getActions());
            }
        } catch (Throwable e) {
            throw new IOException("Grant acl into newly creatd table failed. snapshot: " + snapshot + ", table: " + newTableName, e);
        }
    }
}
Also used : TablePermission(org.apache.hadoop.hbase.security.access.TablePermission) Permission(org.apache.hadoop.hbase.security.access.Permission) Connection(org.apache.hadoop.hbase.client.Connection) TablePermission(org.apache.hadoop.hbase.security.access.TablePermission) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Connection (org.apache.hadoop.hbase.client.Connection)1 Permission (org.apache.hadoop.hbase.security.access.Permission)1 TablePermission (org.apache.hadoop.hbase.security.access.TablePermission)1