使用ActiveMQ自带simpleAuthenticationPlugin

1.直接将用户名密码写入activemq.xml文件

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

2.使用credentials.properties存储明文凭证

<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="${activemq.username}" password="${activemq.password}" groups="users, admins" />
</users>
</simpleAuthenticationPlugin>
</plugins> vim credentials.properties
activemq.username=username
activemq.password=password

activemq.xml 顶部导入了file:${activemq.conf}/credentials.properties,我们可以使用变量的方式引用该文件内部的属性

groups="users, admins" 表示定义用户所属的用户组, activemq按照用户组分配权限,注意不能删除groups属性,可以置空

3.使用credentials-enc.properties存储加密凭证

ActiveMQ允许我们对凭证加密后存储在配置文件中,虽然更加安全但也麻烦一些,这里根据实验结果对官方文档给出的方法进行梳理

# --- 创建加密凭证
bin/activemq encrypt --password activemq --input password
# --password 凭证加密密码 --input 凭证原文
# 返回内容:
# ...
# Encrypted text: FJnN6inNmqDigYEs4wDgkwbe3l2B7mQr
# 解密过程相反,但要输入相同的凭证加密密码
bin/activemq decrypt --password activemq --input FJnN6inNmqDigYEs4wDgkwbe3l2B7mQr
# 返回内容:
# ...
# Decrypted text: password # --- 将加密凭证写入credentials-enc.properties
activemq.username=admin
activemq.password=ENC(FJnN6inNmqDigYEs4wDgkwbe3l2B7mQr)
# 格式上注意使用ENC()包裹加密凭证 # --- 修改activemq.xml顶部的配置导入部分
<!-- 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> --> <bean id="environmentVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="passwordEnvName" value="ACTIVEMQ_ENCRYPTION_PASSWORD" />
</bean> <bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="environmentVariablesConfiguration" />
</bean> <bean id="propertyConfigurer" class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor" />
<property name="location" value="file:${activemq.base}/conf/credentials-enc.properties"/>
</bean>
# 注释掉原有的credentials.properties导入部分,新增三个bean,三个bean的意思是从环境变量ACTIVEMQ_ENCRYPTION_PASSWORD中加载凭证加密密码,然后对credentials-enc.properties中的加密凭证解密,所以启动mq之前还需要设置环境变量。
# 也可以直接将加密密码写在配置文件中:
<!-- 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-enc.properties</value>
</property>
</bean> --> <bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="algorithm" value="PBEWithMD5AndDES"/>
<property name="password" value="activemq"/>
</bean> <bean id="propertyConfigurer" class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor" />
<property name="location" value="file:${activemq.base}/conf/credentials-enc.properties"/>
</bean>
# 将原来三个bean中前两个替换成新的bean # --- 启动MQ实例
# 如果采用环境变量方式存储凭证加密密码,那么这里要设置一下
export ACTIVEMQ_ENCRYPTION_PASSWORD=activemq
bin/activemq start
unset ACTIVEMQ_ENCRYPTION_PASSWORD
# 如果直接将凭证加密密码写入配置文件,那么这里直接启动实例即可

安全这件事强调一万遍也不为过,但如果可以攻破服务器直接看到配置文件的话那问题一定不是MQ的。

使用JAASAuthentication Plugin

JAAS 全称为Java Authentication and Authorization Service JAVA认证授权服务

JAASAuthentication Plugin依赖标准的JAAS机制来实现认证,默认使用login.config文件作为配置

vim login.config
activemq {
org.apache.activemq.jaas.PropertiesLoginModule required
org.apache.activemq.jaas.properties.user="users.properties"
org.apache.activemq.jaas.properties.group="groups.properties";
};

login.config配置中引用了users.properties和groups.properties分别进行用户名密码和用户组配置

vim users.properties
username=password
vim groups.properties
groups=username1, username2...

在activemq.xml添加JAASAuthentication Plugin配置

<plugins>
<jaasAuthenticationPlugin configuration="activemq" />
</plugins>

configuration="activemq" 指向login.config中配置的名称

使用authorizationPlugin进行授权

activemq可以对Queue,Topic的读写创建等进行权限控制,权限按照用户组分配

<plugins>
<authorizationPlugin>
<map>
<authorizationMap>
<authorizationEntries>
<authorizationEntry queue="activemq.>" read="users" write="users" admin="users"/>
<authorizationEntry topic="USER.>" read="admins" write="admins" admin="admins"/>
</authorizationEntries>
</authorizationMap>
</map>
</authorizationPlugin>
</plugins>

> 表示通配符 上述配置表明只有users组才能读写创建activemq.开头的队列,只有admins组才能读写创建USER.开头的主题

值的注意的是,"activemq.>"中通配符前的点符号必须存在否则无法生效,也就是说前缀必须以点号结尾

> 也可用 * 替换

ActiveMQ 认证与授权的更多相关文章

  1. OAuth2.0认证和授权原理

    什么是OAuth授权?   一.什么是OAuth协议 OAuth(开放授权)是一个开放标准. 允许第三方网站在用户授权的前提下访问在用户在服务商那里存储的各种信息. 而这种授权无需将用户提供用户名和密 ...

  2. MVC 登录认证与授权及读取登录错误码

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精    最近在自学MVC,遇到的问题很多,索性一点点总结下 ...

  3. Python+Django+SAE系列教程17-----authauth (认证与授权)系统1

    通过session,我们能够在多次浏览器请求中保持数据,接下来的部分就是用session来处理用户登录了. 当然,不能仅凭用户的一面之词,我们就相信,所以我们须要认证. 当然了,Django 也提供了 ...

  4. hOAuth2.0认证和授权原理

    原文地址: http://www.6zou.net/tech/what_is_oauth.html http://www.phpddt.com/%E4%BA%8C%E6%AC%A1%E5%BC%80% ...

  5. Open开发平台,认证,授权,计费

    1.申请appid和appkeyhttp://wiki.connect.qq.com/%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C_oauth2-0 appid:应用的唯一 ...

  6. 用户登录安全框架shiro—用户的认证和授权(一)

     ssm整合shiro框架,对用户的登录操作进行认证和授权,目的很纯粹就是为了增加系统的安全线,至少不要输在门槛上嘛. 这几天在公司独立开发一个供公司内部人员使用的小管理系统,客户不多但是登录一直都是 ...

  7. Asp.Net MVC-4-过滤器1:认证与授权

    基础 过滤器体现了MVC框架中的Aop思想,虽然这种实现并不完美但在实际的开发过程中一般也足以满足需求了. 过滤器分类 依据上篇分析的执行时机的不同可以把过滤器按照实现不同的接口分为下面五类: IAu ...

  8. ASP.NET Core 认证与授权[1]:初识认证

    在ASP.NET 4.X 中,我们最常用的是Forms认证,它既可以用于局域网环境,也可用于互联网环境,有着非常广泛的使用.但是它很难进行扩展,更无法与第三方认证集成,因此,在 ASP.NET Cor ...

  9. ASP.NET Core 认证与授权[3]:OAuth & OpenID Connect认证

    在上一章中,我们了解到,Cookie认证是一种本地认证方式,通常认证与授权都在同一个服务中,也可以使用Cookie共享的方式分开部署,但局限性较大,而如今随着微服务的流行,更加偏向于将以前的单体应用拆 ...

随机推荐

  1. go -- 测试

    package 测试 import ( "fmt" "github.com/magiconair/properties/assert" "net/ht ...

  2. Activiti task claim

    Activiti task claim claim,认领,领取 claim - 国内版 Bing https://cn.bing.com/search?FORM=U227DF&PC=U227& ...

  3. pip的安装

    1.get-pip.py安装 (官方)https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py $wget https: ...

  4. c#中Split 分离字符以及空格消除方法

    1        split几种分离方法 1)用字符串分隔: using System.Text.RegularExpressions; string str="aaajsbbbjsccc& ...

  5. AC与AP的安装使用(未经实战,仅供参考,未完待续)

    AC:无线控制器(Wireless Access Point Controller) AP:无线访问接入点(WirelessAccessPoint) 以信锐AC为例 AC设备的管理口为MANAGE(E ...

  6. [LeetCode] 803. Bricks Falling When Hit 打击砖块掉落

    We have a grid of 1s and 0s; the 1s in a cell represent bricks.  A brick will not drop if and only i ...

  7. PCL读取PCD文件的数据

    1.pcd文件——rabbit.pcd 链接:https://pan.baidu.com/s/1v6mjPjwd7fIqUSjlIGTIGQ提取码:zspx 新建项目pcl rabbit.pcd 和p ...

  8. spring boot @RequestBody数据传递及解析

    @RequestBody需要接的参数是一个string化的json @RequestBody,要读取的数据在请求体里,所以要发post请求,还要将Content-Type设置为application/ ...

  9. 【视频开发】 十全大补:CxImage图像处理类库

     十全大补:CxImage图像处理类库 转载IT168        CxImage是一个可以用于MFC 的C++图像处理类库类,它可以打开,保存,显示,转换各种常见格式的图像文件,比如BMP, JP ...

  10. 机器学习技法总结(四)(aggregation,vote,bootstrap...)

    研究的动机是:我们采用了不同的模型得到T个不同的g,那么我们是不是可以通过这些不同的g的融合得到更加出色的G呢?因此,便有了以上四种不同的方法:1)(select)直接选择最好的一个作为融合的结果:2 ...