/** * Construct a new Right from its description. * This is a package private constructor, the registration of a new right should be done using * the {@link AuthorizationManager} * * @param description Description of the right to create. */ Right(RightDescription description) { this(description.getName(), description.getDefaultState(), description.getTieResolutionPolicy(), description.getInheritanceOverridePolicy(), description.getImpliedRights(), description.getTargetedEntityType(), description.isReadOnly()); }
/** * @param right The right description of the right that fail to register. * @param t A throwable of the detailed exception. */ public UnableToRegisterRightException(RightDescription right, Throwable t) { super(String.format("Unable to register right [%s].", right.getName()), t); } }
@Override public Right register(RightDescription rightDescription) throws UnableToRegisterRightException { try { Right newRight = new Right(rightDescription); // cleanup the cache since a new right scheme enter in action securityCache.remove(securityReferenceFactory.newEntityReference(xwikiBridge.getMainWikiReference())); return newRight; } catch (Throwable e) { Right right = Right.toRight(rightDescription.getName()); if (right != Right.ILLEGAL && right.like(rightDescription)) { return right; } throw new UnableToRegisterRightException(rightDescription, e); } }
/** * @param description a right description to compare this right to. * @return true if the right is equivalent to the provided description. */ boolean like(RightDescription description) { return new EqualsBuilder() .append(this.isReadOnly(), description.isReadOnly()) .append(this.getDefaultState(), description.getDefaultState()) .append(this.getTieResolutionPolicy(), description.getTieResolutionPolicy()) .append(this.getInheritanceOverridePolicy(), description.getInheritanceOverridePolicy()) .append(this.getTargetedEntityType(), description.getTargetedEntityType()) .append(this.getImpliedRights(), description.getImpliedRights()) .isEquals(); } }