Search in sources :

Example 6 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.

the class ObjectStore method grantRole.

@Override
public boolean grantRole(Role role, String userName, PrincipalType principalType, String grantor, PrincipalType grantorType, boolean grantOption) throws MetaException, NoSuchObjectException, InvalidObjectException {
    boolean success = false;
    boolean commited = false;
    try {
        openTransaction();
        MRoleMap roleMap = null;
        try {
            roleMap = this.getMSecurityUserRoleMap(userName, principalType, role.getRoleName());
        } catch (Exception e) {
        }
        if (roleMap != null) {
            throw new InvalidObjectException("Principal " + userName + " already has the role " + role.getRoleName());
        }
        if (principalType == PrincipalType.ROLE) {
            validateRole(userName);
        }
        MRole mRole = getMRole(role.getRoleName());
        long now = System.currentTimeMillis() / 1000;
        MRoleMap roleMember = new MRoleMap(userName, principalType.toString(), mRole, (int) now, grantor, grantorType.toString(), grantOption);
        pm.makePersistent(roleMember);
        commited = commitTransaction();
        success = true;
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MRole(org.apache.hadoop.hive.metastore.model.MRole) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap) JDOException(javax.jdo.JDOException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException)

Example 7 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.

the class ObjectStore method getAllRoleAncestors.

/**
   * Add role names of parentRoles and its parents to processedRoles
   *
   * @param processedRoleNames
   * @param parentRoles
   */
private void getAllRoleAncestors(Set<String> processedRoleNames, List<MRoleMap> parentRoles) {
    for (MRoleMap parentRole : parentRoles) {
        String parentRoleName = parentRole.getRole().getRoleName();
        if (!processedRoleNames.contains(parentRoleName)) {
            // unprocessed role: get its parents, add it to processed, and call this
            // function recursively
            List<MRoleMap> nextParentRoles = listMRoles(parentRoleName, PrincipalType.ROLE);
            processedRoleNames.add(parentRoleName);
            getAllRoleAncestors(processedRoleNames, nextParentRoles);
        }
    }
}
Also used : MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Example 8 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.

the class ObjectStore method listRolesWithGrants.

@Override
public List<RolePrincipalGrant> listRolesWithGrants(String principalName, PrincipalType principalType) {
    List<RolePrincipalGrant> result = new ArrayList<RolePrincipalGrant>();
    List<MRoleMap> roleMaps = listMRoles(principalName, principalType);
    if (roleMaps != null) {
        for (MRoleMap roleMap : roleMaps) {
            RolePrincipalGrant rolePrinGrant = new RolePrincipalGrant(roleMap.getRole().getRoleName(), roleMap.getPrincipalName(), PrincipalType.valueOf(roleMap.getPrincipalType()), roleMap.getGrantOption(), roleMap.getAddTime(), roleMap.getGrantor(), // no grantor type for public role, hence the null check
            roleMap.getGrantorType() == null ? null : PrincipalType.valueOf(roleMap.getGrantorType()));
            result.add(rolePrinGrant);
        }
    }
    return result;
}
Also used : RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) ArrayList(java.util.ArrayList) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Example 9 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.

the class ObjectStore method listMRoles.

@SuppressWarnings("unchecked")
public List<MRoleMap> listMRoles(String principalName, PrincipalType principalType) {
    boolean success = false;
    Query query = null;
    List<MRoleMap> mRoleMember = new ArrayList<MRoleMap>();
    try {
        LOG.debug("Executing listRoles");
        openTransaction();
        query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2");
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        query.setUnique(false);
        List<MRoleMap> mRoles = (List<MRoleMap>) query.executeWithArray(principalName, principalType.toString());
        pm.retrieveAll(mRoles);
        success = commitTransaction();
        mRoleMember.addAll(mRoles);
        LOG.debug("Done retrieving all objects for listRoles");
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
    if (principalType == PrincipalType.USER) {
        // All users belong to public role implicitly, add that role
        MRole publicRole = new MRole(HiveMetaStore.PUBLIC, 0, HiveMetaStore.PUBLIC);
        mRoleMember.add(new MRoleMap(principalName, principalType.toString(), publicRole, 0, null, null, false));
    }
    return mRoleMember;
}
Also used : Query(javax.jdo.Query) MRole(org.apache.hadoop.hive.metastore.model.MRole) ArrayList(java.util.ArrayList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Example 10 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.

the class ObjectStore method listMSecurityPrincipalMembershipRole.

@SuppressWarnings("unchecked")
private List<MRoleMap> listMSecurityPrincipalMembershipRole(final String roleName, final PrincipalType principalType, QueryWrapper queryWrapper) {
    boolean success = false;
    List<MRoleMap> mRoleMemebership = null;
    try {
        LOG.debug("Executing listMSecurityPrincipalMembershipRole");
        openTransaction();
        Query query = queryWrapper.query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2");
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        mRoleMemebership = (List<MRoleMap>) query.execute(roleName, principalType.toString());
        pm.retrieveAll(mRoleMemebership);
        success = commitTransaction();
        LOG.debug("Done retrieving all objects for listMSecurityPrincipalMembershipRole");
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return mRoleMemebership;
}
Also used : Query(javax.jdo.Query) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Aggregations

MRoleMap (org.apache.hadoop.hive.metastore.model.MRoleMap)11 ArrayList (java.util.ArrayList)5 Query (javax.jdo.Query)4 MRole (org.apache.hadoop.hive.metastore.model.MRole)4 LinkedList (java.util.LinkedList)2 List (java.util.List)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 RolePrincipalGrant (org.apache.hadoop.hive.metastore.api.RolePrincipalGrant)2 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)2 IOException (java.io.IOException)1 JDOCanRetryException (javax.jdo.JDOCanRetryException)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 JDOException (javax.jdo.JDOException)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)1 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1 InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 Role (org.apache.hadoop.hive.metastore.api.Role)1 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)1