private List<HiveRoleGrant> getRolesFromMS() throws HiveAuthzPluginException { try { List<RolePrincipalGrant> roles = getRoleGrants(currentUserName, PrincipalType.USER); Map<String, HiveRoleGrant> name2Rolesmap = new HashMap<String, HiveRoleGrant>(); getAllRoleAncestors(name2Rolesmap, roles); List<HiveRoleGrant> currentRoles = new ArrayList<HiveRoleGrant>(roles.size()); for (HiveRoleGrant role : name2Rolesmap.values()) { if (!HiveMetaStore.ADMIN.equalsIgnoreCase(role.getRoleName())) { currentRoles.add(role); } else { this.adminRole = role; } } return currentRoles; } catch (Exception e) { throw SQLAuthorizationUtils.getPluginException("Failed to retrieve roles for " + currentUserName, e); } }
private List<HiveRoleGrant> getRolesFromMS() throws HiveAuthzPluginException { try { List<RolePrincipalGrant> roles = getRoleGrants(currentUserName, PrincipalType.USER); Map<String, HiveRoleGrant> name2Rolesmap = new HashMap<String, HiveRoleGrant>(); getAllRoleAncestors(name2Rolesmap, roles); List<HiveRoleGrant> currentRoles = new ArrayList<HiveRoleGrant>(roles.size()); for (HiveRoleGrant role : name2Rolesmap.values()) { if (!HiveMetaStore.ADMIN.equalsIgnoreCase(role.getRoleName())) { currentRoles.add(role); } else { this.adminRole = role; } } return currentRoles; } catch (Exception e) { throw SQLAuthorizationUtils.getPluginException("Failed to retrieve roles for " + currentUserName, e); } }
/** * Add role names of parentRoles and its parents to processedRolesMap * * @param processedRolesMap * @param roleGrants * @throws TException * @throws HiveAuthzPluginException * @throws MetaException */ private void getAllRoleAncestors(Map<String, HiveRoleGrant> processedRolesMap, List<RolePrincipalGrant> roleGrants) throws MetaException, HiveAuthzPluginException, TException { for (RolePrincipalGrant parentRoleGrant : roleGrants) { String parentRoleName = parentRoleGrant.getRoleName(); if (processedRolesMap.get(parentRoleName) == null) { // unprocessed role: get its parents, add it to processed, and call this // function recursively List<RolePrincipalGrant> nextParentRoles = getRoleGrants(parentRoleName, PrincipalType.ROLE); processedRolesMap.put(parentRoleName, new HiveRoleGrant(parentRoleGrant)); getAllRoleAncestors(processedRolesMap, nextParentRoles); } } }
/** * Add role names of parentRoles and its parents to processedRolesMap * * @param processedRolesMap * @param roleGrants * @throws TException * @throws HiveAuthzPluginException * @throws MetaException */ private void getAllRoleAncestors(Map<String, HiveRoleGrant> processedRolesMap, List<RolePrincipalGrant> roleGrants) throws MetaException, HiveAuthzPluginException, TException { for (RolePrincipalGrant parentRoleGrant : roleGrants) { String parentRoleName = parentRoleGrant.getRoleName(); if (processedRolesMap.get(parentRoleName) == null) { // unprocessed role: get its parents, add it to processed, and call this // function recursively List<RolePrincipalGrant> nextParentRoles = getRoleGrants(parentRoleName, PrincipalType.ROLE); processedRolesMap.put(parentRoleName, new HiveRoleGrant(parentRoleGrant)); getAllRoleAncestors(processedRolesMap, nextParentRoles); } } }
private List<HiveRoleGrant> getRolesFromMS() throws HiveAuthzPluginException { try { List<RolePrincipalGrant> roles = getRoleGrants(currentUserName, PrincipalType.USER); Map<String, HiveRoleGrant> name2Rolesmap = new HashMap<String, HiveRoleGrant>(); getAllRoleAncestors(name2Rolesmap, roles); List<HiveRoleGrant> currentRoles = new ArrayList<HiveRoleGrant>(roles.size()); for (HiveRoleGrant role : name2Rolesmap.values()) { if (!HiveMetaStore.ADMIN.equalsIgnoreCase(role.getRoleName())) { currentRoles.add(role); } else { this.adminRole = role; } } return currentRoles; } catch (Exception e) { throw SQLAuthorizationUtils.getPluginException("Failed to retrieve roles for " + currentUserName, e); } }
/** * Add role names of parentRoles and its parents to processedRolesMap * * @param processedRolesMap * @param roleGrants * @throws TException * @throws HiveAuthzPluginException * @throws MetaException */ private void getAllRoleAncestors(Map<String, HiveRoleGrant> processedRolesMap, List<RolePrincipalGrant> roleGrants) throws MetaException, HiveAuthzPluginException, TException { for (RolePrincipalGrant parentRoleGrant : roleGrants) { String parentRoleName = parentRoleGrant.getRoleName(); if (processedRolesMap.get(parentRoleName) == null) { // unprocessed role: get its parents, add it to processed, and call this // function recursively List<RolePrincipalGrant> nextParentRoles = getRoleGrants(parentRoleName, PrincipalType.ROLE); processedRolesMap.put(parentRoleName, new HiveRoleGrant(parentRoleGrant)); getAllRoleAncestors(processedRolesMap, nextParentRoles); } } }