GroupAdapterAuthorizationSource { protected List<String> collectEntitiesFromSubject(String username, Subject subject, String[] rolePrincipleNames) { if (null == subject) { return null; } List<String> roles = new ArrayList<>(); try { Set<java.security.Principal> principals = subject.getPrincipals(); if (principals != null) { for (java.security.Principal p : principals) { if (p instanceof BasicAuthorizationPrincipal) { continue; } if (p instanceof java.security.acl.Group) { for (final String rolePrincipleName : rolePrincipleNames) { if (rolePrincipleName.equalsIgnoreCase(p.getName())) { Enumeration<? extends java.security.Principal> groups = ((java.security.acl.Group) p).members(); while (groups.hasMoreElements()) { final java.security.Principal groupPrincipal = groups.nextElement(); roles.add(groupPrincipal.getName()); } } } } else { roles.add(p.getName()); } } } } catch (Exception e) { throw new RuntimeException(e); } return roles; } GroupAdapterAuthorizationSource();   }
@Test public void skipBasicAuthorizationPrincipalTest() { Set<Principal> principals = new HashSet<>(); principals.add(new JMXPrincipal("admin")); principals.add(new BasicAuthorizationPrincipal("analyst")); principals.add(new JMXPrincipal("developer")); Subject subject = new Subject(true, principals, Collections.emptySet(), Collections.emptySet()); List<String> entities = adapter.collectEntitiesFromSubject("admin", subject, new String[0]); assertEquals(2, entities.size()); assertEquals("admin", entities.get(0)); assertEquals("developer", entities.get(1)); }