LdapIdentityStore extends AbstractIdentityStore { @Override public List<String> getCallerGroups(String callerName) { LdapContext ctx = null; try { Hashtable<String, Object> env = new Hashtable<String, Object>(contextEnv); env.put("com.sun.jndi.ldap.connect.pool", "false"); ctx = new InitialLdapContext(env, null); String callerDn = formatDn(callerName); Attributes attributes = ctx.getAttributes(callerDn, new String[]{entryMapping.getCallerMapping().getGroupAttribute()}); Attribute attribute = attributes.get(entryMapping.getCallerMapping().getGroupAttribute()); NamingEnumeration<?> values = attribute.getAll(); ArrayList<String> result = new ArrayList<>(); while (values.hasMore()) { String dn = (String)values.next(); LdapName ldapDN = new LdapName(dn); List<Rdn> rdns = ldapDN.getRdns(); Rdn mostSpecificRdn = rdns.get(rdns.size() - 1); result.add((String)mostSpecificRdn.getValue()); } return result; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { } } } } LdapIdentityStore(
        Hashtable<String, Object> contextEnvironment,
        LdapEntryMapping entryMapping); @Override List<String> getCallerGroups(String callerName); @Override List<String> getCallerRoles(String callerName);  }
@Test public void callerGroups() throws IOException { Hashtable<String, Object> env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap: env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=Admin"); env.put(Context.SECURITY_CREDENTIALS, "welcome1"); LdapEntryMapping mapping = new LdapEntryMapping(); mapping .getCallerMapping() .setDnPattern("uid={0},ou=people,ou=myrealm,dc=base_domain") .setGroupAttribute("wlsMemberOf"); LdapIdentityStore store = new LdapIdentityStore(env, mapping); List<String> groups = store.getCallerGroups("jsmith"); assertNotNull("Groups", groups); assertEquals("Groups count", 2, groups.size()); assertTrue("Deployers", groups.contains("Deployers")); assertTrue("Operators", groups.contains("Operators")); }