use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class DDLTask method descDatabase.
private int descDatabase(Hive db, DescDatabaseDesc descDatabase) throws HiveException {
DataOutputStream outStream = getOutputStream(descDatabase.getResFile());
try {
Database database = db.getDatabase(descDatabase.getDatabaseName());
if (database == null) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, descDatabase.getDatabaseName());
}
Map<String, String> params = null;
if (descDatabase.isExt()) {
params = database.getParameters();
}
// key. This is to get consistent param ordering between Java7 and Java8.
if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST) && params != null) {
params = new TreeMap<String, String>(params);
}
String location = database.getLocationUri();
if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST)) {
location = "location/in/test";
}
PrincipalType ownerType = database.getOwnerType();
formatter.showDatabaseDescription(outStream, database.getName(), database.getDescription(), location, database.getOwnerName(), (null == ownerType) ? null : ownerType.name(), params);
} catch (Exception e) {
throw new HiveException(e, ErrorMsg.GENERIC_ERROR);
} finally {
IOUtils.closeStream(outStream);
}
return 0;
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class HiveAuthorizationTaskFactoryImpl method createShowRoleGrantTask.
@Override
public Task<? extends Serializable> createShowRoleGrantTask(ASTNode ast, Path resultFile, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) {
ASTNode child = (ASTNode) ast.getChild(0);
PrincipalType principalType = PrincipalType.USER;
switch(child.getType()) {
case HiveParser.TOK_USER:
principalType = PrincipalType.USER;
break;
case HiveParser.TOK_GROUP:
principalType = PrincipalType.GROUP;
break;
case HiveParser.TOK_ROLE:
principalType = PrincipalType.ROLE;
break;
}
String principalName = BaseSemanticAnalyzer.unescapeIdentifier(child.getChild(0).getText());
RoleDDLDesc roleDesc = new RoleDDLDesc(principalName, principalType, RoleDDLDesc.RoleOperation.SHOW_ROLE_GRANT, null);
roleDesc.setResFile(resultFile.toString());
return TaskFactory.get(new DDLWork(inputs, outputs, roleDesc));
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class HiveV1Authorizer method getRoleGrantInfoForPrincipal.
@Override
public List<HiveRoleGrant> getRoleGrantInfoForPrincipal(HivePrincipal principal) throws HiveAuthzPluginException, HiveAccessControlException {
PrincipalType type = AuthorizationUtils.getThriftPrincipalType(principal.getType());
try {
List<HiveRoleGrant> grants = new ArrayList<HiveRoleGrant>();
Hive hive = Hive.getWithFastCheck(this.conf);
for (RolePrincipalGrant grant : hive.getRoleGrantInfoForPrincipal(principal.getName(), type)) {
grants.add(new HiveRoleGrant(grant));
}
return grants;
} catch (HiveException e) {
throw new HiveAuthzPluginException(e);
}
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class HiveV1Authorizer method showPrivileges.
@Override
public List<HivePrivilegeInfo> showPrivileges(HivePrincipal principal, HivePrivilegeObject privObj) throws HiveAuthzPluginException, HiveAccessControlException {
String name = principal == null ? null : principal.getName();
PrincipalType type = AuthorizationUtils.getThriftPrincipalType(principal == null ? null : principal.getType());
List<HiveObjectPrivilege> privs = new ArrayList<HiveObjectPrivilege>();
try {
Hive hive = Hive.getWithFastCheck(this.conf);
if (privObj == null) {
// show user level privileges
privs.addAll(hive.showPrivilegeGrant(HiveObjectType.GLOBAL, name, type, null, null, null, null));
} else if (privObj.getDbname() == null) {
// show all privileges
privs.addAll(hive.showPrivilegeGrant(null, name, type, null, null, null, null));
} else {
Database dbObj = hive.getDatabase(privObj.getDbname());
;
if (dbObj == null) {
throw new HiveException("Database " + privObj.getDbname() + " does not exists");
}
Table tableObj = null;
if (privObj.getObjectName() != null) {
tableObj = hive.getTable(dbObj.getName(), privObj.getObjectName());
}
List<String> partValues = privObj.getPartKeys();
if (tableObj == null) {
// show database level privileges
privs.addAll(hive.showPrivilegeGrant(HiveObjectType.DATABASE, name, type, dbObj.getName(), null, null, null));
} else {
List<String> columns = privObj.getColumns();
if (columns != null && !columns.isEmpty()) {
// show column level privileges
for (String columnName : columns) {
privs.addAll(hive.showPrivilegeGrant(HiveObjectType.COLUMN, name, type, dbObj.getName(), tableObj.getTableName(), partValues, columnName));
}
} else if (partValues == null) {
// show table level privileges
privs.addAll(hive.showPrivilegeGrant(HiveObjectType.TABLE, name, type, dbObj.getName(), tableObj.getTableName(), null, null));
} else {
// show partition level privileges
privs.addAll(hive.showPrivilegeGrant(HiveObjectType.PARTITION, name, type, dbObj.getName(), tableObj.getTableName(), partValues, null));
}
}
}
return AuthorizationUtils.getPrivilegeInfos(privs);
} catch (Exception ex) {
throw new HiveAuthzPluginException(ex);
}
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class HiveV1Authorizer method grantOrRevokeRole.
private void grantOrRevokeRole(List<HivePrincipal> principals, List<String> roles, boolean grantOption, HivePrincipal grantor, boolean isGrant) throws HiveException {
PrincipalType grantorType = AuthorizationUtils.getThriftPrincipalType(grantor.getType());
Hive hive = Hive.getWithFastCheck(this.conf);
for (HivePrincipal principal : principals) {
PrincipalType principalType = AuthorizationUtils.getThriftPrincipalType(principal.getType());
String userName = principal.getName();
for (String roleName : roles) {
if (isGrant) {
hive.grantRole(roleName, userName, principalType, grantor.getName(), grantorType, grantOption);
} else {
hive.revokeRole(roleName, userName, principalType, grantOption);
}
}
}
}
Aggregations