User: norbert
Date: 00/05/22 10:33:47
Added: src/java/org/spyderMQ/security Identity.java
SecurityManager.java
Log:
package SecurityManager
Revision Changes Path
1.1 spyderMQ/src/java/org/spyderMQ/security/Identity.java
Index: Identity.java
===================================================================
/*
* spyderMQ, the OpenSource JMS implementation
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package org.spydermq.security;
/**
* This class stores informations about an identity (login)
*
* @author Norbert Lataille ([EMAIL PROTECTED])
*
* @version $Revision: 1.1 $
*/
public class Identity
{
String login;
String passwd;
String clientID;
Identity(String login,String passwd,String clientID)
{
this.login=login;
this.passwd=passwd;
this.clientID=clientID;
}
}
1.1 spyderMQ/src/java/org/spyderMQ/security/SecurityManager.java
Index: SecurityManager.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 SecurityManager
{
//Known users hashed by login
private Hashtable users;
//registered clientID
private HashSet clientID;
public SecurityManager()
{
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);
}
}