test_class.file: authentication/identity-store/identity-store-readonly/src/test/java/javax/security/identitystore/persistence/LdapIdentityStoreTest.java
test_class.identifier: LdapIdentityStoreTest
test_case.body: @Test
      public void  validateUsernamePassword() throws IOException {
  
          // Test with locally installed LDAP
  
          // Set up the environment for creating the initial context
          Hashtable<String, Object> env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, "ldap://localhost:7001");
  
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          env.put(Context.SECURITY_PRINCIPAL, "cn=Admin");
          env.put(Context.SECURITY_CREDENTIALS, "welcome1");
  
  
          // LDAP entry mapping
          LdapEntryMapping mapping = new LdapEntryMapping();
          mapping
              .getCallerMapping()
                  .setDnPattern("uid={0},ou=people,ou=myrealm,dc=base_domain")
                  .setGroupAttribute("wlsMemberOf");
  
          // Instantiate store
          LdapIdentityStore store = new LdapIdentityStore(env, mapping);
  
          // Test validation
          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());
  
      }
test_case.class_method_signature: LdapIdentityStoreTest.validateUsernamePassword()
test_case.full_signature: @Test public void validateUsernamePassword()
test_case.identifier: validateUsernamePassword
test_case.invocations: put put put put put setGroupAttribute setDnPattern getCallerMapping assertEquals getStatus validateUsernamePassword assertEquals getStatus validateUsernamePassword
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void validateUsernamePassword()
focal_class.declarator: contextEnv
focal_class.modifier: final private
focal_class.original_string: final private Hashtable<String, Object> contextEnv;
focal_class.type: Hashtable<String, Object>
focal_class.var_name: contextEnv
focal_class.declarator: entryMapping
focal_class.modifier: final private
focal_class.original_string: final private LdapEntryMapping entryMapping;
focal_class.type: LdapEntryMapping
focal_class.var_name: entryMapping
focal_class.file: authentication/identity-store/identity-store-readonly/src/main/java/javax/security/identitystore/persistence/LdapIdentityStore.java
focal_class.identifier: LdapIdentityStore
focal_class.class_method_signature: LdapIdentityStore.LdapIdentityStore(
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.full_signature: public  LdapIdentityStore(
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.identifier: LdapIdentityStore
focal_class.modifiers: public
focal_class.parameters: (
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.signature:  LdapIdentityStore(
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.class_method_signature: LdapIdentityStore.formatDn(String caller)
focal_class.full_signature:  String formatDn(String caller)
focal_class.identifier: formatDn
focal_class.parameters: (String caller)
focal_class.return: String
focal_class.signature: String formatDn(String caller)
focal_class.class_method_signature: LdapIdentityStore.validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_class.full_signature: @Override protected CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_class.identifier: validateUsernamePassword
focal_class.modifiers: @Override protected
focal_class.parameters: (UsernamePasswordCredential usernamePasswordCredential)
focal_class.return: CredentialValidationResult
focal_class.signature: CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_class.class_method_signature: LdapIdentityStore.getCallerGroups(String callerName)
focal_class.full_signature: @Override public List<String> getCallerGroups(String callerName)
focal_class.identifier: getCallerGroups
focal_class.modifiers: @Override public
focal_class.parameters: (String callerName)
focal_class.return: List<String>
focal_class.signature: List<String> getCallerGroups(String callerName)
focal_class.class_method_signature: LdapIdentityStore.getCallerRoles(String callerName)
focal_class.full_signature: @Override public List<String> getCallerRoles(String callerName)
focal_class.identifier: getCallerRoles
focal_class.modifiers: @Override public
focal_class.parameters: (String callerName)
focal_class.return: List<String>
focal_class.signature: List<String> getCallerRoles(String callerName)
focal_class.superclass: extends AbstractIdentityStore
focal_method.body: @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()));
  
              // Never use connection pool to prevent password caching
              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) {
              // TODO: Add logging
              System.out.println("Credential validation failed for caller " + caller);
          } finally {
              if (authCtx != null) {
                  try {
                      authCtx.close();
                  } catch (NamingException e) {
                  }
              }
          }
          return CredentialValidationResult.INVALID_RESULT;
      }
focal_method.class_method_signature: LdapIdentityStore.validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_method.full_signature: @Override protected CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_method.identifier: validateUsernamePassword
focal_method.invocations: getCaller formatDn put put put getValue getPassword put println close
focal_method.modifiers: @Override protected
focal_method.parameters: (UsernamePasswordCredential usernamePasswordCredential)
focal_method.return: CredentialValidationResult
focal_method.signature: CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)