activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: ARTEMIS-1479 Fix set validated user in large messages
Date Wed, 25 Oct 2017 15:46:25 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master ec9779786 -> 448ff08bf


ARTEMIS-1479 Fix set validated user in large messages


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/06dab31f
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/06dab31f
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/06dab31f

Branch: refs/heads/master
Commit: 06dab31fd0c139d662a3a5973b9a06fe711e0faf
Parents: ec97797
Author: Chris Burlinchon <chris.burlinchon@r3.com>
Authored: Tue Oct 24 17:11:19 2017 +0100
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Wed Oct 25 11:44:14 2017 -0400

----------------------------------------------------------------------
 .../core/server/impl/ServerSessionImpl.java     |  8 +--
 .../largemessage/ServerLargeMessageTest.java    | 74 +++++++++++++++++++-
 2 files changed, 77 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/06dab31f/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
index 679312c..48acdf1 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
@@ -1357,10 +1357,6 @@ public class ServerSessionImpl implements ServerSession, FailureListener
{
          message.setMessageID(id);
       }
 
-      if (server.getConfiguration().isPopulateValidatedUser() && validatedUser !=
null) {
-         message.setValidatedUserID(validatedUser);
-      }
-
       SimpleString address = message.getAddressSimpleString();
 
       if (defaultAddress == null && address != null) {
@@ -1700,6 +1696,10 @@ public class ServerSessionImpl implements ServerSession, FailureListener
{
          throw e;
       }
 
+      if (server.getConfiguration().isPopulateValidatedUser() && validatedUser !=
null) {
+         msg.setValidatedUserID(validatedUser);
+      }
+
       if (tx == null || autoCommitSends) {
       } else {
          routingContext.setTransaction(tx);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/06dab31f/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/largemessage/ServerLargeMessageTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/largemessage/ServerLargeMessageTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/largemessage/ServerLargeMessageTest.java
index a13c5fe..e325273 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/largemessage/ServerLargeMessageTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/largemessage/ServerLargeMessageTest.java
@@ -16,7 +16,13 @@
  */
 package org.apache.activemq.artemis.tests.integration.largemessage;
 
+import java.lang.management.ManagementFactory;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.apache.activemq.artemis.api.core.Message;
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
 import org.apache.activemq.artemis.api.core.client.ClientConsumer;
 import org.apache.activemq.artemis.api.core.client.ClientMessage;
@@ -26,10 +32,15 @@ import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
 import org.apache.activemq.artemis.api.core.client.ServerLocator;
 import org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager;
 import org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl;
+import org.apache.activemq.artemis.core.security.Role;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
-import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.core.server.ActiveMQServers;
+import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
+import org.apache.activemq.artemis.tests.integration.security.SecurityTest;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.junit.After;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 public class ServerLargeMessageTest extends ActiveMQTestBase {
@@ -40,6 +51,29 @@ public class ServerLargeMessageTest extends ActiveMQTestBase {
 
    // Static --------------------------------------------------------
 
+   String originalPath;
+
+   @Before
+   public void setupProperty() {
+      originalPath = System.getProperty("java.security.auth.login.config");
+      if (originalPath == null) {
+         URL resource = SecurityTest.class.getClassLoader().getResource("login.config");
+         if (resource != null) {
+            originalPath = resource.getFile();
+            System.setProperty("java.security.auth.login.config", originalPath);
+         }
+      }
+   }
+
+   @After
+   public void clearProperty() {
+      if (originalPath == null) {
+         System.clearProperty("java.security.auth.login.config");
+      } else {
+         System.setProperty("java.security.auth.login.config", originalPath);
+      }
+   }
+
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
@@ -105,6 +139,44 @@ public class ServerLargeMessageTest extends ActiveMQTestBase {
       }
    }
 
+   @Test
+   public void testSendServerMessageWithValidatedUser() throws Exception {
+      ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
+      ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true),
ManagementFactory.getPlatformMBeanServer(), securityManager, false));
+      server.getConfiguration().setPopulateValidatedUser(true);
+
+      Role role = new Role("programmers", true, true, true, true, true, true, true, true,
true, true);
+      Set<Role> roles = new HashSet<>();
+      roles.add(role);
+      server.getSecurityRepository().addMatch("#", roles);
+
+      server.start();
+      ServerLocator locator = createInVMNonHALocator();
+      ClientSessionFactory sf = createSessionFactory(locator);
+
+      try {
+         ClientSession session = sf.createSession("first", "secret", false, true, true, false,
0);
+         ClientMessage clientMessage = session.createMessage(false);
+         clientMessage.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE));
+
+         session.createQueue("A", RoutingType.ANYCAST, "A");
+
+         ClientProducer prod = session.createProducer("A");
+         prod.send(clientMessage);
+         session.commit();
+         session.start();
+
+         ClientConsumer cons = session.createConsumer("A");
+         ClientMessage msg = cons.receive(5000);
+
+         assertEquals("first", msg.getValidatedUserID());
+      } finally {
+         sf.close();
+         locator.close();
+         server.stop();
+      }
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------


Mime
View raw message