/** * <p> * This method traverses the role tree that has the specified root role and puts all simple (i.e. not an instance of * RoleGroup) roles into the specified roles list. * </p> * * @param role the root of the role tree. * @param roles the {@code List<Role>} that contains the simple roles of the tree. */ protected void getAllRoles(Role role, List<Role> roles) { if (role instanceof RoleGroup) { RoleGroup group = (RoleGroup) role; for (Role nestedRole : group.getRoles()) getAllRoles(nestedRole, roles); } else roles.add(role); } }
/** * <p> * This method traverses the role tree that has the specified root role and puts all simple (i.e. not an instance of * RoleGroup) roles into the specified roles list. * </p> * * @param role the root of the role tree. * @param roles the {@code List<Role>} that contains the simple roles of the tree. */ protected void getAllRoles(Role role, List<Role> roles) { if (role instanceof RoleGroup) { RoleGroup group = (RoleGroup) role; for (Role nestedRole : group.getRoles()) getAllRoles(nestedRole, roles); } else roles.add(role); } }
@Override @SuppressWarnings("unchecked") public <T> Set<T> getEntitlements(Class<T> clazz, Resource resource, Identity identity) throws AuthorizationException { if (identity.getRole() == null) return super.getEntitlements(clazz, resource, identity); // currently we only provide sets of EntitlementEntry objects. if (!EntitlementEntry.class.equals(clazz)) return null; Set<EntitlementEntry> entitlements = new HashSet<EntitlementEntry>(); // fill the entitlements for each role. List<Role> roles = new ArrayList<Role>(); this.getAllRoles(identity.getRole(), roles); for (Role role : roles) { // get the initial permissions - those that apply to the specified resource. ACLPermission permission = super.getInitialPermissions(resource, role.getRoleName()); if (permission != null) super.fillEntitlements(entitlements, resource, role.getRoleName(), permission); } return (Set<T>) entitlements; }
@Override @SuppressWarnings("unchecked") public <T> Set<T> getEntitlements(Class<T> clazz, Resource resource, Identity identity) throws AuthorizationException { if (identity.getRole() == null) return super.getEntitlements(clazz, resource, identity); // currently we only provide sets of EntitlementEntry objects. if (!EntitlementEntry.class.equals(clazz)) return null; Set<EntitlementEntry> entitlements = new HashSet<EntitlementEntry>(); // fill the entitlements for each role. List<Role> roles = new ArrayList<Role>(); this.getAllRoles(identity.getRole(), roles); for (Role role : roles) { // get the initial permissions - those that apply to the specified resource. ACLPermission permission = super.getInitialPermissions(resource, role.getRoleName()); if (permission != null) super.fillEntitlements(entitlements, resource, role.getRoleName(), permission); } return (Set<T>) entitlements; }
this.getAllRoles(identity.getRole(), roles);
this.getAllRoles(identity.getRole(), roles);