Search in sources :

Example 6 with Role

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

the class SQLStdHiveAccessController method createRole.

@Override
public void createRole(String roleName, HivePrincipal adminGrantor) throws HiveAuthzPluginException, HiveAccessControlException {
    // only user belonging to admin role can create new roles.
    if (!isUserAdmin()) {
        throw new HiveAccessControlException("Current user : " + currentUserName + " is not" + " allowed to add roles. " + ADMIN_ONLY_MSG);
    }
    if (RESERVED_ROLE_NAMES.contains(roleName.trim().toUpperCase())) {
        throw new HiveAuthzPluginException("Role name cannot be one of the reserved roles: " + RESERVED_ROLE_NAMES);
    }
    try {
        String grantorName = adminGrantor == null ? null : adminGrantor.getName();
        metastoreClientFactory.getHiveMetastoreClient().create_role(new Role(roleName, 0, grantorName));
    } catch (TException e) {
        throw SQLAuthorizationUtils.getPluginException("Error create role", e);
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) TException(org.apache.thrift.TException) HiveAccessControlException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException) HiveAuthzPluginException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException)

Example 7 with Role

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

the class HiveV1Authorizer method getCurrentRoleNames.

@Override
public List<String> getCurrentRoleNames() throws HiveAuthzPluginException {
    String userName = SessionState.get().getUserName();
    if (userName == null) {
        userName = SessionState.getUserFromAuthenticator();
    }
    if (userName == null) {
        throw new HiveAuthzPluginException("Cannot resolve current user name");
    }
    try {
        Hive hive = Hive.getWithFastCheck(this.conf);
        List<String> roleNames = new ArrayList<String>();
        for (Role role : hive.listRoles(userName, PrincipalType.USER)) {
            roleNames.add(role.getRoleName());
        }
        return roleNames;
    } catch (HiveException e) {
        throw new HiveAuthzPluginException(e);
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) Hive(org.apache.hadoop.hive.ql.metadata.Hive) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ArrayList(java.util.ArrayList)

Example 8 with Role

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

the class TestHBaseStore method dropRole.

@Test
public void dropRole() throws Exception {
    String roleName = "anotherrole";
    store.addRole(roleName, "me");
    Role role = store.getRole(roleName);
    Assert.assertNotNull(role);
    store.removeRole(roleName);
    thrown.expect(NoSuchObjectException.class);
    store.getRole(roleName);
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) Test(org.junit.Test)

Example 9 with Role

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

the class TestHBaseStore method createRole.

@Test
public void createRole() throws Exception {
    int now = (int) System.currentTimeMillis() / 1000;
    String roleName = "myrole";
    store.addRole(roleName, "me");
    Role r = store.getRole(roleName);
    Assert.assertEquals(roleName, r.getRoleName());
    Assert.assertEquals("me", r.getOwnerName());
    Assert.assertTrue(now <= r.getCreateTime());
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) Test(org.junit.Test)

Example 10 with Role

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

the class HBaseStore method listRolesWithGrants.

@Override
public List<RolePrincipalGrant> listRolesWithGrants(String principalName, PrincipalType principalType) {
    boolean commit = false;
    openTransaction();
    try {
        List<Role> roles = listRoles(principalName, principalType);
        List<RolePrincipalGrant> rpgs = new ArrayList<RolePrincipalGrant>(roles.size());
        for (Role role : roles) {
            HbaseMetastoreProto.RoleGrantInfoList grants = getHBase().getRolePrincipals(role.getRoleName());
            if (grants != null) {
                for (HbaseMetastoreProto.RoleGrantInfo grant : grants.getGrantInfoList()) {
                    if (grant.getPrincipalType() == HBaseUtils.convertPrincipalTypes(principalType) && grant.getPrincipalName().equals(principalName)) {
                        rpgs.add(new RolePrincipalGrant(role.getRoleName(), principalName, principalType, grant.getGrantOption(), (int) grant.getAddTime(), grant.getGrantor(), HBaseUtils.convertPrincipalTypes(grant.getGrantorType())));
                    }
                }
            }
        }
        commit = true;
        return rpgs;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) ArrayList(java.util.ArrayList) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) TException(org.apache.thrift.TException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) IOException(java.io.IOException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Aggregations

Role (org.apache.hadoop.hive.metastore.api.Role)30 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)5 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)5 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)5 PrivilegeBag (org.apache.hadoop.hive.metastore.api.PrivilegeBag)5 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)5 Database (org.apache.hadoop.hive.metastore.api.Database)4 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 Table (org.apache.hadoop.hive.metastore.api.Table)3 HashSet (java.util.HashSet)2 Result (org.apache.hadoop.hbase.client.Result)2 ObjectStore (org.apache.hadoop.hive.metastore.ObjectStore)2 RawStore (org.apache.hadoop.hive.metastore.RawStore)2 TestObjectStore (org.apache.hadoop.hive.metastore.TestObjectStore)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 Partition (org.apache.hadoop.hive.metastore.api.Partition)2