User: hiram   
  Date: 00/12/25 20:16:00

  Added:       src/java/org/spydermq/security UserManager.java
  Removed:     src/java/org/spydermq/security SecurityManager.java
  Log:
  Fix a syschronization problem with the UIL and OIL classes.  Now the
  ASF can handle multiple messages without a problem.  Removed all dependencys
  the client had on the SecurityManger.
  
  Revision  Changes    Path
  1.1                  spyderMQ/src/java/org/spydermq/security/UserManager.java
  
  Index: UserManager.java
  ===================================================================
  /*
   * spyderMQ, the OpenSource JMS implementation
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.spydermq.security;
  
  import java.util.Hashtable;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Collection;
  
  import javax.jms.JMSException;
  
  /**
   * This class is a simple Security Manager. It handles credential issues.
   *      
   *    @author Norbert Lataille ([EMAIL PROTECTED])
   * 
   *    @version $Revision: 1.1 $
   */
  public class UserManager
  {
        //Known users hashed by login
        private Hashtable users;
        //registered clientID 
        private HashSet clientID;
                
        public UserManager() 
        {
                users=new Hashtable();
                clientID=new HashSet();
        }
        
        public void addUser(String login,String passwd,String clientID)
        {
                users.put(login,new Identity(login,passwd,clientID));
        }
        
        public String checkUser(String login,String passwd) throws JMSException
        {
                Identity user=(Identity)users.get(login);               
                if (user==null) throw new JMSException("This user does not exist");    
         
                if (!passwd.equals(user.passwd)) throw new JMSException("Bad 
password");
                
                if (user.clientID!=null) {
                        if (clientID.contains(user.clientID)) throw new 
JMSException("This clientID is already registered !");
                        clientID.add(user.clientID);
                }
                
                return user.clientID;
        }
        
        public void check(String login,String passwd,String clientID)
        {               
                synchronized (users) {
                        users.put(login,new Identity(login,passwd,clientID));
                }
        }
        
        public void addClientID(String ID) throws JMSException
        {
                                
                //Check : this ID must not be registered
                if (clientID.contains(ID)) throw new JMSException("This clientID is 
already registered !");
  
                //Check : this ID must not be password protected
                synchronized (users) {
                        Iterator i=users.values().iterator();
                        if (i!=null) {
                                while (i.hasNext()) {
                                        Identity id=(Identity)i.next();
                                        if (id.clientID!=null)
                                                if (id.clientID.equals(ID))
                                                        throw new JMSException("This 
clientID is password protected !");
                                }
                        }
                }
                
                clientID.add(ID);
        }
        
        public void removeID(String ID)
        {
                clientID.remove(ID);
        }
        
  }
  
  
  

Reply via email to