Search in sources :

Example 51 with HiveObjectPrivilege

use of org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege in project hive by apache.

the class ObjectStore method listPrincipalTableColumnGrantsAll.

@Override
public List<HiveObjectPrivilege> listPrincipalTableColumnGrantsAll(String principalName, PrincipalType principalType) {
    boolean success = false;
    Query query = null;
    try {
        openTransaction();
        LOG.debug("Executing listPrincipalTableColumnGrantsAll");
        List<MTableColumnPrivilege> mSecurityTabPartList;
        if (principalName != null && principalType != null) {
            query = pm.newQuery(MTableColumnPrivilege.class, "principalName == t1 && principalType == t2");
            query.declareParameters("java.lang.String t1, java.lang.String t2");
            mSecurityTabPartList = (List<MTableColumnPrivilege>) query.execute(principalName, principalType.toString());
        } else {
            query = pm.newQuery(MTableColumnPrivilege.class);
            mSecurityTabPartList = (List<MTableColumnPrivilege>) query.execute();
        }
        LOG.debug("Done executing query for listPrincipalTableColumnGrantsAll");
        pm.retrieveAll(mSecurityTabPartList);
        List<HiveObjectPrivilege> result = convertTableCols(mSecurityTabPartList);
        success = commitTransaction();
        LOG.debug("Done retrieving all objects for listPrincipalTableColumnGrantsAll");
        return result;
    } finally {
        rollbackAndCleanup(success, query);
    }
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)

Example 52 with HiveObjectPrivilege

use of org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege in project hive by apache.

the class ObjectStore method convertDC.

private List<HiveObjectPrivilege> convertDC(List<MDCPrivilege> privs) {
    List<HiveObjectPrivilege> result = new ArrayList<>();
    for (MDCPrivilege priv : privs) {
        String pname = priv.getPrincipalName();
        String authorizer = priv.getAuthorizer();
        PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
        String dataConnectorName = priv.getDataConnector().getName();
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.DATACONNECTOR, null, dataConnectorName, null, null);
        PrivilegeGrantInfo grantor = new PrivilegeGrantInfo(priv.getPrivilege(), priv.getCreateTime(), priv.getGrantor(), PrincipalType.valueOf(priv.getGrantorType()), priv.getGrantOption());
        result.add(new HiveObjectPrivilege(objectRef, pname, ptype, grantor, authorizer));
    }
    return result;
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) MDCPrivilege(org.apache.hadoop.hive.metastore.model.MDCPrivilege) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 53 with HiveObjectPrivilege

use of org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege in project presto by prestodb.

the class ThriftHiveMetastore method listTablePrivileges.

@Override
public Set<HivePrivilegeInfo> listTablePrivileges(MetastoreContext metastoreContext, String databaseName, String tableName, PrestoPrincipal principal) {
    try {
        return retry().stopOnIllegalExceptions().run("getListPrivileges", stats.getListPrivileges().wrap(() -> getMetastoreClientThenCall(metastoreContext, client -> {
            Table table = client.getTable(databaseName, tableName);
            ImmutableSet.Builder<HivePrivilegeInfo> privileges = ImmutableSet.builder();
            List<HiveObjectPrivilege> hiveObjectPrivilegeList;
            // principal can be null when we want to list all privileges for admins
            if (principal == null) {
                hiveObjectPrivilegeList = client.listPrivileges(null, null, new HiveObjectRef(TABLE, databaseName, tableName, null, null));
            } else {
                if (principal.getType() == USER && table.getOwner().equals(principal.getName())) {
                    privileges.add(new HivePrivilegeInfo(OWNERSHIP, true, principal, principal));
                }
                hiveObjectPrivilegeList = client.listPrivileges(principal.getName(), fromPrestoPrincipalType(principal.getType()), new HiveObjectRef(TABLE, databaseName, tableName, null, null));
            }
            for (HiveObjectPrivilege hiveObjectPrivilege : hiveObjectPrivilegeList) {
                PrestoPrincipal grantee = new PrestoPrincipal(fromMetastoreApiPrincipalType(hiveObjectPrivilege.getPrincipalType()), hiveObjectPrivilege.getPrincipalName());
                privileges.addAll(parsePrivilege(hiveObjectPrivilege.getGrantInfo(), Optional.of(grantee)));
            }
            return privileges.build();
        })));
    } catch (TException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    } catch (Exception e) {
        throw propagate(e);
    }
}
Also used : TException(org.apache.thrift.TException) HivePrivilegeInfo(com.facebook.presto.hive.metastore.HivePrivilegeInfo) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Table(org.apache.hadoop.hive.metastore.api.Table) ThriftMetastoreUtil.fromMetastoreApiTable(com.facebook.presto.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) ImmutableSet(com.google.common.collect.ImmutableSet) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) PrestoException(com.facebook.presto.spi.PrestoException) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal) SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) HiveViewNotSupportedException(com.facebook.presto.hive.HiveViewNotSupportedException) PrestoException(com.facebook.presto.spi.PrestoException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException)

Aggregations

HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)53 ArrayList (java.util.ArrayList)38 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)38 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)37 List (java.util.List)15 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)15 LinkedList (java.util.LinkedList)13 PrivilegeBag (org.apache.hadoop.hive.metastore.api.PrivilegeBag)11 Database (org.apache.hadoop.hive.metastore.api.Database)10 IOException (java.io.IOException)9 PrincipalPrivilegeSet (org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet)9 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)9 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)9 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)9 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)9 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)9 Query (javax.jdo.Query)8 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)8 Table (org.apache.hadoop.hive.metastore.api.Table)8 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)8