mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
03.03.2013 56e752193bfb90d11cfe73c35a24e576b9b18c87
opends/src/server/org/opends/server/authorization/dseecompat/EnumRight.java
@@ -23,11 +23,15 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS
 */
package org.opends.server.authorization.dseecompat;
import static org.opends.server.authorization.dseecompat.Aci.*;
import java.util.EnumSet;
import java.util.Set;
/**
 * This class provides an enumeration of the allowed rights.
 */
@@ -89,7 +93,7 @@
     */
    ADDWRITE    ("addwrite");
    /*
    /**
     * The name of the right.
     */
    private final String right;
@@ -103,6 +107,15 @@
    }
    /**
     * Returns the string representation of the right.
     *
     * @return the string representation of the right
     */
    public String getRight() {
        return right;
    }
    /**
     * Checks if the enumeration is equal to the right name.
     * @param right The name of the right to check.
     * @return  True if the right is equal to the enumeration's.
@@ -171,4 +184,53 @@
        }
        return mask;
    }
    /**
     * Return the EnumRight corresponding to the provided rightsMask.
     *
     * @param rightsMask
     *          the rights mask for which to return the corresponding EnumRight
     * @return EnumRight corresponding to the provided rightsMask.
     */
    public static Set<EnumRight> getEnumRight(int rightsMask) {
        if (hasRights(rightsMask, ACI_ALL))
            return EnumSet.of(ALL);
        final EnumSet<EnumRight> results = EnumSet.noneOf(EnumRight.class);
        if (hasRights(rightsMask, ACI_READ))
            results.add(READ);
        if (hasRights(rightsMask, ACI_WRITE))
            results.add(WRITE);
        if (hasRights(rightsMask, ACI_ADD))
            results.add(ADD);
        if (hasRights(rightsMask, ACI_DELETE))
            results.add(DELETE);
        if (hasRights(rightsMask, ACI_SEARCH))
            results.add(SEARCH);
        if (hasRights(rightsMask, ACI_COMPARE))
            results.add(COMPARE);
        if (hasRights(rightsMask, ACI_EXPORT))
            results.add(EXPORT);
        if (hasRights(rightsMask, ACI_IMPORT))
            results.add(IMPORT);
        if (hasRights(rightsMask, ACI_PROXY))
            results.add(PROXY);
        if (hasRights(rightsMask, ACI_SELF))
            results.add(SELFWRITE);
        return results;
    }
    /**
     * Checks if the provided rights mask has the specified rights.
     *
     * @param rightsMask
     *          The rights mask to look into.
     * @param rights
     *          The rights to check for.
     * @return true if the rights mask has the specified rights, false
     *           otherwise.
     */
    public static boolean hasRights(int rightsMask, int rights) {
        return (rightsMask & rights) == rights;
    }
}