/** * 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); } } }
@Override public List<Role> listRoles(String principalName, PrincipalType principalType) { List<Role> result = new ArrayList<>(); List<MRoleMap> roleMaps = listMRoles(principalName, principalType); if (roleMaps != null) { for (MRoleMap roleMap : roleMaps) { MRole mrole = roleMap.getRole(); Role role = new Role(mrole.getRoleName(), mrole.getCreateTime(), mrole.getOwnerName()); result.add(role); } } return result; }
@Override public List<RolePrincipalGrant> listRoleMembers(String roleName) { List<MRoleMap> roleMaps = listMRoleMembers(roleName); List<RolePrincipalGrant> rolePrinGrantList = new ArrayList<>(); 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()) ); rolePrinGrantList.add(rolePrinGrant); } } return rolePrinGrantList; }
@Override public List<RolePrincipalGrant> listRolesWithGrants(String principalName, PrincipalType principalType) { List<RolePrincipalGrant> result = new ArrayList<>(); 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; }
/** * 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); } } }
/** * 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 = listRoles(parentRoleName, PrincipalType.ROLE); processedRoleNames.add(parentRoleName); getAllRoleAncestors(processedRoleNames, nextParentRoles); } } }
/** * 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 = listRoles(parentRoleName, PrincipalType.ROLE); processedRoleNames.add(parentRoleName); getAllRoleAncestors(processedRoleNames, nextParentRoles); } } }
@Override public List<Role> listRoles(String principalName, PrincipalType principalType) { List<Role> result = new ArrayList<>(); List<MRoleMap> roleMaps = listMRoles(principalName, principalType); if (roleMaps != null) { for (MRoleMap roleMap : roleMaps) { MRole mrole = roleMap.getRole(); Role role = new Role(mrole.getRoleName(), mrole.getCreateTime(), mrole.getOwnerName()); result.add(role); } } return result; }
@Override List<Role> run(RawStore ms) throws Exception { List<Role> result = new ArrayList<Role>(); List<MRoleMap> roleMap = ms.listRoles(principalName, principalType); if (roleMap!=null) { for (MRoleMap role : roleMap) { MRole r = role.getRole(); result.add(new Role(r.getRoleName(), r .getCreateTime(), r.getOwnerName())); } } return result; } });
/** * Check if newRole is in parent hierarchy of curRole * @param newRole * @param curRole * @return true if newRole is curRole or present in its hierarchy * @throws MetaException */ private boolean isNewRoleAParent(String newRole, String curRole) throws MetaException { if(newRole.equals(curRole)){ return true; } //do this check recursively on all the parent roles of curRole List<MRoleMap> parentRoleMaps = getMS().listRoles(curRole, PrincipalType.ROLE); for(MRoleMap parentRole : parentRoleMaps){ if(isNewRoleAParent(newRole, parentRole.getRole().getRoleName())){ return true; } } return false; }
/** * Check if newRole is in parent hierarchy of curRole * @param newRole * @param curRole * @return true if newRole is curRole or present in its hierarchy * @throws MetaException */ private boolean isNewRoleAParent(String newRole, String curRole) throws MetaException { if(newRole.equals(curRole)){ return true; } //do this check recursively on all the parent roles of curRole List<MRoleMap> parentRoleMaps = getMS().listRoles(curRole, PrincipalType.ROLE); for(MRoleMap parentRole : parentRoleMaps){ if(isNewRoleAParent(newRole, parentRole.getRole().getRoleName())){ return true; } } return false; }
Map<String, List<PrivilegeGrantInfo>> tableRolePriv = new HashMap<String, List<PrivilegeGrantInfo>>(); for (MRoleMap role : roles) { String roleName = role.getRole().getRoleName(); tableRolePriv.put(roleName, getTablePrivilege(dbName, tableName, roleName, PrincipalType.ROLE));
public List<Role> list_roles(final String principalName, final PrincipalType principalType) throws MetaException, TException { incrementCounter("list_roles"); List<Role> ret = null; try { List<Role> result = new ArrayList<Role>(); List<MRoleMap> roleMap = getMS().listRoles(principalName, principalType); if (roleMap != null) { for (MRoleMap role : roleMap) { MRole r = role.getRole(); result.add(new Role(r.getRoleName(), r .getCreateTime(), r.getOwnerName())); } } ret = result; } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return ret; }
Map<String, List<PrivilegeGrantInfo>> dbRolePriv = new HashMap<String, List<PrivilegeGrantInfo>>(); for (MRoleMap role : roles) { String name = role.getRole().getRoleName(); dbRolePriv .put(name, getDBPrivilege(dbName, name, PrincipalType.ROLE));
@Override public List<Role> list_roles(final String principalName, final PrincipalType principalType) throws MetaException, TException { incrementCounter("list_roles"); firePreEvent(new PreAuthorizationCallEvent(this)); List<Role> result = new ArrayList<Role>(); try { List<MRoleMap> roleMaps = getMS().listRoles(principalName, principalType); if (roleMaps != null) { for (MRoleMap roleMap : roleMaps) { MRole mrole = roleMap.getRole(); Role role = new Role(mrole.getRoleName(), mrole.getCreateTime(), mrole.getOwnerName()); result.add(role); } } return result; } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public List<Role> list_roles(final String principalName, final PrincipalType principalType) throws MetaException, TException { incrementCounter("list_roles"); firePreEvent(new PreAuthorizationCallEvent(this)); List<Role> result = new ArrayList<Role>(); try { List<MRoleMap> roleMaps = getMS().listRoles(principalName, principalType); if (roleMaps != null) { for (MRoleMap roleMap : roleMaps) { MRole mrole = roleMap.getRole(); Role role = new Role(mrole.getRoleName(), mrole.getCreateTime(), mrole.getOwnerName()); result.add(role); } } return result; } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Convert each MRoleMap object into a thrift RolePrincipalGrant object * @param roleMaps * @return */ private List<RolePrincipalGrant> getRolePrincipalGrants(List<MRoleMap> roleMaps) { List<RolePrincipalGrant> rolePrinGrantList = new ArrayList<RolePrincipalGrant>(); 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()) ); rolePrinGrantList.add(rolePrinGrant); } } return rolePrinGrantList; }
@Override public List<RolePrincipalGrant> listRolesWithGrants(String principalName, PrincipalType principalType) { List<RolePrincipalGrant> result = new ArrayList<>(); 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; }
/** * Convert each MRoleMap object into a thrift RolePrincipalGrant object * @param roleMaps * @return */ private List<RolePrincipalGrant> getRolePrincipalGrants(List<MRoleMap> roleMaps) { List<RolePrincipalGrant> rolePrinGrantList = new ArrayList<RolePrincipalGrant>(); 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()) ); rolePrinGrantList.add(rolePrinGrant); } } return rolePrinGrantList; }
@Override public List<RolePrincipalGrant> listRoleMembers(String roleName) { List<MRoleMap> roleMaps = listMRoleMembers(roleName); List<RolePrincipalGrant> rolePrinGrantList = new ArrayList<>(); 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()) ); rolePrinGrantList.add(rolePrinGrant); } } return rolePrinGrantList; }