| | |
| | | * |
| | | * |
| | | * 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. |
| | | */ |
| | |
| | | */ |
| | | ADDWRITE ("addwrite"); |
| | | |
| | | /* |
| | | /** |
| | | * The name of the right. |
| | | */ |
| | | private final String right; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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. |
| | |
| | | } |
| | | 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; |
| | | } |
| | | } |