From cfbe67a8558d6a0bc28b6a3b8846f751ad76309a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 03 Jul 2013 11:03:06 +0000
Subject: [PATCH] First stab at having debuggable ACIs.
---
opendj-sdk/opends/src/server/org/opends/server/authorization/dseecompat/EnumRight.java | 66 ++++++++++++++++++++++++++++++++-
1 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/authorization/dseecompat/EnumRight.java b/opendj-sdk/opends/src/server/org/opends/server/authorization/dseecompat/EnumRight.java
index b7ec612..4b195a0 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/authorization/dseecompat/EnumRight.java
+++ b/opendj-sdk/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;
+ }
}
--
Gitblit v1.10.0