[cvs] expresso commit by rimovm: Map Based User Info implementation

JCorporate Ltd jcorp at jcorp2.servlets.net
Thu Nov 4 02:35:01 PST 2004


Log Message:
-----------
Map Based User Info implementation

Added Files:
-----------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/security:
        MapBasedUserInfo.java

Revision Data
-------------
--- /dev/null
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/security/MapBasedUserInfo.java
@@ -0,0 +1,575 @@
+package com.jcorporate.expresso.core.security;
+
+import java.util.*;
+import com.jcorporate.expresso.core.db.DBException;
+import com.jcorporate.expresso.core.misc.ConfigManager;
+
+/**
+ * A User Info implementation that is Map based instead of database object
+ * based.  Although this isn't usually used in Expresso, a few cases, where
+ * we need a SuperUser, for example when database access doesn't exist.  It is
+ * not considered something to use on a broad basis, more as a workaround
+ * for some special startup conditions.
+ * @author Michael Rimov
+ * @version $Revision: 1.1 $ on $Date: 2004/11/04 10:35:01 $
+ */
+public class MapBasedUserInfo
+    implements UserInfo
+{
+    /**
+     * Map of a map of user info objects.
+     */
+    private static Map dataContexts;
+
+
+    /**
+     * Current data context.
+     */
+    private String dataContext;
+
+    private String email;
+
+    private String emailAuthCode;
+
+    private String emailValCode;
+
+    private String accountStatus;
+
+    private String createDate;
+
+    private String loginName;
+
+    private String password;
+
+    private String primaryGroup;
+
+    private boolean regComplete;
+
+    private String registrationDomain;
+
+    private int uid;
+
+    private String updateDate;
+
+    static {
+        synchronized (MapBasedUserInfo.class) {
+            dataContexts = new HashMap();
+            for (Enumeration e = ConfigManager.getAllConfigKeys();
+                                 e.hasMoreElements();) {
+                String contextName = (String)e.nextElement();
+                dataContexts.put(contextName, new HashMap());
+            }
+        }
+    }
+
+    /**
+     * Default constructor.
+     */
+    public MapBasedUserInfo()
+    {
+    }
+
+    /**
+     *
+     * @throws DBException If the add fails
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void add()
+        throws DBException
+    {
+        synchronized(MapBasedUserInfo.class) {
+           Map contextMap = (Map)dataContexts.get(this.getDataContext());
+           contextMap.put(new Integer(this.getUid()), this);
+        }
+    }
+
+    /**
+     *
+     * @throws DBException If the delete fails
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void delete()
+        throws DBException
+    {
+        synchronized(MapBasedUserInfo.class) {
+           Map contextMap = (Map)dataContexts.get(this.getDataContext());
+           contextMap.remove(new Integer(this.getUid()));
+        }
+    }
+
+    /**
+     *
+     * @throws DBException If the find fails
+     * @return true if the user is found
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized boolean find()
+        throws DBException
+    {
+        return false;
+    }
+
+    /**
+     * Retrieve the current account status.
+     *
+     * @throws DBException If the find fails
+     * @return java.lang.String
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getAccountStatus()
+        throws DBException
+    {
+        return accountStatus;
+    }
+
+    /**
+     * Unsupported operation
+     * @return java.util.Vector
+     * @throws DBException If there is an error during the retrieval
+     * @throws java.lang.UnsupportedOperationException
+     */
+    public Vector getAllUsers()
+        throws DBException
+    {
+        throw new java.lang.UnsupportedOperationException("Not Supported");
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getCreateDate()
+        throws DBException
+    {
+        return createDate;
+    }
+
+    /**
+     *
+     * @return String
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getDBName()
+    {
+        if (dataContext == null) {
+            return "default";
+        }
+        return dataContext;
+    }
+
+    /**
+     *
+     * @return String
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getDataContext()
+    {
+        if (dataContext == null) {
+            return "default";
+        }
+        return dataContext;
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getEmail()
+        throws DBException
+    {
+        return email;
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getEmailAuthCode()
+        throws DBException
+    {
+        return emailAuthCode;
+    }
+
+    /**
+     *
+     * @throws DBException If the find fails
+     * @return java.lang.String
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getEmailValCode()
+        throws DBException
+    {
+        return emailValCode;
+    }
+
+    /**
+     * Not Implemented
+     * @deprecated Use the direct getLoginName, getEmail, getPassword, etc.
+     *
+     * @param fieldName The field to retrieve
+     * @return Vector Group names that this user belongs to
+     * @throws DBException If an error occurs when the group info is read
+     * @throws java.lang.UnsupportedOperationException This is not Implemented
+     */
+    public String getField(String fieldName)
+        throws DBException
+    {
+        throw new java.lang.UnsupportedOperationException("Not Supported");
+    }
+
+    /**
+     * Currently unsupported.  Returns a blank Vector
+     * @return Vector Group names that this user belongs to
+     * @throws DBException If an error occurs when the group info is read
+     */
+    public Vector getGroups()
+        throws DBException
+    {
+        return new Vector();
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getLoginName()
+        throws DBException
+    {
+        return loginName; }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getPassword()
+        throws DBException
+    {
+        return password;
+    }
+
+    /**
+     *
+     * @return name of the primary group of this user; null if no group is
+     *   found
+     * @throws DBException
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getPrimaryGroup()
+        throws DBException
+    {
+        return primaryGroup;
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized boolean getRegComplete()
+        throws DBException
+    {
+        return regComplete;
+    }
+
+    /**
+     *
+     * @throws DBException If the underlying User implementation throws the
+     *   same
+     * @return java.lang.String
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getRegistrationDomain()
+        throws DBException
+    {
+        return registrationDomain;
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized int getUid()
+        throws DBException
+    {
+        return uid;
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getUpdateDate()
+        throws DBException
+    {
+        return updateDate;
+    }
+
+    /**
+     *
+     * @return java.lang.String
+     * @throws DBException If there is an error during the retrieval
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized String getUserName()
+        throws DBException
+    {
+        return loginName;
+    }
+
+    /**
+     * Unsupported Operation
+     * @throws DBException
+     * @return A ValidValue vector describing what can be looked up.
+     * @throws java.lang.UnsupportedOperationException
+     */
+    public Vector getValues()
+        throws DBException
+    {
+        return null;
+    }
+
+    /**
+     * Checks if the given password equals what we have on file.
+     *
+     * @param testPassword The string to test if it's a correct password
+     * @return true if the testPassword equals the password on file.
+     * @throws DBException If an error occurs when the group info is read
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized boolean passwordEquals(String testPassword)
+        throws DBException
+    {
+        if (password == null) {
+            if (testPassword == null) {
+                return true;
+            } else {
+                return true;
+            }
+        }
+        return password.equals(testPassword);
+    }
+
+    /**
+     *
+     * @throws DBException If the retrieve fails
+     */
+    public synchronized void retrieve()
+        throws DBException
+    {
+        MapBasedUserInfo returnValue = null;
+        synchronized(MapBasedUserInfo.class) {
+           Map contextMap = (Map)dataContexts.get(this.getDataContext());
+           returnValue = (MapBasedUserInfo)contextMap.get(new Integer(this.getUid()));
+        }
+
+        if (returnValue == null) {
+            throw new DBException("Unable to locate uid: " + this.getUid());
+        }
+
+        this.setEmail(returnValue.getEmail());
+        this.setAccountStatus(returnValue.getAccountStatus());
+        this.setEmailValCode(this.getEmailValCode());
+        this.setLoginName(this.getLoginName());
+        this.setPassword(this.getPassword());
+        this.setRegComplete(this.getRegComplete());
+        this.setRegistrationDomain(this.getRegistrationDomain());
+    }
+
+    /**
+     * Not Implemented
+     * @throws DBException
+     * @throws UnsupportedOperationException
+     */
+    public void sendAuthEmail()
+        throws DBException
+    {
+        throw new java.lang.UnsupportedOperationException("Not supported");
+    }
+
+    /**
+     * Not Implemented
+     * @throws DBException
+     * @throws UnsupportedOperationException
+     */
+    public void sendFollowUpEmail()
+        throws DBException
+    {
+        throw new java.lang.UnsupportedOperationException("Not supported");
+    }
+
+    /**
+     *
+     * @param accountStatus java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setAccountStatus(String accountStatus)
+        throws DBException
+    {
+        this.accountStatus = accountStatus;
+    }
+
+    /**
+     *
+     * @param newDBName java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setDBName(String newDBName)
+        throws DBException
+    {
+        dataContext = newDBName;
+    }
+
+    /**
+     *
+     * @param email java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setEmail(String email)
+        throws DBException
+    {
+        this.email = email;
+    }
+
+    /**
+     * Sets the code required for auth.
+     *
+     * @param code java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setEmailValCode(String code)
+        throws DBException
+    {
+        this.emailValCode = code;
+    }
+
+    /**
+     *
+     * @param loginName java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setLoginName(String loginName)
+        throws DBException
+    {
+        this.loginName = loginName;
+    }
+
+    /**
+     *
+     * @param password java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setPassword(String password)
+        throws DBException
+    {
+        this.password = password;
+    }
+
+    /**
+     *
+     * @param status java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setRegComplete(boolean status)
+        throws DBException
+    {
+        this.regComplete = status;
+    }
+
+    /**
+     *
+     * @param id java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setRegistrationDomain(String id)
+        throws DBException
+    {
+        this.registrationDomain = id;
+    }
+
+    /**
+     *
+     * @param uid The uid of the user
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setUid(int uid)
+        throws DBException
+    {
+        this.uid = uid;
+    }
+
+    /**
+     *
+     * @param name java.lang.String
+     * @throws DBException If there is an error
+     * @todo Implement this com.jcorporate.expresso.core.security.UserInfo
+     *   method
+     */
+    public synchronized void setUserName(String name)
+        throws DBException
+    {
+        this.loginName = name;
+    }
+
+    /**
+     * There should be no copying and detaching from the datasource.  This
+     * does nothing.
+     * @throws DBException If the add fails
+     */
+    public void update()
+        throws DBException
+    {
+        return;
+    }
+}


More information about the cvs mailing list