ActiveMQ 认证与授权
使用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 认证与授权的更多相关文章
- OAuth2.0认证和授权原理
什么是OAuth授权? 一.什么是OAuth协议 OAuth(开放授权)是一个开放标准. 允许第三方网站在用户授权的前提下访问在用户在服务商那里存储的各种信息. 而这种授权无需将用户提供用户名和密 ...
- MVC 登录认证与授权及读取登录错误码
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 最近在自学MVC,遇到的问题很多,索性一点点总结下 ...
- Python+Django+SAE系列教程17-----authauth (认证与授权)系统1
通过session,我们能够在多次浏览器请求中保持数据,接下来的部分就是用session来处理用户登录了. 当然,不能仅凭用户的一面之词,我们就相信,所以我们须要认证. 当然了,Django 也提供了 ...
- hOAuth2.0认证和授权原理
原文地址: http://www.6zou.net/tech/what_is_oauth.html http://www.phpddt.com/%E4%BA%8C%E6%AC%A1%E5%BC%80% ...
- Open开发平台,认证,授权,计费
1.申请appid和appkeyhttp://wiki.connect.qq.com/%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C_oauth2-0 appid:应用的唯一 ...
- 用户登录安全框架shiro—用户的认证和授权(一)
ssm整合shiro框架,对用户的登录操作进行认证和授权,目的很纯粹就是为了增加系统的安全线,至少不要输在门槛上嘛. 这几天在公司独立开发一个供公司内部人员使用的小管理系统,客户不多但是登录一直都是 ...
- Asp.Net MVC-4-过滤器1:认证与授权
基础 过滤器体现了MVC框架中的Aop思想,虽然这种实现并不完美但在实际的开发过程中一般也足以满足需求了. 过滤器分类 依据上篇分析的执行时机的不同可以把过滤器按照实现不同的接口分为下面五类: IAu ...
- ASP.NET Core 认证与授权[1]:初识认证
在ASP.NET 4.X 中,我们最常用的是Forms认证,它既可以用于局域网环境,也可用于互联网环境,有着非常广泛的使用.但是它很难进行扩展,更无法与第三方认证集成,因此,在 ASP.NET Cor ...
- ASP.NET Core 认证与授权[3]:OAuth & OpenID Connect认证
在上一章中,我们了解到,Cookie认证是一种本地认证方式,通常认证与授权都在同一个服务中,也可以使用Cookie共享的方式分开部署,但局限性较大,而如今随着微服务的流行,更加偏向于将以前的单体应用拆 ...
随机推荐
- .sql文件l通过PLSQL导入到Oracle数据库
最近从第三方共享到一个数据,对方提供的是.sql文件.如何导入Oracle数据库? 开始想通过navicat for mysql工具--运行SQL文件来导入表---总是出现错误,失败. 后来还是用回P ...
- java8新特性一图整理
可以右键在新选项卡打开查看大图 原图地址:https://www.processon.com/view/5abb31abe4b027675e42cebc#map
- 【转】史上最强Tomcat8性能优化
https://blog.csdn.net/ThinkWon/article/details/102744033 文章目录授人以鱼不如授人以渔目的服务器资源Tomcat配置优化Linux环境安装运行T ...
- Sword 第三方库介绍二
/* uuid生成 */ #include <stdio.h> #include <stdlib.h> /* calloc()函数头文件 */ #include <ass ...
- osg::Group源码
osg::Group源码 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library i ...
- [Algorithm] Graph
图的概念有点多,在此只讨论最基础的内容,所以选择比较薄的高教版<数据结构>. 1.4 非线性数据结构--图 ........................................ ...
- OpenStack Neutron单网卡桥接模式访问外网
环境配置: * Exsi一台 * Exsi创建的单网卡虚拟机一台 * Ubuntu 14LTS 64位操作系统 * OpenStack Liberty版本 * 使用Neutron网络而非Nova网络 ...
- [ Docker ] 基础概念
目录- 什么是容器- 虚拟化和容器技术- docker 的基本概念 1. 什么是容器 容器英文:Container,容器是一种基础工具:泛指任何可以用于容纳其他物品的工具,可以部分或者完全封闭,被用于 ...
- oracle创建用户并指定表空间
/*第1步:创建ODPS数据表空间 */create tablespace ODPS logging datafile '/home/oracle/tablespace_dir/ODPS.dbf' s ...
- iOS @功能的部分实现思路
需求描述 1. 发布信息时,通过键盘键入@符号,或者点选相关功能键,唤醒@列表,进行选择 2.选择结束后,输入栏改色显示相关内容 3.删除时,整体删除@区块,且不能让光标落在@区块之间 实现步骤 1. ...