code: @Override
      public LoginContext createLoginContext(Subject subject, final String username, final char[] password) throws LoginException {
          final DefaultLoginResult loginResult = new DefaultLoginResult();
  
          CallbackHandler handler = new CallbackHandler() {
              @Override
              public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  
                  for (Callback callback : callbacks) {
                      if (callback instanceof NameCallback) {
                          ((NameCallback) callback).setName(username);
                      } else if (callback instanceof PasswordCallback) {
                          ((PasswordCallback) callback).setPassword(password);
                      } else if (callback instanceof LoginResultCallback) {
                          ((LoginResultCallback) callback).setLoginResult(loginResult);
                      } else {
                          throw new UnsupportedCallbackException(callback);
                      }
                  }
              }
          };
  
          // use JAAS to login and establish subject principals
          return createLoginContext(subject, handler, loginResult);
      }
docs: For login context providers that can abstract their tokens into a username and password,
  this is a utility method that can create the login context based on the provided username and password.
  
  @param subject  the subject that has been created for the user, or <code>null</code> if none has been created.
  @param username the presented user name
  @param password the presented password
  @return a login context based on the parameters
  @throws LoginException when a login context cannot be created