RBACRegistry implements RBACRegistryMBean { @Override public Map<String, Object> list() throws Exception { Map<String, Object> result = new HashMap<>(); Map<String, Map<String, Object>> domains = new HashMap<>(); Map<String, Map<String, Object>> cache = new HashMap<>(); result.put("cache", cache); result.put("domains", domains); if (mBeanServer == null) { return result; } Set<ObjectName> visited = new HashSet<>(); for (ObjectName nameObject : mBeanServer.queryNames(null, null)) { if (!visited.contains(nameObject)) { Map<String, Object> jsonifiedMBeanInfo; Map<String, Object> domain = domains.get(nameObject.getDomain()); if (domain == null) { domain = new HashMap<>(); domains.put(nameObject.getDomain(), domain); } String mbeanInfoKey = isSpecialMBean(nameObject); if (mbeanInfoKey != null && cache.containsKey(mbeanInfoKey)) { jsonifiedMBeanInfo = cache.get(mbeanInfoKey); } else { try { MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(nameObject); if (mbeanInfoKey == null) { mbeanInfoKey = isSpecialClass(nameObject, mBeanInfo); } if (mbeanInfoKey != null && cache.containsKey(mbeanInfoKey)) { jsonifiedMBeanInfo = cache.get(mbeanInfoKey); } else { jsonifiedMBeanInfo = jsonifyMBeanInfo(mBeanInfo); } if (mbeanInfoKey != null) { cache.put(mbeanInfoKey, jsonifiedMBeanInfo); } } catch (InstanceNotFoundException e) { LOG.debug("Failed to get MBean info for {}. Due to InstanceNotFoundException.", nameObject); continue; } } if (mbeanInfoKey != null) { domain.put(nameObject.getKeyPropertyListString(), mbeanInfoKey); } else { domain.put(nameObject.getKeyPropertyListString(), jsonifiedMBeanInfo); } visited.add(nameObject); } } tryAddRBACInfo(result); return result; }  void init(); void destroy(); @Override Map<String, Object> list(); static Logger LOG; }
@Test public void list() throws Exception { Map<String, Object> result = rbacRegistry.list(); assertThat(result.get("cache"), notNullValue()); Map<String, Map<String, Object>> domains = (Map<String, Map<String, Object>>) result.get("domains"); assertThat(domains, notNullValue()); Map<String, Object> hawtioDomain = domains.get("hawtio"); assertThat(hawtioDomain, notNullValue()); assertThat(hawtioDomain.get("type=security,name=RBACRegistry"), notNullValue()); }