/** * Determine whether this permission is equal to another permission. Returns {@code true} if * both {@link #actionsEquals(AbstractActionPermission)} and {@link #nameEquals(AbstractNamedPermission)} * return {@code true}. * * @param permission the other permission * @return {@code true} if this permission implies the other; {@code false} otherwise */ public final boolean equals(final This permission) { return super.equals(permission) && actionsEquals(permission); }
/** * Construct a new instance. The name enumeration is pulled from the source permission object. * * @param sourcePermission the source permission object (must not be {@code null}) * @return the permission collection */ public static AbstractPermissionCollection newInstance(final AbstractNameSetOnlyPermission<?> sourcePermission) { return newInstance(sourcePermission, sourcePermission.getNameEnumeration()); }
public final int hashCode() { return super.hashCode() * 53 + actionsHashCode(); }
/** * Determine whether this permission implies another permission. Returns {@code true} if * both {@link #impliesActions(AbstractActionPermission)} and {@link #impliesName(AbstractNamedPermission)} * return {@code true}. * * @param permission the other permission * @return {@code true} if this permission implies the other; {@code false} otherwise */ public final boolean implies(final This permission) { return permission != null && impliesActions(permission) && impliesName(permission); }
/** * Determine whether this permission's actions value implies the given action bits. * * @param actionBits the actions bits to test * @return {@code true} if this permission implies the given action bits; {@code false} otherwise */ public final boolean impliesActionBits(final int actionBits) { return isSet(this.actionBits, actionBits & actionsMask()); }
/** * Determine whether this permission has a name equal to the name of the given permission. * * @param permission the permission whose name is to be checked * @return {@code true} if this permission's name is equal to the given permission's name, {@code false} otherwise */ public final boolean nameEquals(final This permission) { return permission != null && nameEquals(permission.getName()); }
/** * Get a permission which is identical to this one, but with new actions which consist of the union of the actions * from this permission and the action bits from the given value. The returned permission may or may not be a new * instance, and may be equal to this instance. * * @param actionBits the action bits * @return the permission (not {@code null}) */ public final This withActionBits(int actionBits) { return withNewActionBits(this.actionBits | actionBits & actionsMask()); }
/** * Determine whether this permission implies the name of the given permission. * * @param permission the permission whose name is to be checked * @return {@code true} if this permission's name implies the given name, {@code false} otherwise */ public boolean impliesName(final This permission) { return permission != null && impliesName(permission.getName()); }
/** * Return a new verifier which implies the opposite of this verifier. * * @return the new permission verifier (not {@code null}) */ default PermissionVerifier not() { return permission -> ! implies(permission); }
/** * Get an empty permission collection which is capable of holding instances of this permission type. * <p> * The default implementation returns a {@link SimplePermissionCollection}. * * @return the permission collection to use */ public AbstractPermissionCollection newPermissionCollection() { return new SimplePermissionCollection(this); }
/** * Determine if one collection implies all the permissions in the other collection. * * @param collection the collection to check against (must not be {@code null}) * @param testCollection the collection whose permissions are to be tested (must not be {@code null}) * @return {@code true} if {@code collection} implies all of the permissions in {@code testCollection}, {@code false} otherwise */ public static boolean impliesAll(PermissionCollection collection, PermissionCollection testCollection) { return forEachIn(collection, PermissionCollection::implies, testCollection); }
/** * Construct a new instance. * * @param name the name of the permission * @param actions the actions (should be empty) */ public ElytronPermission(final String name, final String actions) { super(name, strings); requireEmptyActions(actions); }
/** * Determine whether this permission implies the given name. * * @param name the name to check * @return {@code true} if this permission's name implies the given name, {@code false} otherwise */ public boolean impliesName(final String name) { return nameEquals("*") || nameEquals(name); }
/** * Determine if two permission collections are equal, that is, each collection implies all of the permissions in the * other collection. * * @param pc1 the first collection (must not be {@code null}) * @param pc2 the second collection (must not be {@code null}) * @return {@code true} if the collections imply one another, {@code false} otherwise */ public static boolean equals(PermissionCollection pc1, PermissionCollection pc2) { return impliesAll(pc1, pc2) && impliesAll(pc2, pc1); }
/** * Get a permission which is identical to this one, but with new actions which consist of the actions * from this permission without the action bits from the given value. The returned permission may or may not be a new * instance, and may be equal to this instance. * * @param actionBits the action bits * @return the permission (not {@code null}) */ public final This withoutActionBits(int actionBits) { return withNewActionBits(this.actionBits & ~actionBits); }
UnionPermissionCollection(final PermissionCollection pc1, final PermissionCollection pc2) { this.pc1 = pc1; this.pc2 = pc2; setReadOnly(); }
IntersectionPermissionCollection(final PermissionCollection pc1, final PermissionCollection pc2) { this.pc1 = pc1; this.pc2 = pc2; setReadOnly(); }
/** * Get the actions string. The string is computed the first time this method is called, and cached thereafter. * * @return the actions string (not {@code null}) */ public final String getActions() { final String actions = this.actions; if (actions != null) { return actions; } return this.actions = PermissionUtil.toActionsString(actionBits, this::getActionName); }
/** * Parse the actions string into a bit set. * * @param actionsString the actions string * @return the bit set * @throws IllegalArgumentException if the actions string contained an invalid name or invalid syntax */ public final int parseActions(final String actionsString) throws IllegalArgumentException { return PermissionUtil.parseActions(actionsString, this::getActionBit); }
/** * Add all of the permissions from the source collection to the target collection. * * @param target the target collection (must not be {@code null}) * @param source the source collection (must not be {@code null}) * @return the target collection (not {@code null}) */ public static PermissionCollection addAll(PermissionCollection target, PermissionCollection source) { return forEachIn(source, PermissionCollection::add, target); }