User: pra
Date: 02/03/06 09:27:51
Added: src/main/org/jboss/mq/sm AbstractStateManager.java
AbstractStateManagerMBean.java StateManager.java
Log:
Commit of JBossMQ new JAAS based security architecture
Revision Changes Path
1.1 jbossmq/src/main/org/jboss/mq/sm/AbstractStateManager.java
Index: AbstractStateManager.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mq.sm;
import java.util.Collection;
import java.util.Set;
import java.util.HashSet;
import javax.jms.JMSException;
import javax.jms.JMSSecurityException;
import javax.jms.InvalidClientIDException;
import org.jboss.mq.SpyTopic;
import org.jboss.mq.DurableSubscriptionID;
import org.jboss.mq.server.JMSServer;
import org.jboss.mq.server.JMSTopic;
import org.jboss.system.ServiceMBeanSupport;
/**
* An abstract baseclass to make it a little bit easier to implement
* new StateManagers.
*
* Apart from one methods in StateManager subclasses implement
* the protected abstract callback methods to do its work.
*
*
* @author <a href="[EMAIL PROTECTED]">Peter Antman</a>
* @author <a href="[EMAIL PROTECTED]">Norbert Lataille</a>
* @author <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
* @version $Revision: 1.1 $
*/
public abstract class AbstractStateManager
extends ServiceMBeanSupport
implements StateManager, AbstractStateManagerMBean {
/**
* Abstracts the data between a subclass and this class.
*
* A sublcass can extends this class to ad custom behaviour.
*/
protected class DurableSubscription {
String clientID;
String name;
String topic;
public DurableSubscription () {}
public DurableSubscription(String clientID, String name, String topic) {
this.clientID = clientID;
this.name = name;
this.topic = topic;
}
public String getClientID() {return clientID;}
public String getName() {return name;}
public String getTopic() {return topic;}
public void setTopic(String topic) { this.topic = topic;}
}
/**
* The currently loggen in clientID's
*/
private final Set loggedOnClientIds = new HashSet();
public AbstractStateManager() {
}
/**
* Set the durable subscriber.
*
* getDurableSubscription() will be called to get the durable sub.
*
* removeDurableSubscription() will be called to remove a dur sub.
*
* saveDurableSubscription() will be called to save a new dur sub or
* to save a changed one (same clientID and name, different topic).
*/
public void setDurableSubscription(JMSServer server, DurableSubscriptionID sub,
SpyTopic topic) throws JMSException {
boolean debug = log.isDebugEnabled();
if (debug)
log.debug("Checking durable subscription: " + sub + ", on topic: " + topic);
DurableSubscription subscription = getDurableSubscription(sub);
// A new subscription
if ( subscription== null) {
if (debug)
log.debug("The subscription was not previously registered.");
// Either this was a remove attemt, not to successfull,
// or it was a bogus request (should then an exception be raised?9
if (topic == null)
{
return;
}
// Create the real durable subscription
JMSTopic dest = (JMSTopic)server.getJMSDestination(topic);
dest.createDurableSubscription(sub);
// Save it
subscription = new DurableSubscription(sub.getClientID(),
sub.getSubscriptionName(),
topic.getName());
// Call subclass
saveDurableSubscription(subscription);
}
// An existing subscription...it was previously registered...
// Check if it is an unsubscribe, or a change of subscription.
else
{
if (debug)
log.debug("The subscription was previously registered.");
// The client wants an unsubscribe
// TODO: we are not spec compliant since we neither check if
// the topic has an active subscriber or if there are messages
// destined for the client not yet acked by the session!!!
if (topic == null)
{
if (debug)
log.debug("Removing subscription.");
// we have to change the subscription...do physical work
SpyTopic prevTopic = new SpyTopic(subscription.getTopic());
JMSTopic dest = (JMSTopic)server.getJMSDestination(prevTopic);
// TODO here we should check if the client still has
// an active consumer
dest.destroyDurableSubscription(sub);
//straight deletion, remove subscription - call subclass
removeDurableSubscription(subscription);
}
// The topic previously subscribed to is not the same as the
// one in the subscription request.
// TODO: we do currently no check if the selector has changed.
else if (!subscription.getTopic().equals(topic.getName()))
{
//new topic so we have to change it
if (debug)
log.debug("But the topic was different, changing the subscription.");
// remove the old sub
SpyTopic prevTopic = new SpyTopic(subscription.getTopic());
JMSTopic dest = (JMSTopic)server.getJMSDestination(prevTopic);
dest.destroyDurableSubscription(sub);
// Create the new
dest = (JMSTopic)server.getJMSDestination(topic);
dest.createDurableSubscription(sub);
//durable subscription has new topic, save.
subscription.setTopic(topic.getName());
saveDurableSubscription(subscription);
}
}
}
/**
* Get SpyTopic for the give DurableSubscriptionID. Will call
* getDurableSubscription() to get the subscription.
*/
public SpyTopic getDurableTopic(DurableSubscriptionID sub) throws JMSException {
DurableSubscription subscription = getDurableSubscription(sub);
if (subscription == null)
throw new JMSException("No durable subscription found for subscription: " +
sub.getSubscriptionName());
return new SpyTopic(subscription.getTopic());
}
/**
* Get a preconfiged clientID and possible do authentication.
*
* Subclass will be called by getPreconfClientId(), and may if it wants
* to do authentication.
*/
public String checkUser(String login, String passwd) throws JMSException {
String clientId = getPreconfClientId(login,passwd);
if (clientId != null)
{
synchronized (loggedOnClientIds)
{
if (loggedOnClientIds.contains(clientId))
{
throw new JMSSecurityException
("The login id has an assigned client id. " +
"That client id is already connected to the server!");
}
loggedOnClientIds.add(clientId);
}
}
return clientId;
}
/**
* This manager keeps the state of the logged in clientID.
*
* Before a clientID is added, the callback checkLoggedOnClientId() is
* called. A subclass can do its specific check there and throw
* an exception if it does not allow the clientID to loggin.
*/
public void addLoggedOnClientId(String ID) throws JMSException {
//Check : this ID must not be registered
synchronized (loggedOnClientIds)
{
if (loggedOnClientIds.contains(ID))
{
throw new InvalidClientIDException("This loggedOnClientIds is already
registered !");
}
}
checkLoggedOnClientId(ID);
synchronized (loggedOnClientIds)
{
loggedOnClientIds.add(ID);
}
}
/**
* Remove the clienID from the logged in ones.
*
* No callback is done. If sublaclass needs to do anything specific it must
* override this method.
*/
public void removeLoggedOnClientId(String ID) {
synchronized (loggedOnClientIds)
{
loggedOnClientIds.remove(ID);
}
}
//
// Abstract method sublclasses need to implement.
//
abstract public Collection getDurableSubscriptionIdsForTopic(SpyTopic topic)
throws JMSException;
/**
* Get preconfigured clientID for login/user, and if state manager wants
* do authentication. This is NOT recomended when using a SecurityManager.
*/
abstract protected String getPreconfClientId(String login,String passwd) throws
JMSException;
/**
* Check if the clientID is allowed to logg in from the particular state
* managers perspective.
*/
abstract protected void checkLoggedOnClientId(String clientID) throws
JMSException;
/**
* Get a DurableSubscription describer.
*
* If subscription is not found, return null. The get
*
*/
abstract protected DurableSubscription
getDurableSubscription(DurableSubscriptionID sub) throws JMSException;
/**
* Add to durable subs and save the subsrcription to persistent storage.
*
* Called by this class so the sublclass can save. This may be both
* a new subscription or a changed one. It is up to the sublcass
* to know how to find a changed on. (Only the topic will have changed,
* and it is the same DurableSubscription that is saved again that this
* class got through getDurableSubscription.
*
*
*/
abstract protected void saveDurableSubscription(DurableSubscription ds) throws
JMSException;
/**
* Remove the subscription and save to persistent storage.
*
* Called by this class so the sublclass can remove.
*/
abstract protected void removeDurableSubscription(DurableSubscription ds) throws
JMSException;
} // AbstractStateManager
1.1 jbossmq/src/main/org/jboss/mq/sm/AbstractStateManagerMBean.java
Index: AbstractStateManagerMBean.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mq.sm;
import org.jboss.system.ServiceMBean;
/**
* AbstractStateManagerMBean.java
*
* @author <a href="[EMAIL PROTECTED]">Peter Antman</a>
* @version $Revision: 1.1 $
*/
public interface AbstractStateManagerMBean
extends ServiceMBean
{
/**
* Get an instance if the StateManager (Singleton).
*/
StateManager getInstance();
} // AbstractStateManagerMBean
1.1 jbossmq/src/main/org/jboss/mq/sm/StateManager.java
Index: StateManager.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mq.sm;
import java.util.Collection;
import javax.jms.JMSException;
import org.jboss.mq.SpyTopic;
import org.jboss.mq.DurableSubscriptionID;
import org.jboss.mq.server.JMSServer;
/**
* Interface for StateManager.
*
* A StateManager is a manager that manages states that has to do with clients/
* users and durable subscription.
*
* A state manager most know how to persist information regarding durable
* subscriptions.
*
* It should also hold all current clientID's that are connected to the server.
*
* It may also support basic autentication, which is what the old
* default StateManager did.
*
* @author <a href="[EMAIL PROTECTED]">Peter Antman</a>
* @author <a href="[EMAIL PROTECTED]">Norbert Lataille</a>
* @author <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
* @version $Revision: 1.1 $
*/
public interface StateManager {
/**
* Ad, change or delete a durable subsciption.
*
* The contract is that the StateManager, must physically create the durable
* subscription. And when the method returns the information must be persisted.
*
*
* @param server The JMSServer
* @param sub The id of the durable subscription
* @param topic The topic to subscribe durable on, if null
* the subscription will be removed.
* @exception JMSException Description of Exception
*/
public void setDurableSubscription(JMSServer server, DurableSubscriptionID sub,
SpyTopic topic) throws JMSException;
/**
* Get the destination a subscription is for.
*/
public SpyTopic getDurableTopic(DurableSubscriptionID sub) throws JMSException;
/**
* Check if a user has a preconfigured clientID and return it.
*
* If the user has a preconfigured clienID it will be added to the current
* logged in clientID's and returned.
*
* The state manager may also use this method to authenticate a user.
* If a SecurityManager is installed this is not necesarry.
*
* @param login user name
* @param passwd password
* @return a preconfigured clientID.
* @exception JMSException if the user
* @exception JMSSecurityException if the clientID is already loged in.
*/
public String checkUser(String login, String passwd) throws JMSException;
/**
* Ad a logged in clientID to the statemanager.
*
* The clientID must not be active.
*
* The StateManager should somehow assure that a clientID that is
* preconfigured for a user is not allowed to be added this way.
*
* @param ID a clientID
* @exception JMSException Description of Exception
* @exception InvalidClientIDException if the clientID wass already logged in.
*/
public void addLoggedOnClientId(String ID) throws JMSException;
/**
* Remove the logged in clientID.
*
* @param ID clientID.
*/
public void removeLoggedOnClientId(String ID);
/**
* Get all configured durable subscriptions for a particular topic.
*
* @param topic the topic.
* @return a collection of DurableSubscriptionID
* @exception JMSException Description of Exception
*/
public Collection getDurableSubscriptionIdsForTopic(SpyTopic topic)
throws JMSException;
} // StateManager
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development