除了监视台可以设置用户名和密码外(在conf/jetty.xml中设置),ActiveMQ也可以对各个主题和队列设置用户名和密码(客户端访问broker安全设置)、
1、简单认证插件
SimpleAuthentication Plugin适用于简单的认证需求,或者用于建立测试环境。它允许在XML配置文件中指定用户、用户组和密码等信息。(无法控制到具体的主题队列)
在credentials.properties文件中设置用户名和密码。通过credentials-enc.properties可以对用户名密码进行加密。官方文档地址: http://activemq.apache.org/encrypted-passwords.html
1)credentials.properties:(activemq的conf下)
activemq.username=system
activemq.password=manager
user.username=zhhgtmq
user.password=123456
guest.password=password
2)在activemq.xml文件systemUsage标签之前加上
JAAS(Java Authentication and Authorization Service)也就是java的验证Authentication)、授权(Authorization)服务。简单来说,验证Authentication就是要验证一个用户的有效性,即用户名、密码是否正确。
授权Authorization就是授予用户某种角色,可以访问哪些资源。JAASAuthentication Plugin依赖标准的JAAS机制来实现认证。通常情况下,你需要通过设置java.security.auth.login.config系统属性来配置login modules的配置文件。如果没有指定这个系统属性,那么JAAS Authentication Plugin会缺省使用login.config作为文件名。
1)login.config:
在conf下简历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";
};
2)users.config
在conf下简历users.config文件,内容:
system=manager
user=password
guest=password
在conf下简历groups.config文件,内容:
admins=system,user,guest
例如:
补充:activemq目录下文件说明
activemq.xml
broker.ks
broker.ts
broker-localhost.cert
client.ks
client.ts
credentials.properties //broker连接使用的账号密码文件,明文密码
credentials-enc.properties ////broker连接使用的账号密码文件,加密的密码
groups.properties
jetty.xml
jetty-realm.properties //web console访问的账号密码
jmx.access //访问控制文件,用于限制JMX访问权限
jmx.password //JMX访问密码文件,用于设置JMX访问的密码
log4j.properties
logging.properties
login.config //JAAS认证使用的配置文件,用于指定使用users.properties和groups.properties文件
users.properties