User: pra     
  Date: 02/03/06 09:27:48

  Modified:    src/main/org/jboss/mq Connection.java ConnectionToken.java
                        SpyConnection.java SpySession.java
                        SpyXAConnection.java
  Log:
  Commit of JBossMQ new JAAS based security architecture
  
  Revision  Changes    Path
  1.17      +300 -161  jbossmq/src/main/org/jboss/mq/Connection.java
  
  Index: Connection.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/Connection.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Connection.java   2 Feb 2002 04:02:22 -0000       1.16
  +++ Connection.java   6 Mar 2002 17:27:48 -0000       1.17
  @@ -1,5 +1,5 @@
   /*
  - * JBoss, the OpenSource J2EE webOS
  + * JBos, the OpenSource J2EE webOS
    *
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
  @@ -23,6 +23,7 @@
   import javax.jms.Destination;
   import javax.jms.ExceptionListener;
   import javax.jms.JMSException;
  +import javax.jms.JMSSecurityException;
   import javax.jms.Queue;
   import javax.jms.Topic;
   
  @@ -32,11 +33,48 @@
   import org.jboss.mq.il.ServerIL;
   
   /**
  - * This class implements javax.jms.Connection
  + * <p>This class implements javax.jms.Connection.
  + * </p>
  + *
  + * <p>It is also the gateway through wich all calls to the JMS server is done. To
  + * do its work it needs a ServerIL to invoke (@see org.jboss.mq.server.ServerIL).
  + *</p>
  + *
  + * <p>The (new from february 2002) logic for clientID is the following:
  + * if logging in with a user and passwork a preconfigured clientID may be 
automatically delivered from the server.
  + * </p>
  + *
  + * <p>If the client wants to set it's own clientID it must do so on a connection
  + * wich does not have a prefonfigured clientID and it must do so before it
  + * calls any other methods on the connection (even getClientID()). It is not
  + * allowable to use a clientID that either looks like JBossMQ internal one 
  + * (beginning with ID) or a clientID that is allready in use by someone, or
  + * a clientID that is already preconfigured in the server.
  + *</p>
  + *
  + * <p>If a preconfigured ID is not get, or a valid one is not set, the server will
  + * set an internal ID. This ID is NEVER possible to use for durable subscriptions.
  + * If a prefconfigured ID or one manually set is possible to use to create a 
  + * durable subscriptions is governed by the security configuration of JBossMQ.
  + * In the default setup, only preconfigured clientID's are possible to use. 
  + * If using a SecurityManager, permissions to create a surable subscriptions is * 
the resiult of a combination of the following:
  + *</p>
  + * <p>- The clientID is not one of JBossMQ's internal.
  + *</p>
  + * <p>- The user is authenticated and has a role that has create set to true in
  + * the security config of the destination.
  + *</p>
  + *
  + * <p>Notes for JBossMQ developers:
  + * All calls, except close(), that is possible to do on a connection must call
  + * checkClientID()
  + * </p>
  + * 
    *
    * @author    Norbert Lataille ([EMAIL PROTECTED])
    * @author    Hiram Chirino ([EMAIL PROTECTED])
  - * @version   $Revision: 1.16 $
  + * @author     <a href="[EMAIL PROTECTED]">Peter Antman</a>
  + * @version   $Revision: 1.17 $
    * @created   August 16, 2001
    */
   public class Connection implements java.io.Serializable, javax.jms.Connection
  @@ -113,6 +151,11 @@
       * Set a soon as close() is called on the connection.
       */
      protected volatile boolean closing = false;
  +
  +   /**
  +    * 
  +    */
  +   private volatile boolean setClientIdAllowed = true;
      
      //LinkedList of all created sessions by this connection
      HashSet createdSessions;
  @@ -134,6 +177,8 @@
      //Get a new messageID (creation of a new message)
      private StringBuffer sb = new StringBuffer();
      private char[] charStack = new char[22];
  +
  +   String sessionId;
      
      /**
       * Static class initializer..
  @@ -184,14 +229,12 @@
         }
   
         // Authenticate with the server
  +      authenticate(userName, password);
  +
         if (userName != null)
         {
            askForAnID(userName, password);
         }
  -      if (clientID == null)
  -      {
  -         askForAnID();
  -      }
   
         // Setup the ClientIL service so that the Server can
         // push messages to us
  @@ -203,9 +246,11 @@
         spyXAResourceManager = new SpyXAResourceManager(this);
         
         // Used to monitor the connection.
  +      
         startPingThread();
         if( trace )
            log.trace("Connection establishment successful");
  +      
      }
   
      //////////////////////////////////////////////////////////////
  @@ -217,12 +262,18 @@
      {
         this(null, null, genericConnectionFactory);
      }
  +
  +   //////////////////////////////////////////////////////////////
  +   // Implementation of javax.jms.Connection
  +   //////////////////////////////////////////////////////////////
      
  +
      /**
  -    * Sets the ClientID attribute of the Connection object
  +    * Sets the ClientID attribute of the Connection object.
       *
       * @param cID               The new ClientID value
       * @exception JMSException  Description of Exception
  +    * @see javax.jms.Connection
       */
      public void setClientID(String cID)
         throws JMSException
  @@ -235,6 +286,9 @@
         {
            throw new IllegalStateException("The connection has already a clientID");
         }
  +      if (setClientIdAllowed == false) {
  +         throw new IllegalStateException("SetClientID was not called emediately 
after creation of connection");
  +      }
         if( log.isTraceEnabled() )
            log.trace("SetClientID(" + clientID + ")");
   
  @@ -252,78 +306,213 @@
         }
         
         clientID = cID;
  +      connectionToken.setClientID(clientID);
  +
  +   }
  +
  +   /**
  +    * Gets the ClientID attribute of the Connection object
  +    *
  +    * @return                  The ClientID value
  +    * @exception JMSException  Description of Exception
  +    * @see javax.jms.Connection
  +    */
  +   public String getClientID()
  +      throws JMSException
  +   {
  +      if (closed)
  +      {
  +         throw new IllegalStateException("The connection is closed");
  +      }
  +      checkClientID();
  +      return clientID;
      }
      
      /**
  +    * Gets the ExceptionListener attribute of the Connection object
  +    *
  +    * @return                  The ExceptionListener value
  +    * @exception JMSException  Description of Exception
  +    * @see javax.jms.Connection
  +    */
  +   public ExceptionListener getExceptionListener()
  +      throws JMSException
  +   {
  +      if (closed)
  +      {
  +         throw new IllegalStateException("The connection is closed");
  +      }
  +      checkClientID();
  +      return exceptionListener;
  +   }
  +   /**
       * Sets the ExceptionListener attribute of the Connection object
       *
       * @param listener          The new ExceptionListener value
       * @exception JMSException  Description of Exception
       */
      public void setExceptionListener(ExceptionListener listener)
  -   throws JMSException
  +      throws JMSException
      {
         if (closed)
         {
            throw new IllegalStateException("The connection is closed");
         }
  -      
  +      checkClientID();
         exceptionListener = listener;
      }
  -   
  -   //////////////////////////////////////////////////////////////
  -   // Public Methods
  -   //////////////////////////////////////////////////////////////
  -   
  +
  +      
      /**
  -    * Gets the ClientID attribute of the Connection object
  +    * Gets the MetaData attribute of the Connection object
       *
  -    * @return                  The ClientID value
  +    * @return                  The MetaData value
       * @exception JMSException  Description of Exception
  +    * @see javax.jms.Connection
       */
  -   public String getClientID()
  +   public ConnectionMetaData getMetaData()
      throws JMSException
      {
         if (closed)
         {
            throw new IllegalStateException("The connection is closed");
         }
  -      return clientID;
  +      checkClientID();
  +      return new SpyConnectionMetaData();
      }
  -   
  +
      /**
  -    * Gets the ExceptionListener attribute of the Connection object
  +    * Close the connection.
       *
  -    * @return                  The ExceptionListener value
       * @exception JMSException  Description of Exception
  +    * @see javax.jms.Connection
       */
  -   public ExceptionListener getExceptionListener()
  +   
  +   public synchronized void close()
      throws JMSException
      {
         if (closed)
         {
  +         return;
  +      }
  +      // We do not check clientID on close(), not much worth...
  +      boolean trace = log.isTraceEnabled();
  +      if( trace )
  +         log.trace("Closing sessions, ClientID=" + connectionToken.getClientID());
  +      closing = true;
  +
  +      //notify his sessions
  +      synchronized (createdSessions)
  +      {
  +         
  +         Object[] vect = createdSessions.toArray();
  +         for (int i = 0; i < vect.length; i++)
  +         {
  +            ((SpySession)vect[i]).close();
  +         }
  +         
  +      }
  +      if( trace )
  +      {
  +         log.trace("Closed sessions");
  +         log.debug("Notifiying the server of close");
  +      }
  +
  +      //Notify the JMSServer that I am closing
  +      try
  +      {
  +         serverIL.connectionClosing(connectionToken);
  +      }
  +      catch (Exception e)
  +      {
  +         throw new SpyJMSException("Cannot close properly the connection", e);
  +      }
  +      
  +      // Clean up after the ping thread..
  +      stopPingThread();
  +      
  +      if( trace )
  +         log.trace("Stoping the ClientIL service");
  +      stopILService();
  +      if( trace )
  +         log.trace("Disconnected from server");
  +
  +      // Only set the closed flag after all the objects that depend
  +      // on this connection have been closed.
  +      closed = true;
  +   }
  +   
  +   /**
  +    * Start async message delivery.
  +    *
  +    * @exception JMSException  Description of Exception
  +    * @see javax.jms.Connection
  +    */
  +   public void start()
  +      throws JMSException
  +   {
  +      if (closed)
  +      {
            throw new IllegalStateException("The connection is closed");
         }
  +      checkClientID();
  +      if (!modeStop)
  +      {
  +         return;
  +      }
  +      modeStop = false;
  +
  +      if( log.isTraceEnabled() )
  +         log.trace("Starting connection, ClientID=" + 
connectionToken.getClientID());
         
  -      return exceptionListener;
  +      try
  +      {
  +         serverIL.setEnabled(connectionToken, true);
  +      }
  +      catch (Exception e)
  +      {
  +         throw new SpyJMSException("Cannot enable the connection with the JMS 
server", e);
  +      }
      }
      
      /**
  -    * Gets the MetaData attribute of the Connection object
  +    * Stop delivery of message.
       *
  -    * @return                  The MetaData value
       * @exception JMSException  Description of Exception
  +    * @see javax.jms.Connection
       */
  -   public ConnectionMetaData getMetaData()
  -   throws JMSException
  +   public void stop()
  +      throws JMSException
      {
         if (closed)
         {
            throw new IllegalStateException("The connection is closed");
         }
  +      checkClientID();
  +      if (modeStop)
  +      {
  +         return;
  +      }
  +      modeStop = true;
  +      if( log.isTraceEnabled() )
  +         log.trace("Stoping connection, ClientID=" + connectionToken.getClientID());
         
  -      return new SpyConnectionMetaData();
  +      try
  +      {
  +         serverIL.setEnabled(connectionToken, false);
  +      }
  +      catch (Exception e)
  +      {
  +         throw new SpyJMSException("Cannot disable the connection with the JMS 
server", e);
  +      }
      }
  +
  +   //////////////////////////////////////////////////////////////
  +   // Public Methods
  +   //////////////////////////////////////////////////////////////
  +   
  +
  +
      
      /**
       * Gets the ServerIL attribute of the Connection object
  @@ -437,63 +626,7 @@
         ponged = true;
      }
   
  -   /**
  -    * #Description of the Method
  -    *
  -    * @exception JMSException  Description of Exception
  -    */
  -   public synchronized void close()
  -   throws JMSException
  -   {
  -      if (closed)
  -      {
  -         return;
  -      }
  -      boolean trace = log.isTraceEnabled();
  -      if( trace )
  -         log.trace("Closing sessions, ClientID=" + connectionToken.getClientID());
  -      closing = true;
   
  -      //notify his sessions
  -      synchronized (createdSessions)
  -      {
  -         
  -         Object[] vect = createdSessions.toArray();
  -         for (int i = 0; i < vect.length; i++)
  -         {
  -            ((SpySession)vect[i]).close();
  -         }
  -         
  -      }
  -      if( trace )
  -      {
  -         log.trace("Closed sessions");
  -         log.debug("Notifiying the server of close");
  -      }
  -
  -      //Notify the JMSServer that I am closing
  -      try
  -      {
  -         serverIL.connectionClosing(connectionToken);
  -      }
  -      catch (Exception e)
  -      {
  -         throw new SpyJMSException("Cannot close properly the connection", e);
  -      }
  -      
  -      // Clean up after the ping thread..
  -      stopPingThread();
  -      
  -      if( trace )
  -         log.trace("Stoping the ClientIL service");
  -      stopILService();
  -      if( trace )
  -         log.trace("Disconnected from server");
  -
  -      // Only set the closed flag after all the objects that depend
  -      // on this connection have been closed.
  -      closed = true;
  -   }
      
      //called by a TemporaryDestination which is going to be deleted()
      /**
  @@ -546,65 +679,32 @@
      }
      
      /**
  -    * #Description of the Method
  +    * Check that a clientID exists. If not get one from server.
       *
  -    * @exception JMSException  Description of Exception
  -    */
  -   public void start()
  -      throws JMSException
  -   {
  -      if (closed)
  -      {
  -         throw new IllegalStateException("The connection is closed");
  -      }
  -      
  -      if (!modeStop)
  -      {
  -         return;
  -      }
  -      modeStop = false;
  -
  -      if( log.isTraceEnabled() )
  -         log.trace("Starting connection, ClientID=" + 
connectionToken.getClientID());
  -      
  -      try
  -      {
  -         serverIL.setEnabled(connectionToken, true);
  -      }
  -      catch (Exception e)
  -      {
  -         throw new SpyJMSException("Cannot enable the connection with the JMS 
server", e);
  -      }
  -   }
  -   
  -   /**
  -    * #Description of the Method
  +    * Also sets the setClientIdAllowed to false.
       *
  -    * @exception JMSException  Description of Exception
  -    */
  -   public void stop()
  -      throws JMSException
  -   {
  -      if (closed)
  -      {
  -         throw new IllegalStateException("The connection is closed");
  -      }
  -      
  -      if (modeStop)
  -      {
  -         return;
  -      }
  -      modeStop = true;
  -      if( log.isTraceEnabled() )
  -         log.trace("Stoping connection, ClientID=" + connectionToken.getClientID());
  +    * Check clientId, must be called by all public methods on the
  +    * jacax.jmx.Connection interface and its children.
  +    * @exception JMSException  if clientID is null as post condition
  +    */
  +   synchronized 
  +   protected void  checkClientID() 
  +      throws JMSException{
  +      if (setClientIdAllowed == false)
  +         return;//No need to do anything
         
  -      try
  -      {
  -         serverIL.setEnabled(connectionToken, false);
  -      }
  -      catch (Exception e)
  -      {
  -         throw new SpyJMSException("Cannot disable the connection with the JMS 
server", e);
  +      boolean trace = log.isTraceEnabled();
  +      setClientIdAllowed = false;
  +      if (trace)
  +         log.trace("Checking clientID :" + clientID);
  +      if (clientID == null) {
  +         askForAnID();//Request a random one
  +         if (clientID == null)
  +            throw new JMSException("Could not get a clientID");
  +         connectionToken.setClientID(clientID);
  +         
  +         if (trace)
  +            log.trace("Connection establishment successful");
         }
      }
      
  @@ -648,6 +748,23 @@
            throw new SpyJMSException("Cannot get a client ID", e);
         }
      }
  +
  +      protected void authenticate(String userName, String password)
  +   throws JMSException
  +   {
  +      try
  +      {
  +         log.trace("Authenticating user " + userName);
  +         sessionId = serverIL.authenticate(userName, password);
  +      }
  +      catch(JMSException ex) {
  +         throw ex;
  +      }
  +      catch (Exception e)
  +      {
  +         throw new SpyJMSException("Cannot authenticate user", e);
  +      }
  +   }
      
      // used to acknowledge a message
      /**
  @@ -717,7 +834,7 @@
            
            clientILService = genericConnectionFactory.createClientILService(this);
            clientILService.start();
  -         connectionToken = new ConnectionToken(clientID, 
clientILService.getClientIL());
  +         connectionToken = new ConnectionToken(clientID, 
clientILService.getClientIL(), sessionId);
            serverIL.setConnectionToken(connectionToken);
            
         }
  @@ -807,6 +924,8 @@
      }
      
      //A new Consumer has been created for the Destination dest
  +   // We have to handle security issues, a consumer may actually not be allowed
  +   // to be created
      void addConsumer(SpyConsumer consumer)
         throws JMSException
      {
  @@ -842,12 +961,20 @@
            serverIL.subscribe(connectionToken, req);
            
         }
  +      catch(JMSSecurityException ex) {
  +         removeConsumerInternal(req);
  +         throw ex;
  +      }
  +      catch(JMSException ex) {
  +         throw ex;
  +      }
         catch (Exception e)
         {
            throw new SpyJMSException("Cannot subscribe to this Destination: " + 
e.getMessage(), e);
         }
         
      }
  +
      
      /**
       * @param queue             Description of Parameter
  @@ -867,6 +994,9 @@
         {
            return serverIL.browse(connectionToken, queue, selector);
         }
  +      catch(JMSException ex) {
  +         throw ex;
  +      }
         catch (Exception e)
         {
            throw new SpyJMSException("Cannot browse the Queue", e);
  @@ -919,13 +1049,16 @@
            }
            return message;
         }
  +      catch(JMSException ex) {
  +         throw ex;
  +      }
         catch (Exception e)
         {
            throw new SpyJMSException("Cannot create a ConnectionReceiver", e);
         }
      }
      
  -   //A consumer does not need to recieve the messages from a Destination
  +   //A consumer does not need to receieve the messages from a Destination
      void removeConsumer(SpyConsumer consumer)
      throws JMSException
      {
  @@ -942,23 +1075,8 @@
         {
            
            serverIL.unsubscribe(connectionToken, req.subscriptionId);
  -         
  -         synchronized (subscriptions)
  -         {
  -            
  -            subscriptions.remove(new Integer(req.subscriptionId));
  -            
  -            LinkedList ll = 
(LinkedList)destinationSubscriptions.get(req.destination);
  -            if (ll != null)
  -            {
  -               ll.remove(req);
  -               if (ll.size() == 0)
  -               {
  -                  destinationSubscriptions.remove(req.destination);
  -               }
  -            }
  -         }
  -         
  +
  +         removeConsumerInternal(req);
         }
         catch (Exception e)
         {
  @@ -967,6 +1085,24 @@
         
      }
   
  +   private void removeConsumerInternal(Subscription req) {
  +      synchronized (subscriptions)
  +      {
  +         
  +         subscriptions.remove(new Integer(req.subscriptionId));
  +         
  +         LinkedList ll = (LinkedList)destinationSubscriptions.get(req.destination);
  +         if (ll != null)
  +         {
  +            ll.remove(req);
  +            if (ll.size() == 0)
  +            {
  +               destinationSubscriptions.remove(req.destination);
  +            }
  +         }
  +      }
  +   }
  +   
      //Send a message to the serverIL
      void sendToServer(SpyMessage mes)
         throws JMSException
  @@ -982,6 +1118,9 @@
            serverIL.addMessage(connectionToken, mes);
            
         }
  +      catch(JMSException ex) {
  +         throw ex;
  +      }
         catch (Exception e)
         {
            throw new SpyJMSException("Cannot send a message to the JMS server", e);
  @@ -1005,7 +1144,7 @@
      {
         try
         {
  -         serverIL.destroySubscription(id);
  +         serverIL.destroySubscription(connectionToken,id);
         }
         catch (Exception e)
         {
  
  
  
  1.3       +49 -19    jbossmq/src/main/org/jboss/mq/ConnectionToken.java
  
  Index: ConnectionToken.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/ConnectionToken.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionToken.java      17 Aug 2001 03:04:01 -0000      1.2
  +++ ConnectionToken.java      6 Mar 2002 17:27:48 -0000       1.3
  @@ -13,25 +13,54 @@
   
   /**
    *  This class is the broker point of view on a SpyConnection (it contains a
  - *  ConnectionReceiver)
  + *  ConnectionReceiver).
    *
  - * @author     Norbert Lataille ([EMAIL PROTECTED])
  - * @author     Hiram Chirino ([EMAIL PROTECTED])
  + * Remember that for most IL's it will be serialized!
  + *
  + * @author    <a href="[EMAIL PROTECTED]">Norbert Lataille</a>
  + * @author    <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
  + * @author    <a href="[EMAIL PROTECTED]">Peter Antman</a>
    * @created    August 16, 2001
  - * @version    $Revision: 1.2 $
  + * @version    $Revision: 1.3 $
    */
   public class ConnectionToken
          implements Serializable {
   
      //public transient ConnectionReceiverSetup cr_server;
  +   /**
  +    * Used by the server to callback to client. Will (most of the time)
  +    * be serialized when sent to the server.
  +    */
      public ClientIL  clientIL;
   
  -   private String   clientID;
  +   /**
  +    * The clientID of the connection.
  +    */
  +   protected String   clientID;
  +   
  +   /**
  +    * A secured hashed unique sessionId that is valid only as long
  +    * as the connection live. Set during authentication and used 
  +    * for autorization.
  +    */
  +   private String sessionId;
      private int      hash;
   
      public ConnectionToken( String clientID, ClientIL clientIL ) {
  -      this.clientID = clientID;
         this.clientIL = clientIL;
  +      setClientID(clientID);
  +   }
  +   public ConnectionToken( String clientID, ClientIL clientIL,String sessionId ) {
  +      this(clientID, clientIL);
  +      this.sessionId = sessionId;
  +   }
  +   
  +   public String getClientID() {
  +      return clientID;
  +   }
  +
  +   public void setClientID(String clientID) {
  +      this.clientID = clientID;
         if ( clientID == null ) {
            hash = 0;
         } else {
  @@ -39,24 +68,25 @@
         }
      }
   
  -
  -   public String getClientID() {
  -      return clientID;
  +   public String getSessionId() {
  +      return sessionId;
      }
   
      public boolean equals( Object obj ) {
         // Fixes NPE. Patch submitted by John Ellis (10/29/00)
  -      try {
  -         if ( obj.hashCode() != hash ) {
  -            return false;
  -         }
  -         if ( clientID == null ) {
  -            return true;
  -         }
  -         return ( ( ConnectionToken )obj ).clientID.equals( clientID );
  -      } catch ( Throwable e ) {
  +      if(!(obj instanceof ConnectionToken) || obj == null)
  +         return false;
  +      
  +      if ( obj.hashCode() != hash ) {
            return false;
         }
  +      String yourID =  (( ConnectionToken )obj ).clientID;
  +      if (clientID != null)
  +         return clientID.equals(yourID);
  +      else if (yourID == null)
  +         return true;//We know clientID is null
  +      else
  +         return false;//clientID is null, yourID is not.
      }
   
      public int hashCode() {
  @@ -65,6 +95,6 @@
   
   
      public String toString() {
  -      return "SpyDistributedConnection:" + clientID;
  +      return "SpyDistributedConnection:" + clientID+"/"+sessionId;
      }
   }
  
  
  
  1.3       +15 -6     jbossmq/src/main/org/jboss/mq/SpyConnection.java
  
  Index: SpyConnection.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/SpyConnection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SpyConnection.java        17 Aug 2001 03:04:01 -0000      1.2
  +++ SpyConnection.java        6 Mar 2002 17:27:48 -0000       1.3
  @@ -30,7 +30,7 @@
    * @author     Norbert Lataille ([EMAIL PROTECTED])
    * @author     Hiram Chirino ([EMAIL PROTECTED])
    * @created    August 16, 2001
  - * @version    $Revision: 1.2 $
  + * @version    $Revision: 1.3 $
    */
   public class SpyConnection
          extends Connection
  @@ -66,7 +66,8 @@
         if ( closed ) {
            throw new IllegalStateException( "The connection is closed" );
         }
  -
  +      checkClientID();
  +      
         TopicSession session = new SpyTopicSession( this, transacted, acknowledgeMode 
);
   
         //add the new session to the createdSessions list
  @@ -85,7 +86,8 @@
         if ( closed ) {
            throw new IllegalStateException( "The connection is closed" );
         }
  -
  +      checkClientID();
  +      
         return new SpyConnectionConsumer( this, topic, messageSelector, sessionPool, 
maxMessages );
      }
   
  @@ -117,7 +119,8 @@
         if ( closed ) {
            throw new IllegalStateException( "The connection is closed" );
         }
  -
  +      checkClientID();
  +      
         QueueSession session = new SpyQueueSession( this, transacted, acknowledgeMode 
);
   
         //add the new session to the createdSessions list
  @@ -134,7 +137,8 @@
         if ( closed ) {
            throw new IllegalStateException( "The connection is closed" );
         }
  -
  +      checkClientID();
  +      
         try {
            return serverIL.getTemporaryTopic( connectionToken );
         } catch ( Exception e ) {
  @@ -147,7 +151,8 @@
         if ( closed ) {
            throw new IllegalStateException( "The connection is closed" );
         }
  -
  +      checkClientID();
  +      
         try {
            return serverIL.getTemporaryQueue( connectionToken );
         } catch ( Exception e ) {
  @@ -161,6 +166,8 @@
            if ( closed ) {
               throw new IllegalStateException( "The connection is closed" );
            }
  +         checkClientID();
  +         
            return serverIL.createTopic( connectionToken, name );
         } catch ( Exception e ) {
            throw new SpyJMSException( "Cannot get the Topic from the provider", e );
  @@ -174,6 +181,8 @@
            if ( closed ) {
               throw new IllegalStateException( "The connection is closed" );
            }
  +         checkClientID();
  +         
            return serverIL.createQueue( connectionToken, name );
         } catch ( Exception e ) {
            throw new SpyJMSException( "Cannot get the Queue from the provider", e );
  
  
  
  1.11      +12 -4     jbossmq/src/main/org/jboss/mq/SpySession.java
  
  Index: SpySession.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/SpySession.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SpySession.java   13 Jan 2002 01:10:02 -0000      1.10
  +++ SpySession.java   6 Mar 2002 17:27:48 -0000       1.11
  @@ -16,6 +16,7 @@
   import javax.jms.BytesMessage;
   import javax.jms.Destination;
   import javax.jms.JMSException;
  +import javax.jms.JMSSecurityException;
   import javax.jms.MapMessage;
   import javax.jms.Message;
   import javax.jms.MessageListener;
  @@ -35,7 +36,7 @@
    * @author     Norbert Lataille ([EMAIL PROTECTED])
    * @author     Hiram Chirino ([EMAIL PROTECTED])
    * @created    August 16, 2001
  - * @version    $Revision: 1.10 $
  + * @version    $Revision: 1.11 $
    */
   public abstract class SpySession
          implements Session, XASession {
  @@ -408,8 +409,12 @@
            newMap.add( who );
            consumers = newMap;
         }
  -
  -      connection.addConsumer( who );
  +      try {
  +         connection.addConsumer( who );
  +      }catch(JMSSecurityException ex) {
  +         removeConsumerInternal(who);
  +         throw ex;
  +      }
   
      }
   
  @@ -417,13 +422,16 @@
         throws JMSException {
   
         connection.removeConsumer( who );
  +      
  +      removeConsumerInternal(who);
  +   }
   
  +   private void removeConsumerInternal( SpyMessageConsumer who ) {
         synchronized ( consumers ) {
            HashSet newMap = ( HashSet )consumers.clone();
            newMap.remove( who );
            consumers = newMap;
         }
  -
      }
   
      /**
  
  
  
  1.3       +5 -3      jbossmq/src/main/org/jboss/mq/SpyXAConnection.java
  
  Index: SpyXAConnection.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/SpyXAConnection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SpyXAConnection.java      17 Aug 2001 03:04:01 -0000      1.2
  +++ SpyXAConnection.java      6 Mar 2002 17:27:48 -0000       1.3
  @@ -25,7 +25,7 @@
    *
    * @author     Hiram Chirino ([EMAIL PROTECTED])
    * @created    August 16, 2001
  - * @version    $Revision: 1.2 $
  + * @version    $Revision: 1.3 $
    */
   public class SpyXAConnection
          extends SpyConnection
  @@ -64,7 +64,8 @@
         if ( closed ) {
            throw new IllegalStateException( "The connection is closed" );
         }
  -
  +      checkClientID();
  +      
         XAQueueSession session = new SpyQueueSession( this, true, 0, true );
   
         //add the new session to the createdSessions list
  @@ -89,7 +90,8 @@
         if ( closed ) {
            throw new IllegalStateException( "The connection is closed" );
         }
  -
  +      checkClientID();
  +      
         XATopicSession session = new SpyTopicSession( this, true, 0, true );
         //add the new session to the createdSessions list
         synchronized ( createdSessions ) {
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to