use of org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet in project hive by apache.
the class Hive method createTable.
/**
* Creates the table with the given objects. It takes additional arguments for
* primary keys and foreign keys associated with the table.
*
* @param tbl
* a table object
* @param ifNotExists
* if true, ignore AlreadyExistsException
* @param primaryKeys
* primary key columns associated with the table
* @param foreignKeys
* foreign key columns associated with the table
* @throws HiveException
*/
public void createTable(Table tbl, boolean ifNotExists, List<SQLPrimaryKey> primaryKeys, List<SQLForeignKey> foreignKeys) throws HiveException {
try {
if (tbl.getDbName() == null || "".equals(tbl.getDbName().trim())) {
tbl.setDbName(SessionState.get().getCurrentDatabase());
}
if (tbl.getCols().size() == 0 || tbl.getSd().getColsSize() == 0) {
tbl.setFields(MetaStoreUtils.getFieldsFromDeserializer(tbl.getTableName(), tbl.getDeserializer()));
}
tbl.checkValidity(conf);
if (tbl.getParameters() != null) {
tbl.getParameters().remove(hive_metastoreConstants.DDL_TIME);
}
org.apache.hadoop.hive.metastore.api.Table tTbl = tbl.getTTable();
PrincipalPrivilegeSet principalPrivs = new PrincipalPrivilegeSet();
SessionState ss = SessionState.get();
if (ss != null) {
CreateTableAutomaticGrant grants = ss.getCreateTableGrants();
if (grants != null) {
principalPrivs.setUserPrivileges(grants.getUserGrants());
principalPrivs.setGroupPrivileges(grants.getGroupGrants());
principalPrivs.setRolePrivileges(grants.getRoleGrants());
tTbl.setPrivileges(principalPrivs);
}
}
if (primaryKeys == null && foreignKeys == null) {
getMSC().createTable(tTbl);
} else {
getMSC().createTableWithConstraints(tTbl, primaryKeys, foreignKeys);
}
} catch (AlreadyExistsException e) {
if (!ifNotExists) {
throw new HiveException(e);
}
} catch (Exception e) {
throw new HiveException(e);
}
}
use of org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet in project hive by apache.
the class BitSetCheckedAuthorizationProvider method authorize.
@Override
public void authorize(Table table, Partition part, List<String> columns, Privilege[] inputRequiredPriv, Privilege[] outputRequiredPriv) throws HiveException {
BitSetChecker checker = BitSetChecker.getBitSetChecker(inputRequiredPriv, outputRequiredPriv);
boolean[] inputCheck = checker.inputCheck;
boolean[] outputCheck = checker.outputCheck;
String partName = null;
List<String> partValues = null;
if (part != null && (table.getParameters().get("PARTITION_LEVEL_PRIVILEGE") != null && ("TRUE".equalsIgnoreCase(table.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))))) {
partName = part.getName();
partValues = part.getValues();
}
if (partValues == null) {
if (authorizeUserDBAndTable(table, inputRequiredPriv, outputRequiredPriv, inputCheck, outputCheck)) {
return;
}
} else {
if (authorizeUserDbAndPartition(part, inputRequiredPriv, outputRequiredPriv, inputCheck, outputCheck)) {
return;
}
}
for (String col : columns) {
BitSetChecker checker2 = BitSetChecker.getBitSetChecker(inputRequiredPriv, outputRequiredPriv);
boolean[] inputCheck2 = checker2.inputCheck;
boolean[] outputCheck2 = checker2.outputCheck;
PrincipalPrivilegeSet partColumnPrivileges = hive_db.get_privilege_set(HiveObjectType.COLUMN, table.getDbName(), table.getTableName(), partValues, col, this.getAuthenticator().getUserName(), this.getAuthenticator().getGroupNames());
authorizePrivileges(partColumnPrivileges, inputRequiredPriv, inputCheck2, outputRequiredPriv, outputCheck2);
if (inputCheck2 != null) {
booleanArrayOr(inputCheck2, inputCheck);
}
if (outputCheck2 != null) {
booleanArrayOr(inputCheck2, inputCheck);
}
checkAndThrowAuthorizationException(inputRequiredPriv, outputRequiredPriv, inputCheck2, outputCheck2, table.getDbName(), table.getTableName(), partName, col);
}
}
Aggregations