You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2004/09/10 17:07:03 UTC

svn commit: rev 43673 - in incubator/lenya/trunk/src/java/org/apache/lenya/ac: . file

Author: andreas
Date: Fri Sep 10 08:07:02 2004
New Revision: 43673

Added:
   incubator/lenya/trunk/src/java/org/apache/lenya/ac/UserType.java
      - copied unchanged from rev 43672, incubator/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/UserType.java
Modified:
   incubator/lenya/trunk/src/java/org/apache/lenya/ac/UserManager.java
   incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java
   incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java
Log:
merged BRANCH_1_2_X into trunk

Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/UserManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/UserManager.java	(original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/UserManager.java	Fri Sep 10 08:07:02 2004
@@ -19,7 +19,7 @@
 
 /**
  * User manager.
- * @version $Id: UserManager.java,v 1.3 2004/08/16 16:21:22 andreas Exp $
+ * @version $Id$
  */
 public interface UserManager extends ItemManager {
     
@@ -30,6 +30,13 @@
      */
     User[] getUsers();
     
+    /**
+     * Get all supported user types
+     *
+     * @return a collection of user types
+     */
+    UserType[] getUserTypes();
+
     /**
      * Add the given user
      *

Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java	(original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java	Fri Sep 10 08:07:02 2004
@@ -15,13 +15,19 @@
  *
  */
 
-/* $Id: FileAccreditableManager.java,v 1.5 2004/08/16 15:48:37 andreas Exp $  */
+/* $Id$  */
 
 package org.apache.lenya.ac.file;
 
 import java.io.File;
 import java.net.URI;
-
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.parameters.ParameterException;
 import org.apache.avalon.framework.parameters.Parameterizable;
 import org.apache.avalon.framework.parameters.Parameters;
@@ -35,13 +41,14 @@
 import org.apache.lenya.ac.IPRangeManager;
 import org.apache.lenya.ac.RoleManager;
 import org.apache.lenya.ac.UserManager;
+import org.apache.lenya.ac.UserType;
 import org.apache.lenya.ac.impl.AbstractAccreditableManager;
 
 /**
  * File-based accreditable manager.
  */
 public class FileAccreditableManager extends AbstractAccreditableManager implements Serviceable,
-        Parameterizable {
+        Configurable, Parameterizable {
 
     /**
      * Creates a new FileAccreditableManager. If you use this constructor, you have to set the
@@ -55,15 +62,29 @@
      * Creates a new FileAccessController based on a configuration directory.
      * 
      * @param configurationDirectory The configuration directory.
+     * @param userTypes The supported user types.
      */
-    public FileAccreditableManager(File configurationDirectory) {
+    public FileAccreditableManager(File configurationDirectory, UserType[] userTypes) {
         assert configurationDirectory != null;
         assert configurationDirectory.exists();
         assert configurationDirectory.isDirectory();
         this.configurationDirectory = configurationDirectory;
+        this.userTypes = new HashSet(Arrays.asList(userTypes));
     }
 
     private File configurationDirectory;
+    private Set userTypes;
+
+    /**
+     * Returns the supported user types.
+     * @return An array of user types.
+     * @throws AccessControlException if an error occurs.
+     */
+    public UserType[] getUserTypes() throws AccessControlException {
+        if (userTypes == null)
+            throw new AccessControlException("User types not initialized");
+        return (UserType[]) userTypes.toArray(new UserType[userTypes.size()]);
+    }
 
     /**
      * Returns the configuration directory.
@@ -120,6 +141,59 @@
         }
     }
 
+    protected static final String A_M_TAG = "accreditable-manager";
+    protected static final String U_M_CHILD_TAG = "user-manager";
+    protected static final String U_T_CHILD_TAG = "user-type";
+    protected static final String U_T_CLASS_ATTRIBUTE = "class";
+    protected static final String U_T_CREATE_ATTRIBUTE = "create-use-case";
+    // provided for backward compatibility
+    protected static final String DEFAULT_USER_TYPE_CLASS = FileUser.class.getName();
+    protected static final String DEFAULT_USER_TYPE_KEY = "Local User";
+    protected static final String DEFAULT_USER_CREATE_USE_CASE = "userAddUser";
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     *      added to read new user-manager block within accreditable-manager
+     */
+    public void configure(Configuration configuration) throws ConfigurationException {
+        // note:
+        // we need to distinguish the case where configure is called from
+        // somewhere else (i.e. not due to the reading of ac.xconf),
+        // from the case where the child user-manager does not exist,
+        // for instance when reading an old ac.xconf which does not yet
+        // have this configuration. So for backward compatibility, we need
+        // to distinguish the 2 cases
+        if (A_M_TAG.equals(configuration.getName())) {
+            userTypes = new HashSet();
+            Configuration umConf = configuration.getChild(U_M_CHILD_TAG, false);
+            if (umConf != null) {
+                Configuration[] typeConfs = umConf.getChildren();
+                for (int i = 0; i < typeConfs.length; i++) {
+                    userTypes.add(new UserType(typeConfs[i].getValue(), typeConfs[i]
+                            .getAttribute(U_T_CLASS_ATTRIBUTE), typeConfs[i]
+                            .getAttribute(U_T_CREATE_ATTRIBUTE)));
+                }
+            } else {
+                getLogger().debug(
+                        "FileAccreditableManager: using default configuration for user types");
+                // no "user-manager" block in access control: provide
+                // a default for backward compatibility
+                userTypes.add(getDefaultUserType());
+            }
+            // maybe todo (or is it overkill?) : validate the parametrized user
+            // types, for example, check if the classes are in the classpath ?
+        }
+    }
+
+    /**
+     * Returns the default user type.
+     * @return A user type.
+     */
+    public static UserType getDefaultUserType() {
+        return new UserType(DEFAULT_USER_TYPE_KEY, DEFAULT_USER_TYPE_CLASS,
+                DEFAULT_USER_CREATE_USE_CASE);
+    }
+
     private String configurationDirectoryPath;
 
     /**
@@ -183,7 +257,7 @@
      * @see org.apache.lenya.ac.impl.AbstractAccreditableManager#initializeUserManager()
      */
     protected UserManager initializeUserManager() throws AccessControlException {
-        return FileUserManager.instance(getConfigurationDirectory());
+        return FileUserManager.instance(getConfigurationDirectory(), getUserTypes());
     }
 
 }

Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java	(original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java	Fri Sep 10 08:07:02 2004
@@ -18,50 +18,60 @@
 package org.apache.lenya.ac.file;
 
 import java.io.File;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.Item;
 import org.apache.lenya.ac.User;
 import org.apache.lenya.ac.UserManager;
+import org.apache.lenya.ac.UserType;
 
 /**
  * File-based user manager implementation.
- * @version $Id: FileUserManager.java,v 1.4 2004/08/16 15:59:51 andreas Exp $
+ * @version $Id$
  */
 public class FileUserManager extends FileItemManager implements UserManager {
-    
+
     private static Map instances = new HashMap();
+    private Set userTypes;
 
     /**
      * Create a UserManager
-     *
+     * 
      * @param configurationDirectory for which the UserManager should be instanciated.
-     * @throws AccessControlException if the UserManager could not be
-     *         instantiated.
+     * @param userTypes The supported user types.
+     * @throws AccessControlException if the UserManager could not be instantiated.
      */
-    protected FileUserManager(File configurationDirectory) throws AccessControlException {
+    protected FileUserManager(File configurationDirectory, UserType[] userTypes)
+            throws AccessControlException {
         super(configurationDirectory);
+        this.userTypes = new HashSet(Arrays.asList(userTypes));
     }
 
     /**
      * Describe <code>instance</code> method here.
-     *
+     * 
      * @param configurationDirectory a directory
+     * @param userTypes The supported user types.
      * @return an <code>UserManager</code> value
      * @exception AccessControlException if an error occurs
      */
-    public static FileUserManager instance(File configurationDirectory) throws AccessControlException {
+    public static FileUserManager instance(File configurationDirectory, UserType[] userTypes)
+            throws AccessControlException {
 
         assert configurationDirectory != null;
         if (!configurationDirectory.isDirectory()) {
-            throw new AccessControlException(
-                "Configuration directory [" + configurationDirectory + "] does not exist!");
+            throw new AccessControlException("Configuration directory [" + configurationDirectory
+                    + "] does not exist!");
         }
 
         if (!instances.containsKey(configurationDirectory)) {
-            instances.put(configurationDirectory, new FileUserManager(configurationDirectory));
+            instances.put(configurationDirectory, new FileUserManager(configurationDirectory,
+                    userTypes));
         }
 
         return (FileUserManager) instances.get(configurationDirectory);
@@ -69,7 +79,7 @@
 
     /**
      * Get all users.
-     *
+     * 
      * @return an Iterator to iterate over all users
      */
     public User[] getUsers() {
@@ -97,15 +107,21 @@
 
     /**
      * Get the user with the given user id.
-     *
+     * 
      * @param userId user id of requested user
-     * @return the requested user or null if there is
-     * no user with the given user id
+     * @return the requested user or null if there is no user with the given user id
      */
     public User getUser(String userId) {
         return (User) getItem(userId);
     }
 
+    /**
+     * @see org.apache.lenya.ac.UserManager#getUserTypes()
+     */
+    public UserType[] getUserTypes() {
+        return (UserType[]) userTypes.toArray(new UserType[userTypes.size()]);
+    }
+
     protected static final String SUFFIX = ".iml";
 
     /**
@@ -114,5 +130,5 @@
     protected String getSuffix() {
         return SUFFIX;
     }
-    
-}
+
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org