[ 
https://issues.apache.org/jira/browse/ARTEMIS-1921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17837405#comment-17837405
 ] 

Justin Bertram commented on ARTEMIS-1921:
-----------------------------------------

[~johan1], upon closer inspection I can't get your attached code to work with 
Qpid JMS. The client ID is *not* available during authentication. Here's the 
test I'm running:
{code:java}
import javax.jms.Connection;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import 
org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.core.security.CheckType;
import org.apache.activemq.artemis.core.security.Role;
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager3;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.qpid.jms.JmsConnectionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class Artemis1921 extends ActiveMQTestBase {

   private EmbeddedActiveMQ broker;

   @Before
   public void setup() throws Exception {
      broker = new EmbeddedActiveMQ();
      broker.setSecurityManager(new ActiveMQSecurityManager3() {
         @Override
         public boolean validateUserAndRole(final String user, final String 
password, final Set<Role> roles, final CheckType checkType) {
            return validateUser(user, password);
         }

         @Override
         public boolean validateUser(final String user, final String password) {
            return "foo".equals(user) && "bar".equals(password);
         }

         @Override
         public String validateUserAndRole(final String user, final String 
password, final Set<Role> roles, final CheckType checkType, final String 
address,
                                           final RemotingConnection 
remotingConnection) {
            return validateUser(user, password, remotingConnection);
         }

         @Override
         public String validateUser(final String user, final String password, 
final RemotingConnection remotingConnection) {
            final String clientID = remotingConnection.getClientID();
            if (clientID == null) {
               System.err.println("*****************************************");
               System.err.println("* No clientID set!");
               System.err.println("*****************************************");
               return null;
            }
            return validateUser(user, password) ? user : null;
         }
      });
      final TransportConfiguration transportCfg = new 
TransportConfiguration(NettyAcceptorFactory.class.getName());
      transportCfg.getParams().put(TransportConstants.PROTOCOLS_PROP_NAME, 
"CORE,AMQP");
      transportCfg.getParams().put(TransportConstants.HOST_PROP_NAME, 
"0.0.0.0");
      transportCfg.getParams().put(TransportConstants.PORT_PROP_NAME, "61616");
      broker.setConfiguration(new ConfigurationImpl()
                                 .setPersistenceEnabled(false)
                                 .setSecurityEnabled(true)
                                 .setAcceptorConfigurations(new 
HashSet<>(Arrays.asList(transportCfg)))
      );

      broker.start();
   }

   @After
   public void tearDown() throws Exception {
      broker.stop();
   }

   @Test
   public void testJMSConnect() throws Exception {
      final JmsConnectionFactory jmsCF = new 
JmsConnectionFactory("amqp://localhost:61616");
      jmsCF.setUsername("foo");
      jmsCF.setPassword("bar");
      jmsCF.setClientID("foo_001"); // trying to set clientID on CF
      final Connection jmsConn = jmsCF.createConnection();
      jmsConn.setClientID("foo_001"); // trying to set clientID on connection
      jmsConn.start();
      jmsConn.close();
   }
}{code}
This code doesn't work for any of the supported JMS clients (i.e. Core JMS, 
Qpid JMS, and OpenWire JMS).

> Setting client ID on core JMS should be reflected in broker RemotingConnection
> ------------------------------------------------------------------------------
>
>                 Key: ARTEMIS-1921
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-1921
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>          Components: Broker
>    Affects Versions: 2.6.1
>            Reporter: Johan Stenberg
>            Priority: Major
>         Attachments: Artemis1921_CoreJmsClient_SetClientId_Test.java
>
>
> As opposite to Qpid JMS Client over AMPQ1.0 or FuseSource StompJMS client 
> over STOMP, a clientID set on the JMS ConnectionFactory or the Connection in 
> the Artemis JMS Client is not available on the broker via 
> RemotingConnection#getClientID().



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to