/** * Return the resolved role. A resolved role may be a {@link RoleLink} itself, or null (if a link is incorrect). * * @return {@link Role} */ @Override public <T extends Role> T resolve() { int maxDepth = 40; for (Role r = this; maxDepth > 0; maxDepth--) { if (r instanceof RoleLink) { r = ((RoleLink) r).getRole(); if (r == null) return null; } else return (T) r; } return null; // throw new IllegalStateException("RoleLink depth exceeded, possible circular references"); }
/** * A role has exactly same set of keys as in the supplied role. It does not check the logic, * only that list of all keys is exactly same. * <p> * To check that the role can be performed by some other role, use {@link #isAllowedForKeys(Set)}. * * @param otherRole is {@link Role} for checking by keys * @return true if equals */ @Override @Deprecated public boolean equalKeys(Role otherRole) { final Role role = getRole(); return (role == null) ? false : role.equalKeys(otherRole); }
public boolean containReference(String name) { if(requiredAllReferences.contains(name) || requiredAnyReferences.contains(name)) return true; if(this instanceof RoleLink) { return ((RoleLink)this).getRole().containReference(name); } if(this instanceof ListRole) { return ((ListRole)this).getRoles().stream().anyMatch(r -> r.containReference(name)); } return false; }
/** * Get role as string. * * @return string with data of role */ @Override public String toString() { if (getContract() != null) { final Role role = getRole(); return "RoleLink<" + getName() + "->" + roleName + ":" + ((role == null) ? "null" : role.toString()) + ">"; } else { return "RoleLink<" + getName() + "->" + roleName + ":" + "not connected>"; } }
assertEquals(c.getOwner(), ((RoleLink) c.getPermissions().getFirst("change_owner").getRole()).getRole()); assertEquals(c2, ((RoleLink) c2.getPermissions().getFirst("change_owner").getRole()).getContract()); assertEquals(c, ((RoleLink) c.getPermissions().getFirst("change_owner").getRole()).getContract()); c2.setOwnerKey(ownerKey3); assertNotEquals(c.getOwner(), c2.getOwner()); assertEquals(c.getOwner(), ((RoleLink) c.getPermissions().getFirst("change_owner").getRole()).getRole());