activemq 使用自定义插件(ip白名单认证插件)
插件类
IPAuthenticationBroker用来过滤ip
符合ip格式的ip会判断是否在允许的白名单中,否则抛出异常
package com.xxx.mq.myPlugins;
public class IPAuthenticationBroker extends BrokerFilter {
List<String> allowedIPAddresses;
Pattern pattern = Pattern.compile("^/([0-9\\.]*):(.*)");
public IPAuthenticationBroker(Broker next, List<String> allowedIPAddresses) {
super(next);
this.allowedIPAddresses = allowedIPAddresses;
}
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
String remoteAddress = context.getConnection().getRemoteAddress().split(":")[1].substring(2)