code: private static Account authenticate(String userName, String storedPassword, String clientDigest, String nOnce, String nc,
              String cnonce, String method, String uri, String qop, String realmName, String md5a2, Deployment deployment,
              boolean storedPasswordIsA1Hash) {
  
          CallbackHandlerPolicyContextHandler.setCallbackHandler(new DigestCallbackHandler(userName, nOnce, nc, cnonce, qop,
                  realmName, md5a2));
  
          String serverDigest = "";
          if (storedPasswordIsA1Hash) {
              // storedPassword is HA1 in this case
              serverDigest = MessageDigestResponseAlgorithm.calculateResponse(md5Helper.getAlgorithm(), storedPassword, nOnce,
                      nc, cnonce, method, uri, "", qop);
          } else {
              serverDigest = MessageDigestResponseAlgorithm.calculateResponse(md5Helper.getAlgorithm(), userName, realmName,
                      storedPassword, nOnce, nc, cnonce, method, uri, "", qop);
          }
  
          if (serverDigest.equals(clientDigest)) {
              // lest's reauth with stored password (to force successful authentication) to make wildfly to create Account and
              // Principal for us
              // this is because wildfly bug: https://issues.jboss.org/browse/WFLY-3659
              final IdentityManager identityManager = deployment.getDeploymentInfo().getIdentityManager();
              PasswordCredential credential = new PasswordCredential(storedPassword.toCharArray());
              Account account = identityManager.verify(userName, credential);
  
              return account;
          }
          return null;
      }
docs: /*
  Return the Account associated with the specified username, which matches the digest calculated using the given parameters
  using the method described in rfc2617; otherwise return null.
  
  @param userName Username of the Principal to look up
  
  @param storedPassword
  
  @param clientDigest Digest which has been submitted by the client
  
  @param nOnce Unique (or supposedly unique) token which has been used for this request
  
  @param nc
  
  @param cnonce
  
  @param method
  
  @param uri
  
  @param qop
  
  @param realmName Realm name
  
  @param md5a2 Second MD5 digest used to calculate the digest : MD5(Method + ":" + uri)
  
  @param deployment
  
  @param storedPasswordIsA1Hash