use of org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo in project hive by apache.
the class HBaseUtils method convertPrivilegeGrantInfos.
private static List<PrivilegeGrantInfo> convertPrivilegeGrantInfos(List<HbaseMetastoreProto.PrivilegeGrantInfo> privileges) {
List<PrivilegeGrantInfo> results = new ArrayList<>();
for (HbaseMetastoreProto.PrivilegeGrantInfo proto : privileges) {
PrivilegeGrantInfo pgi = new PrivilegeGrantInfo();
if (proto.hasPrivilege())
pgi.setPrivilege(proto.getPrivilege());
pgi.setCreateTime((int) proto.getCreateTime());
if (proto.hasGrantor())
pgi.setGrantor(proto.getGrantor());
if (proto.hasGrantorType()) {
pgi.setGrantorType(convertPrincipalTypes(proto.getGrantorType()));
}
if (proto.hasGrantOption())
pgi.setGrantOption(proto.getGrantOption());
results.add(pgi);
}
return results;
}
use of org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo in project hive by apache.
the class HBaseStore method listPrincipalTableGrantsAll.
@Override
public List<HiveObjectPrivilege> listPrincipalTableGrantsAll(String principalName, PrincipalType principalType) {
List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
boolean commit = false;
openTransaction();
try {
List<Table> tables = getHBase().scanTables(null, null);
for (Table table : tables) {
List<PrivilegeGrantInfo> grants;
PrincipalPrivilegeSet pps = table.getPrivileges();
if (pps == null)
continue;
Map<String, List<PrivilegeGrantInfo>> map;
switch(principalType) {
case USER:
map = pps.getUserPrivileges();
break;
case ROLE:
map = pps.getRolePrivileges();
break;
default:
throw new RuntimeException("Unknown or unsupported principal type " + principalType.toString());
}
if (map == null)
continue;
grants = map.get(principalName);
if (grants == null || grants.size() == 0)
continue;
for (PrivilegeGrantInfo pgi : grants) {
privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.TABLE, table.getDbName(), table.getTableName(), null, null), principalName, principalType, pgi));
}
}
commit = true;
return privileges;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
commitOrRoleBack(commit);
}
}
use of org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo in project hive by apache.
the class HBaseStore method getDBPrivilegeSet.
@Override
public PrincipalPrivilegeSet getDBPrivilegeSet(String dbName, String userName, List<String> groupNames) throws InvalidObjectException, MetaException {
boolean commit = false;
openTransaction();
try {
PrincipalPrivilegeSet pps = new PrincipalPrivilegeSet();
Database db = getHBase().getDb(dbName);
if (db.getPrivileges() != null) {
List<PrivilegeGrantInfo> pgi;
// Find the user privileges for this db
if (db.getPrivileges().getUserPrivileges() != null) {
pgi = db.getPrivileges().getUserPrivileges().get(userName);
if (pgi != null) {
pps.putToUserPrivileges(userName, pgi);
}
}
if (db.getPrivileges().getRolePrivileges() != null) {
List<String> roles = getHBase().getUserRoles(userName);
if (roles != null) {
for (String role : roles) {
pgi = db.getPrivileges().getRolePrivileges().get(role);
if (pgi != null) {
pps.putToRolePrivileges(role, pgi);
}
}
}
}
}
commit = true;
return pps;
} catch (IOException e) {
LOG.error("Unable to get db privileges for user", e);
throw new MetaException("Unable to get db privileges for user, " + e.getMessage());
} finally {
commitOrRoleBack(commit);
}
}
use of org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo in project hive by apache.
the class HBaseStore method listAllTableGrants.
@Override
public List<HiveObjectPrivilege> listAllTableGrants(String principalName, PrincipalType principalType, String dbName, String tableName) {
List<PrivilegeGrantInfo> grants;
List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
boolean commit = false;
openTransaction();
try {
Table table = getHBase().getTable(dbName, tableName);
if (table == null)
return privileges;
PrincipalPrivilegeSet pps = table.getPrivileges();
if (pps == null)
return privileges;
Map<String, List<PrivilegeGrantInfo>> map;
switch(principalType) {
case USER:
map = pps.getUserPrivileges();
break;
case ROLE:
map = pps.getRolePrivileges();
break;
default:
throw new RuntimeException("Unknown or unsupported principal type " + principalType.toString());
}
if (map == null)
return privileges;
grants = map.get(principalName);
if (grants == null || grants.size() == 0)
return privileges;
for (PrivilegeGrantInfo pgi : grants) {
privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.TABLE, dbName, tableName, null, null), principalName, principalType, pgi));
}
commit = true;
return privileges;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
commitOrRoleBack(commit);
}
}
use of org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo in project hive by apache.
the class HBaseStore method listGlobalGrantsAll.
@Override
public List<HiveObjectPrivilege> listGlobalGrantsAll() {
List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
boolean commit = false;
openTransaction();
try {
PrincipalPrivilegeSet pps = getHBase().getGlobalPrivs();
if (pps != null) {
for (Map.Entry<String, List<PrivilegeGrantInfo>> e : pps.getUserPrivileges().entrySet()) {
for (PrivilegeGrantInfo pgi : e.getValue()) {
privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null), e.getKey(), PrincipalType.USER, pgi));
}
}
for (Map.Entry<String, List<PrivilegeGrantInfo>> e : pps.getRolePrivileges().entrySet()) {
for (PrivilegeGrantInfo pgi : e.getValue()) {
privileges.add(new HiveObjectPrivilege(new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null), e.getKey(), PrincipalType.ROLE, pgi));
}
}
}
commit = true;
return privileges;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
commitOrRoleBack(commit);
}
}
Aggregations