Authorization by login / password does not work when connecting via JMX

huangapple go评论67阅读模式
英文:

Authorization by login / password does not work when connecting via JMX

问题

I have a method whose parameters are passed values for connecting to the ActiveMQ Artemis broker via the JMX protocol. But my username/password is not working. That is, if I leave the user and password values empty, then it will still connect, and I want an error to pop up when connecting to the queue since the user data is incorrect.

public static MBeanServerConnection connectBroker(String brokerUrl, String user, String password) {
    try {
        Map<String, String[]> env = new HashMap();
        String[] creds = {user, password};
        env.put(JMXConnector.CREDENTIALS, creds);
        JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + brokerUrl + ":13682/jmxrmi"), env);
        return connector.getMBeanServerConnection();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

It's strange that if CREDENTIALS are passed, it still works, but I want it to give an error if there is no such user.

broker.xml:

<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
   <core xmlns="urn:activemq:core">
		<name>localhost</name>
      <bindings-directory>./data/messaging/bindings</bindings-directory>

      <journal-directory>./data/messaging/journal</journal-directory>

      <large-messages-directory>./data/messaging/largemessages</large-messages-directory>

      <paging-directory>./data/messaging/paging</paging-directory>

      <!-- true to expose ActiveMQ Artemis resources through JMX -->
      <jmx-management-enabled>true</jmx-management-enabled>

      <!-- Acceptors -->
      <acceptors>
         <acceptor name="netty">tcp://localhost:61616</acceptor>
      </acceptors>

      <!-- Other config -->

      <security-settings>
         <!--security for example queue-->
         <security-setting match="exampleQueue">
            <permission roles="amq" type="createDurableQueue"/>
            <permission roles="amq" type="deleteDurableQueue"/>
            <permission roles="amq" type="createNonDurableQueue"/>
            <permission roles="amq" type="deleteNonDurableQueue"/>
            <permission roles="amq" type="consume"/>
            <permission roles="amq" type="send"/>
			<permission roles="amq" type="browse"/>
         </security-setting>
		 <security-setting match="TestQueue">
            <permission roles="amq" type="createDurableQueue"/>
            <permission roles="amq" type="deleteDurableQueue"/>
            <permission roles="amq" type="createNonDurableQueue"/>
            <permission roles="amq" type="deleteNonDurableQueue"/>
            <permission roles="amq" type="consume"/>
            <permission roles="amq" type="send"/>
         </security-setting>
		 <security-setting match="TestQueueSecond">
            <permission roles="amq" type="createDurableQueue"/>
            <permission roles="amq" type="deleteDurableQueue"/>
            <permission roles="amq" type="createNonDurableQueue"/>
            <permission roles="amq" type="deleteNonDurableQueue"/>
            <permission roles="amq" type="consume"/>
            <permission roles="amq" type="send"/>
         </security-setting>
      </security-settings>

      <addresses>
         <address name="exampleQueue">
            <anycast>
               <queue name="exampleQueue"/>
            </anycast>
         </address>
		 <address name="TestQueue">
            <anycast>
               <queue name="TestQueue"/>
            </anycast>
         </address>
		 <address name="TestQueueSecond">
            <anycast>
               <queue name="TestQueueSecond"/>
            </anycast>
         </address>
      </addresses>
   </core>
</configuration>

management.xml:

<management-context xmlns="http://activemq.apache.org/schema">
   <connector connector-port="13682" connector-host="localhost"/>
   <authorisation>
      <allowlist>
         <entry domain="hawtio"/>
      </allowlist>
      <default-access>
         <access method="list*" roles="view,update,amq,guest"/>
         <access method="get*" roles="view,update,amq,guest"/>
         <access method="is*" roles="view,update,amq,guest"/>
         <access method="set*" roles="update,amq,guest"/>
         <access method

<details>
<summary>英文:</summary>

I have a method whose parameters are passed values for connecting to the ActiveMQ Artemis broker via the JMX protocol. But my username/password is not working. That is, if I leave the user and password values empty, then it will still connect, and I want an error to pop up when connecting to the queue since the user data is incorrect

```java
public static MBeanServerConnection connectBroker(String brokerUrl, String user, String password) {
    try {
        Map&lt;String, String[]&gt; env = new HashMap();
        String[] creds = {user, password};
        env.put(JMXConnector.CREDENTIALS, creds);
        JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(&quot;service:jmx:rmi:///jndi/rmi://&quot; + brokerUrl + &quot;:13682/jmxrmi&quot;), env);
        return connector.getMBeanServerConnection();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

It's strange that if CREDENTIALS is passed, it still works, but I want it to give an error if there is no such user

broker.xml:

&lt;configuration xmlns=&quot;urn:activemq&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;urn:activemq /schema/artemis-configuration.xsd&quot;&gt;
   &lt;core xmlns=&quot;urn:activemq:core&quot;&gt;
		&lt;name&gt;localhost&lt;/name&gt;
      &lt;bindings-directory&gt;./data/messaging/bindings&lt;/bindings-directory&gt;

      &lt;journal-directory&gt;./data/messaging/journal&lt;/journal-directory&gt;

      &lt;large-messages-directory&gt;./data/messaging/largemessages&lt;/large-messages-directory&gt;

      &lt;paging-directory&gt;./data/messaging/paging&lt;/paging-directory&gt;


      &lt;!-- true to expose ActiveMQ Artemis resources through JMX --&gt;
      &lt;jmx-management-enabled&gt;true&lt;/jmx-management-enabled&gt;

      &lt;!-- Acceptors --&gt;
      &lt;acceptors&gt;
         &lt;acceptor name=&quot;netty&quot;&gt;tcp://localhost:61616&lt;/acceptor&gt;
      &lt;/acceptors&gt;

      &lt;!-- Other config --&gt;

      &lt;security-settings&gt;
         &lt;!--security for example queue--&gt;
         &lt;security-setting match=&quot;exampleQueue&quot;&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;createDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;deleteDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;createNonDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;deleteNonDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;consume&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;send&quot;/&gt;
			&lt;permission roles=&quot;amq&quot; type=&quot;browse&quot;/&gt;
         &lt;/security-setting&gt;
		 &lt;security-setting match=&quot;TestQueue&quot;&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;createDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;deleteDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;createNonDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;deleteNonDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;consume&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;send&quot;/&gt;
         &lt;/security-setting&gt;
		 &lt;security-setting match=&quot;TestQueueSecond&quot;&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;createDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;deleteDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;createNonDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;deleteNonDurableQueue&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;consume&quot;/&gt;
            &lt;permission roles=&quot;amq&quot; type=&quot;send&quot;/&gt;
         &lt;/security-setting&gt;
      &lt;/security-settings&gt;

      &lt;addresses&gt;
         &lt;address name=&quot;exampleQueue&quot;&gt;
            &lt;anycast&gt;
               &lt;queue name=&quot;exampleQueue&quot;/&gt;
            &lt;/anycast&gt;
         &lt;/address&gt;
		 &lt;address name=&quot;TestQueue&quot;&gt;
            &lt;anycast&gt;
               &lt;queue name=&quot;TestQueue&quot;/&gt;
            &lt;/anycast&gt;
         &lt;/address&gt;
		 &lt;address name=&quot;TestQueueSecond&quot;&gt;
            &lt;anycast&gt;
               &lt;queue name=&quot;TestQueueSecond&quot;/&gt;
            &lt;/anycast&gt;
         &lt;/address&gt;
      &lt;/addresses&gt;
   &lt;/core&gt;
&lt;/configuration&gt;

management.xml:

&lt;management-context xmlns=&quot;http://activemq.apache.org/schema&quot;&gt;
   &lt;connector connector-port=&quot;13682&quot; connector-host=&quot;localhost&quot;/&gt;
   &lt;authorisation&gt;
      &lt;allowlist&gt;
         &lt;entry domain=&quot;hawtio&quot;/&gt;
      &lt;/allowlist&gt;
      &lt;default-access&gt;
         &lt;access method=&quot;list*&quot; roles=&quot;view,update,amq,guest&quot;/&gt;
         &lt;access method=&quot;get*&quot; roles=&quot;view,update,amq,guest&quot;/&gt;
         &lt;access method=&quot;is*&quot; roles=&quot;view,update,amq,guest&quot;/&gt;
         &lt;access method=&quot;set*&quot; roles=&quot;update,amq,guest&quot;/&gt;
         &lt;access method=&quot;*&quot; roles=&quot;amq,guest&quot;/&gt;
      &lt;/default-access&gt;
      &lt;role-access&gt;
         &lt;match domain=&quot;org.apache.activemq.artemis&quot;&gt;
            &lt;access method=&quot;list*&quot; roles=&quot;view,update,amq,guest&quot;/&gt;
            &lt;access method=&quot;get*&quot; roles=&quot;view,update,amq,guest&quot;/&gt;
            &lt;access method=&quot;is*&quot; roles=&quot;view,update,amq,guest&quot;/&gt;
            &lt;access method=&quot;set*&quot; roles=&quot;update,amq,guest&quot;/&gt;
            &lt;access method=&quot;*&quot; roles=&quot;amq,guest&quot;/&gt;
         &lt;/match&gt;
         &lt;!--example of how to configure a specific object--&gt;
         &lt;!--&lt;match domain=&quot;org.apache.activemq.artemis&quot; key=&quot;subcomponent=queues&quot;&gt;
            &lt;access method=&quot;list*&quot; roles=&quot;view,update,amq&quot;/&gt;
            &lt;access method=&quot;get*&quot; roles=&quot;view,update,amq&quot;/&gt;
            &lt;access method=&quot;is*&quot; roles=&quot;view,update,amq&quot;/&gt;
            &lt;access method=&quot;set*&quot; roles=&quot;update,amq&quot;/&gt;
            &lt;access method=&quot;*&quot; roles=&quot;amq&quot;/&gt;
         &lt;/match&gt;--&gt;
      &lt;/role-access&gt;
   &lt;/authorisation&gt;
&lt;/management-context&gt;

login.config:

activemq {
   org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule sufficient
       debug=false
       reload=true
       org.apache.activemq.jaas.properties.user=&quot;artemis-users.properties&quot;
       org.apache.activemq.jaas.properties.role=&quot;artemis-roles.properties&quot;;
    
   org.apache.activemq.artemis.spi.core.security.jaas.GuestLoginModule sufficient
       debug=false
       org.apache.activemq.jaas.guest.user=&quot;admin&quot;
       org.apache.activemq.jaas.guest.role=&quot;amq&quot;;
};

答案1

得分: 1

Your login.config is using the GuestLoginModule, i.e.:

这表示不传递任何凭据或传递错误凭据的用户将被接受,并分配用户名admin和角色amq。详细信息请参阅文档

If you don't want this behavior you can use this in your login.config instead:

如果您不想要这种行为,您可以在您的login.config中使用以下内容:

英文:

Your login.config is using the GuestLoginModule, i.e.:

   org.apache.activemq.artemis.spi.core.security.jaas.GuestLoginModule sufficient
       debug=false
       org.apache.activemq.jaas.guest.user=&quot;admin&quot;
       org.apache.activemq.jaas.guest.role=&quot;amq&quot;;

This means that users who don't pass any credentials or pass the wrong credentials will be accepted and given the username admin and the role amq. See the documentation for more details.

If you don't want this behavior you can use this in your login.config instead:

activemq {
   org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule required
       debug=false
       reload=true
       org.apache.activemq.jaas.properties.user=&quot;artemis-users.properties&quot;
       org.apache.activemq.jaas.properties.role=&quot;artemis-roles.properties&quot;;
};

huangapple
  • 本文由 发表于 2023年5月11日 16:47:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225749.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定