美文网首页
ActiveMQ(二) 安全机制

ActiveMQ(二) 安全机制

作者: 为喵星人而战 | 来源:发表于2018-06-03 11:25 被阅读0次

ActiveMQ 的安全机制

    为了避免"只要知道本机的ip和端口,任何人都可以向queue中发送消息 或者 从queue中取消息"这种情况,
可以使用ActiveMQ的安全机制,不再使用默认的用户名和密码,而是使用自己设定的用户名和密码。
    这个可以到ActiveMQ的配置文件activemq.xml中进行配置,
    activemq.xml的路劲,例如:D:\Program Files\Java\ActiveMq\apache-activemq-5.6.0\conf 这个路径下面。

1.配置用户名和密码

配置用户名和密码只需要在 activemq.xml文件中的 <broker></broker> 标签里面加入一个 <plugins></plugins>标签即可,具体如下:

    <plugins>     
        <simpleAuthenticationPlugin>    
        <users>    
            <authenticationUser username="chen" password="chen123" groups="users,admins"/>    
        </users>    
        </simpleAuthenticationPlugin>    
    </plugins> 

整个activemq.xml文件如下:

<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<!-- START SNIPPET: example -->
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

    <!--
        The <broker> element is used to configure the ActiveMQ broker.
    -->
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">

        <!--
            For better performances use VM cursor and small memory limit.
            For more information, see:

            http://activemq.apache.org/message-cursors.html

            Also, if your producer is "hanging", it's probably due to producer flow control.
            For more information, see:
            http://activemq.apache.org/producer-flow-control.html
        -->

        <destinationPolicy>
            <policyMap>
              <policyEntries>
                <policyEntry topic=">" producerFlowControl="true" memoryLimit="1mb">
                  <pendingSubscriberPolicy>
                    <vmCursor />
                  </pendingSubscriberPolicy>
                </policyEntry>
                <policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb">
                  <!-- Use VM cursor for better latency
                       For more information, see:

                       http://activemq.apache.org/message-cursors.html

                  <pendingQueuePolicy>
                    <vmQueueCursor/>
                  </pendingQueuePolicy>
                  -->
                </policyEntry>
              </policyEntries>
            </policyMap>
        </destinationPolicy>


        <!--
            The managementContext is used to configure how ActiveMQ is exposed in
            JMX. By default, ActiveMQ uses the MBean server that is started by
            the JVM. For more information, see:

            http://activemq.apache.org/jmx.html
        -->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <!--
            Configure message persistence for the broker. The default persistence
            mechanism is the KahaDB store (identified by the kahaDB tag).
            For more information, see:

            http://activemq.apache.org/persistence.html
        -->
        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>


          <!--
            The systemUsage controls the maximum amount of space the broker will
            use before slowing down producers. For more information, see:
            http://activemq.apache.org/producer-flow-control.html
            If using ActiveMQ embedded - the following limits could safely be used:

        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>
        -->
          <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="64 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <!--
            The transport connectors expose ActiveMQ over a given protocol to
            clients and other brokers. For more information, see:

            http://activemq.apache.org/configuring-transports.html
        -->
        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
        </transportConnectors>


        <plugins>     
            <simpleAuthenticationPlugin>    
            <users>    
                <authenticationUser username="chen" password="chen123" groups="users,admins"/>    
            </users>    
            </simpleAuthenticationPlugin>    
        </plugins>    



    </broker>

    <!--
        Enable web consoles, REST and Ajax APIs and demos

        Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
    -->
    <import resource="jetty.xml"/>

</beans>
<!-- END SNIPPET: example -->

2.重启ActiveMQ,即重启 activemq.bat 文件。

3.在生产者(Sender)和消费者(receiver) 创建连接工厂的代码部分,修改默认的用户名和密码 为 自己设定的用户名和密码;如果不修改,则访问会报错

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
            "chen",
            "chen123",
            "tcp://localhost:61616");

相关文章

  • ActiveMQ(二) 安全机制

    ActiveMQ 的安全机制 1.配置用户名和密码 配置用户名和密码只需要在 activemq.xml文件中的 ...

  • ActiveMQ-安全机制

    activemq的web管理页面:http://127.0.0.1:8161/admin activemq管控台使...

  • 第四章 连接到ActiveMQ

    JMS代理(如ActiveMQ broker)的主要作用是为客户端程序提供一种通信机制。为此,ActiveMQ提供...

  • SEAndroid安全机制(二)

    前一篇文章介绍了SEAndroid安全机制的框架,以及代码中各个文件的作用,接下来总结下遇到SEAndroid问题...

  • SpringBoot之ActiveMQ实现延迟消息

    一、安装activeMQ ​ 安装步骤参照网上教程,本文不做介绍 二、修改activeMQ配置文件...

  • Active MQ未授权访问

    ActiveMQ是一款流行的开源消息服务器。默认情况下,ActiveMQ服务是没有配置安全参数。恶意人员可以利用默...

  • activeMQ-08签收机制

    activeMQ的签收机制,主要作用于消费者。1)默认为自动签收;Session.AUTO_ACKNOWLEDGE...

  • 摘要

    监狱安全管理的机制,由领导责任机制,安全防控机制,隐患排除机制,应急处置机制,狱情搜集机制组成。领导责任机制,坚持...

  • ActiveMQ二之ActiveMQ简介

    个人专题目录: ActiviMQ专题 链路追踪 Dubbo专题 Docker专题 Git专题 Idea专题 Jav...

  • iOS逆向工程

    一.什么是逆向工程 二.iOS 系统安全机制 1.iOS 系统的安全架构 加载顺序:①.安全启动链--->②.系统...

网友评论

      本文标题:ActiveMQ(二) 安全机制

      本文链接:https://www.haomeiwen.com/subject/kvhjsftx.html