test_class.file: authentication/identity-store/identity-store-readonly/src/test/java/javax/security/identitystore/persistence/JaasIdentityStoreTest.java
test_class.identifier: JaasIdentityStoreTest
test_case.body: @Test
      public void validateUsernamePassword() throws IOException {
  
          // Need a principal resolver
          JaasTestArtifacts.TestJaasSubjectPrincipalResolver resolver = new JaasTestArtifacts.TestJaasSubjectPrincipalResolver();
  
          // Need a JAAS config
          Configuration config = new JaasTestArtifacts.TestConfiguration();
  
          // Instantiate the store with a selected config entry name
          JaasIdentityStore store = new JaasIdentityStore(JaasTestArtifacts.CONFIG_ENTRY_NAME, config, resolver );
  
          // Validate credentials
          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: JaasIdentityStoreTest.validateUsernamePassword()
test_case.full_signature: @Test public void validateUsernamePassword()
test_case.identifier: validateUsernamePassword
test_case.invocations: 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: appConfigurationEntryName
focal_class.modifier: final private
focal_class.original_string: final private String appConfigurationEntryName;
focal_class.type: String
focal_class.var_name: appConfigurationEntryName
focal_class.declarator: configuration
focal_class.modifier: final private
focal_class.original_string: final private Configuration configuration;
focal_class.type: Configuration
focal_class.var_name: configuration
focal_class.declarator: jaasSubjectPrincipalResolver
focal_class.modifier: final private
focal_class.original_string: final private JaasSubjectPrincipalResolver jaasSubjectPrincipalResolver;
focal_class.type: JaasSubjectPrincipalResolver
focal_class.var_name: jaasSubjectPrincipalResolver
focal_class.file: authentication/identity-store/identity-store-readonly/src/main/java/javax/security/identitystore/persistence/JaasIdentityStore.java
focal_class.identifier: JaasIdentityStore
focal_class.class_method_signature: JaasIdentityStore.JaasIdentityStore(
          String appConfigurationEntryName,
          Configuration configuration,
          JaasSubjectPrincipalResolver jaasSubjectPrincipalResolver)
focal_class.full_signature: public  JaasIdentityStore(
          String appConfigurationEntryName,
          Configuration configuration,
          JaasSubjectPrincipalResolver jaasSubjectPrincipalResolver)
focal_class.identifier: JaasIdentityStore
focal_class.modifiers: public
focal_class.parameters: (
          String appConfigurationEntryName,
          Configuration configuration,
          JaasSubjectPrincipalResolver jaasSubjectPrincipalResolver)
focal_class.signature:  JaasIdentityStore(
          String appConfigurationEntryName,
          Configuration configuration,
          JaasSubjectPrincipalResolver jaasSubjectPrincipalResolver)
focal_class.class_method_signature: JaasIdentityStore.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: JaasIdentityStore.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.class_method_signature: JaasIdentityStore.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.superclass: extends AbstractIdentityStore
focal_method.body: @Override
      protected CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential) {
  
          final CallbackHandler callbackHandler = callbacks -> {
              for (final Callback callback : callbacks) {
                  if (callback instanceof NameCallback) {
                      ((NameCallback) callback).setName(usernamePasswordCredential.getCaller());
  
                  } else if (callback instanceof PasswordCallback) {
                      ((PasswordCallback) callback).setPassword(usernamePasswordCredential.getPassword().getValue());
  
                  } else {
                      throw new UnsupportedCallbackException(callback);
                  }
              }
          };
  
          LoginContext loginContext = null;
          Subject subject = null;
          String caller = null;
          List<String> groups = null;
          List<String> roles = null;
          try {
              // Initialize the LoginContext
              loginContext = new LoginContext(appConfigurationEntryName, new Subject(), callbackHandler, configuration);
  
              // this will properly instantiate the login module and authenticate the user
              loginContext.login();
  
              // at the end of the authentication, the subject should contain the principals
              subject = loginContext.getSubject();
              if (null == subject)
                  throw new IllegalStateException("Null Subject");
  
              // Resolve principals
              caller = jaasSubjectPrincipalResolver.getCaller(subject);
              groups = jaasSubjectPrincipalResolver.getCallerGroups(subject, caller);
              roles = jaasSubjectPrincipalResolver.getCallerRoles(subject, caller);
  
          } catch (LoginException e) {
              // TODO: Logging
              e.printStackTrace();
  
              System.out.println("Login invalid: " + e.getMessage());
              return CredentialValidationResult.INVALID_RESULT;
          } catch (Exception e) {
              // TODO: Logging
              System.out.println("Login not validated: " + e.getMessage());
              return CredentialValidationResult.NOT_VALIDATED_RESULT;
          } finally {
              try {
                  if (null != loginContext) {
                      loginContext.logout();
                  }
              } catch (Exception e) {
                  // TODO: Logging
                  System.out.println("Logout exception: " + e.getMessage());
              }
          }
  
          return new CredentialValidationResult(CredentialValidationResult.Status.VALID, caller, groups, roles);
      }
focal_method.class_method_signature: JaasIdentityStore.validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_method.full_signature: @Override protected CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_method.identifier: validateUsernamePassword
focal_method.invocations: setName getCaller setPassword getValue getPassword login getSubject getCaller getCallerGroups getCallerRoles printStackTrace println getMessage println getMessage logout println getMessage
focal_method.modifiers: @Override protected
focal_method.parameters: (UsernamePasswordCredential usernamePasswordCredential)
focal_method.return: CredentialValidationResult
focal_method.signature: CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)