[jboss-cvs] JBoss Messaging SVN: r8514 - in branches/Branch_1_4: src/main/org/jboss/jms/tx and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 1 00:19:14 EDT 2012


Author: gaohoward
Date: 2012-04-01 00:19:09 -0400 (Sun, 01 Apr 2012)
New Revision: 8514

Modified:
   branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java
   branches/Branch_1_4/src/main/org/jboss/jms/tx/MessagingXAResource.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java
Log:
JBMESSAGING-1920



Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java	2012-03-30 04:54:49 UTC (rev 8513)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java	2012-04-01 04:19:09 UTC (rev 8514)
@@ -103,6 +103,11 @@
                                 connectionDelegate.getMaxRetryChangeRate(), connectionDelegate.getRetryChangeRateInterval(),
                                 connectionDelegate.getMinTimeoutProcessTime());
 
+         MethodInvocation mi = (MethodInvocation)inv;
+         String username = (String)mi.getArguments()[0];
+         
+         connectionState.setUsername(username);
+
          remotingConnection.getConnectionListener().setConnectionState(connectionState);
          remotingConnection.getConnectionListener().start();
           

Modified: branches/Branch_1_4/src/main/org/jboss/jms/tx/MessagingXAResource.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/tx/MessagingXAResource.java	2012-03-30 04:54:49 UTC (rev 8513)
+++ branches/Branch_1_4/src/main/org/jboss/jms/tx/MessagingXAResource.java	2012-04-01 04:19:09 UTC (rev 8514)
@@ -21,6 +21,7 @@
   */
 package org.jboss.jms.tx;
 
+import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.client.state.SessionState;
 import org.jboss.jms.delegate.ConnectionDelegate;
 import org.jboss.jms.exception.MessagingXAException;
@@ -109,9 +110,28 @@
          return false;
       }
       
-      boolean same = (((MessagingXAResource)xaResource).rm.getServerID() == this.rm.getServerID())
-                  && (((MessagingXAResource)xaResource).rm.getTransactions() == this.rm.getTransactions());
+      MessagingXAResource otherResource = (MessagingXAResource)xaResource;
       
+      boolean same = (otherResource.rm.getServerID() == this.rm.getServerID())
+                  && (otherResource.rm.getTransactions() == this.rm.getTransactions());
+
+      if (same)
+      {
+         //if user is different, then don't do it
+         ConnectionState state = (ConnectionState)sessionState.getParent();
+         ConnectionState otherState = (ConnectionState)otherResource.sessionState.getParent();
+         String u1 = state.getUsername();
+         String u2 = otherState.getUsername();
+         if (u1 != null)
+         {
+            same = u1.equals(u2);
+         }
+         else if (u2 != null)
+         {
+            same = false;
+         }
+      }
+
       if (trace) { log.trace("Calling isSameRM, result is " + same + " " + ((MessagingXAResource)xaResource).rm.getServerID() + " " + this.rm.getServerID()); }
             
       return same;

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java	2012-03-30 04:54:49 UTC (rev 8513)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java	2012-04-01 04:19:09 UTC (rev 8514)
@@ -30,6 +30,7 @@
 import javax.jms.MessageConsumer;
 import javax.jms.MessageListener;
 import javax.jms.MessageProducer;
+import javax.jms.Queue;
 import javax.jms.ServerSession;
 import javax.jms.ServerSessionPool;
 import javax.jms.Session;
@@ -49,6 +50,7 @@
 import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
 
 import org.jboss.jms.client.JBossConnection;
+import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.JBossSession;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
 import org.jboss.jms.client.delegate.DelegateSupport;
@@ -3577,12 +3579,113 @@
 
    }
 
+   public void testCommit2ResourcesFromDiffUsers() throws Exception
+   {
+      String secConfigA = "<security>" + "<role name=\"guest\" read=\"true\" write=\"true\"/>"
+                          + "</security>";
+
+      Queue securedQueueA = deployAndConfigureSecuredQueue("securedQueueA", secConfigA);
+      
+      String secConfigB = "<security>" + "<role name=\"publisher\" read=\"true\" write=\"true\"/>"
+                          + "</security>";
+
+      Queue securedQueueB = deployAndConfigureSecuredQueue("securedQueueB", secConfigB);
+      
+      Connection conn0 = null;
+      XAConnection xconn1 = null;
+      XAConnection xconn2 = null;
+
+      try
+      {
+         conn0 = cf.createConnection();
+         conn0.start();
+         Session sess0 = conn0.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod = sess0.createProducer(securedQueueA);
+         Message m = sess0.createTextMessage("XATest1");
+         prod.send(m);
+ 
+         xconn1 = cf.createXAConnection("guest", "guest");
+         xconn1.start();
+
+         xconn2 = cf.createXAConnection("john", "needle");
+         xconn2.start();
+
+         tm.begin();
+
+         XASession xsess1 = xconn1.createXASession();
+         MessagingXAResource res1 = (MessagingXAResource)xsess1.getXAResource();
+
+         XASession xsess2 = xconn2.createXASession();
+         MessagingXAResource res2 = (MessagingXAResource)xsess2.getXAResource();
+
+         Transaction tx = tm.getTransaction();
+
+         tx.enlistResource(res1);
+         tx.enlistResource(res2);
+
+         MessageConsumer xcons1 = xsess1.createConsumer(securedQueueA);
+
+         TextMessage m2 = (TextMessage)xcons1.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+         
+         MessageProducer xprod2 = xsess2.createProducer(securedQueueB);
+         xprod2.send(m2);
+
+         tx.delistResource(res1, XAResource.TMSUCCESS);
+         tx.delistResource(res2, XAResource.TMSUCCESS);
+
+         tm.commit();
+
+         //receive m2
+         MessageConsumer cons2 = xsess2.createConsumer(securedQueueB);
+         m2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+
+         assertNotNull(m2);
+         assertEquals("XATest1", m2.getText());
+      }
+      finally
+      {
+         if (conn0 != null)
+         {
+            conn0.close();
+         }
+         if (xconn1 != null)
+         {
+            xconn1.close();
+         }
+         if (xconn2 != null)
+         {
+            xconn2.close();
+         }
+         
+      }
+
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
 
    // Private -------------------------------------------------------
 
+   /**
+    * @param string
+    * @param secConfigA
+    * @return
+    * @throws Exception 
+    */
+   private Queue deployAndConfigureSecuredQueue(String qname, String secConfig) throws Exception
+   {
+      ServerManagement.deployQueue(qname, qname);
+
+      ServerManagement.configureSecurityForDestination(qname, secConfig);
+
+      Queue queue = (Queue)ic.lookup(qname);
+      return queue;
+   }
+
    private void assertEqualByteArrays(final byte[] b1, final byte[] b2)
    {
       log.info("b1 length: " + b1.length + " b2 length " + b2.length);



More information about the jboss-cvs-commits mailing list