RBACDecorator implements RBACDecoratorMBean { static String pidListKey(List<String> allJmxAclPids, ObjectName objectName) throws NoSuchAlgorithmException, UnsupportedEncodingException { List<String> pidCandidates = iterateDownPids(nameSegments(objectName)); MessageDigest md = MessageDigest.getInstance("MD5"); for (String pc : pidCandidates) { String generalPid = getGeneralPid(allJmxAclPids, pc); if (generalPid.length() > 0) { md.update(generalPid.getBytes("UTF-8")); } } return Hex.encodeHexString(md.digest()); } RBACDecorator(BundleContext bundleContext); @Override @SuppressWarnings("unchecked") void decorate(Map<String, Object> result); @Override boolean getVerify(); @Override void setVerify(boolean verify); static Logger LOG; }
@Test public void objectNameKeys() throws Exception { List<String> realJmxAclPids = Arrays.asList( "jmx.acl.org.apache.activemq.Broker.amq1.Queue.q2", "jmx.acl.org.apache.activemq.Broker.amq1.Queue._", "jmx.acl.org.apache.activemq.Broker._.Queue.q1", "jmx.acl.org.apache.activemq.Broker._.Queue", "jmx.acl.org.apache.activemq.Broker.amq2", "jmx.acl.org.apache.activemq.Broker._", "jmx.acl.org.apache.activemq._", "jmx.acl.org.apache.activemq", "jmx.acl"); ObjectName o11 = new ObjectName("org.apache.activemq:type=Broker,brokerName=amq1,destinationType=Queue,destinationName=q1"); ObjectName o12 = new ObjectName("org.apache.activemq:type=Broker,brokerName=amq1,destinationType=Queue,destinationName=q2"); ObjectName o13 = new ObjectName("org.apache.activemq:type=Broker,brokerName=amq1,destinationType=Queue,destinationName=q3"); String k1 = RBACDecorator.pidListKey(realJmxAclPids, o11); String k2 = RBACDecorator.pidListKey(realJmxAclPids, o12); String k3 = RBACDecorator.pidListKey(realJmxAclPids, o13); assertThat(k1, not(equalTo(k2))); assertThat(k1, equalTo(k3)); }