LdapIdentityStore extends AbstractIdentityStore { @Override protected CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential) { final String caller = usernamePasswordCredential.getCaller(); LdapContext authCtx = null; try { Hashtable<String, Object> env = new Hashtable<String, Object>(contextEnv); String principalDn = formatDn(caller); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, principalDn); env.put(Context.SECURITY_CREDENTIALS, new String(usernamePasswordCredential.getPassword().getValue())); env.put("com.sun.jndi.ldap.connect.pool", "false"); authCtx = new InitialLdapContext(env, null); return new CredentialValidationResult(CredentialValidationResult.Status.VALID, caller, this); } catch (Exception e) { System.out.println("Credential validation failed for caller " + caller); } finally { if (authCtx != null) { try { authCtx.close(); } catch (NamingException e) { } } } return CredentialValidationResult.INVALID_RESULT; } LdapIdentityStore(
        Hashtable<String, Object> contextEnvironment,
        LdapEntryMapping entryMapping); @Override List<String> getCallerGroups(String callerName); @Override List<String> getCallerRoles(String callerName);  }
@Test public void validateUsernamePassword() 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); assertEquals("validate", CredentialValidationResult.Status.VALID, store.validateUsernamePassword(new UsernamePasswordCredential("jsmith", new Password("welcome1"))).getStatus()); assertEquals("validate", CredentialValidationResult.Status.INVALID, store.validateUsernamePassword(new UsernamePasswordCredential("jsmith", new Password("badPassword"))).getStatus()); }