diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 5fc4af4..487d292 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -42,7 +42,6 @@ import java.util.Properties; import java.util.Set; import java.util.Timer; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -3999,8 +3998,6 @@ private boolean isNewRoleAParent(String newRole, String curRole) throws MetaExce result.add(role); } } - // all users by default belongs to public role - result.add(new Role(PUBLIC,0,PUBLIC)); return result; } catch (MetaException e) { throw e; @@ -4909,9 +4906,6 @@ public GetRoleGrantsForPrincipalResponse get_role_grants_for_principal( } List roleGrantsList = getRolePrincipalGrants(roleMaps); - // all users by default belongs to public role - roleGrantsList.add(new RolePrincipalGrant(PUBLIC, request.getPrincipal_name(), request - .getPrincipal_type(), false, 0, null, null)); return new GetRoleGrantsForPrincipalResponse(roleGrantsList); } @@ -4931,7 +4925,9 @@ public GetRoleGrantsForPrincipalResponse get_role_grants_for_principal( roleMap.getGrantOption(), roleMap.getAddTime(), roleMap.getGrantor(), - PrincipalType.valueOf(roleMap.getGrantorType()) + // no grantor type for public role, hence the null check + roleMap.getGrantorType() == null ? null + : PrincipalType.valueOf(roleMap.getGrantorType()) ); rolePrinGrantList.add(rolePrinGrant); } diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java index 3ea87a0..5f69a13 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -3186,6 +3186,7 @@ public boolean removeRole(String roleName) throws MetaException, // get names of these roles and its ancestors Set roleNames = new HashSet(); getAllRoleAncestors(roleNames, ret); + return roleNames; } @@ -3235,7 +3236,20 @@ private void getAllRoleAncestors(Set processedRoleNames, List rollbackTransaction(); } } + + if (principalType == PrincipalType.USER) { + // All users belong to public role implicitly, add that role + if (mRoleMember == null) { + mRoleMember = new ArrayList(); + } else { + mRoleMember = new ArrayList(mRoleMember); + } + MRole publicRole = new MRole(HiveMetaStore.PUBLIC, 0, HiveMetaStore.PUBLIC); + mRoleMember.add(new MRoleMap(principalName, principalType.toString(), publicRole, 0, + null, null, false)); + } return mRoleMember; + } @SuppressWarnings("unchecked")