Update of /var/cvs/src/org/mmbase/security
In directory james.mmbase.org:/tmp/cvs-serv26818

Modified Files:
        Action.java ActionRepository.java Authentication.java 
        MemoryActionRepository.java Rank.java 
Log Message:
associated 'namespace' with actions to make chance on conflicts smaller, and to 
have a natural relation to components


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/security


Index: Action.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/security/Action.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- Action.java 26 Jul 2007 22:04:23 -0000      1.4
+++ Action.java 21 Jan 2008 15:25:28 -0000      1.5
@@ -17,14 +17,17 @@
  * component XML's).
  *
  * @author Michiel Meeuwissen
- * @version $Id: Action.java,v 1.4 2007/07/26 22:04:23 michiel Exp $
+ * @version $Id: Action.java,v 1.5 2008/01/21 15:25:28 michiel Exp $
  * @since MMBase-1.9
  */
 public class Action implements java.io.Serializable {
     protected final String name;
     protected final LocalizedString description;
     protected final ActionChecker defaultChecker;
-    public Action(String n, ActionChecker c) {
+    protected final String nameSpace;
+
+    public Action(String ns, String n, ActionChecker c) {
+        nameSpace = ns;
         name = n;
         defaultChecker = c;
         description = new LocalizedString(name);
@@ -38,14 +41,27 @@
     public ActionChecker getDefault() {
         return defaultChecker;
     }
+    /**
+     * Every action has a non-null name. Together with the [EMAIL PROTECTED] 
#getNameSpace} it uniquely
+     * identifies the action.
+     */
     public String getName() {
         return name;
     }
+
+    /**
+     * Most 'actions' have a namespace. This is normally identical to thye 
name of the component
+     * with wich there are associated. It can be <code>null</code> though.
+     */
+    public String getNameSpace() {
+        return nameSpace;
+    }
+
     public LocalizedString getDescription() {
         return description;
     }
 
     public String toString() {
-        return name + ":" + defaultChecker;
+        return nameSpace + ":" + name + ":" + defaultChecker;
     }
 }


Index: ActionRepository.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/security/ActionRepository.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ActionRepository.java       26 Jul 2007 22:04:23 -0000      1.5
+++ ActionRepository.java       21 Jan 2008 15:25:28 -0000      1.6
@@ -11,13 +11,18 @@
 import java.util.*;
 
 /**
+ * The defined 'actions' are maintained by the 'action' repository. The 
security implementation can
+ * decide how to persistify actions and how to connect rights to it.
+ *
+ * @see [EMAIL PROTECTED] Action}.
  * @author Michiel Meeuwissen
- * @version $Id: ActionRepository.java,v 1.5 2007/07/26 22:04:23 michiel Exp $
+ * @version $Id: ActionRepository.java,v 1.6 2008/01/21 15:25:28 michiel Exp $
  * @since MMBase-1.9
  */
 public abstract class ActionRepository extends Configurable {
 
     protected static ActionRepository bootstrap = new MemoryActionRepository();
+
     public static final ActionRepository getInstance() {
         if (bootstrap != null) {
             return bootstrap;
@@ -28,7 +33,7 @@
 
     public abstract void add(Action a);
 
-    public abstract Action get(String name);
+    public abstract Action get(String nameSpace, String name);
 
     public abstract Collection<Action> getActions();
 }


Index: Authentication.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/security/Authentication.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- Authentication.java 10 Jan 2008 14:12:24 -0000      1.40
+++ Authentication.java 21 Jan 2008 15:25:28 -0000      1.41
@@ -24,7 +24,7 @@
  *
  * @author Eduard Witteveen
  * @author Michiel Meeuwissen (javadocs)
- * @version $Id: Authentication.java,v 1.40 2008/01/10 14:12:24 michiel Exp $
+ * @version $Id: Authentication.java,v 1.41 2008/01/21 15:25:28 michiel Exp $
  */
 public abstract class Authentication extends Configurable implements 
AuthenticationData {
     private static final Logger log = 
Logging.getLoggerInstance(Authentication.class);
@@ -63,7 +63,7 @@
      *
      * @return <code>null</code> if no valid credentials were supplied,  a 
(perhaps new) UserContext if login succeeded.
      *
-     * @exception SecurityException When something strange happend, or 
authentication was unsucessfull.
+     * @exception SecurityException When something strange happened, or 
authentication was unsucessfull.
      */
     public abstract UserContext login(String application, Map<String, Object> 
loginInfo, Object[] parameters) throws SecurityException;
 


Index: MemoryActionRepository.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/security/MemoryActionRepository.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- MemoryActionRepository.java 26 Jul 2007 22:04:23 -0000      1.5
+++ MemoryActionRepository.java 21 Jan 2008 15:25:28 -0000      1.6
@@ -14,14 +14,37 @@
 import org.mmbase.util.logging.Logging;
 
 /**
+ * This is the most simple way to store 'actions', namely simply in memory. 
Config files may fill
+ * this repository on startup.
+ *
  * @author Michiel Meeuwissen
- * @version $Id: MemoryActionRepository.java,v 1.5 2007/07/26 22:04:23 michiel 
Exp $
+ * @version $Id: MemoryActionRepository.java,v 1.6 2008/01/21 15:25:28 michiel 
Exp $
  * @since MMBase-1.9
  */
 public class MemoryActionRepository extends ActionRepository {
     private static final Logger log = 
Logging.getLoggerInstance(MMBaseCop.class);
 
-    private final Map<String, Action> store = new HashMap<String, Action>();
+    private static class Key  {
+        private final String nameSpace;
+        private final String name;
+        Key(String ns, String n) {
+            nameSpace = ns;
+            name = n;
+        }
+        public int hashCode() {
+            return name.hashCode();
+        }
+        public boolean equals(Object o) {
+            if (o instanceof Key) {
+                Key k = (Key) o;
+                return k.name.equals(name) && (k.nameSpace == null ? nameSpace 
== null : k.nameSpace.equals(nameSpace));
+            } else {
+                return false;
+            }
+        }
+    }
+
+    private final Map<Key, Action> store = new HashMap<Key, Action>();
 
     public MemoryActionRepository() {
     }
@@ -31,11 +54,11 @@
 
     public void add(Action a) {
         log.info("Adding " + a + " to " + this);
-        store.put(a.getName(), a);
+        store.put(new Key(a.getNameSpace(), a.getName()), a);
     }
 
-    public Action get(String name) {
-        return store.get(name);
+    public Action get(String nameSpace, String name) {
+        return store.get(new Key(nameSpace, name));
     }
     public Collection<Action> getActions() {
         return store.values();


Index: Rank.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/security/Rank.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- Rank.java   22 Sep 2006 13:12:18 -0000      1.17
+++ Rank.java   21 Jan 2008 15:25:28 -0000      1.18
@@ -26,7 +26,7 @@
  * @author Eduard Witteveen
  * @author Pierre van Rooden
  * @author Michiel Meeuwissen
- * @version $Id: Rank.java,v 1.17 2006/09/22 13:12:18 michiel Exp $
+ * @version $Id: Rank.java,v 1.18 2008/01/21 15:25:28 michiel Exp $
  */
 public final class Rank implements Comparable<Rank>, java.io.Serializable {
 
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to