Source:
protected PasswordAuthentication getPasswordAuthentication() { final AuthenticationContext context = AuthenticationContext.captureCurrent(); final AuthenticationConfiguration authenticationConfiguration; try { authenticationConfiguration = client.getAuthenticationConfiguration(getRequestingURL().toURI(), context); } catch (URISyntaxException e) { return null; } if (authenticationConfiguration == null) return null; final CallbackHandler callbackHandler = client.getCallbackHandler(authenticationConfiguration); final NameCallback nameCallback = new NameCallback(getRequestingPrompt()); final CredentialCallback credentialCallback = new CredentialCallback(PasswordCredential.class); char[] password = null; try { callbackHandler.handle(new Callback[] { nameCallback, credentialCallback }); final TwoWayPassword twoWayPassword = credentialCallback.applyToCredential(PasswordCredential.class, c -> c.getPassword().castAs(TwoWayPassword.class)); if (twoWayPassword == null) { return null; } final PasswordFactory factory = PasswordFactory.getInstance(twoWayPassword.getAlgorithm()); final ClearPasswordSpec keySpec = factory.getKeySpec(twoWayPassword, ClearPasswordSpec.class); password = keySpec.getEncodedPassword(); } catch (UnsupportedCallbackException e) { if (e.getCallback() == credentialCallback) { final PasswordCallback passwordCallback = new PasswordCallback("Password", false); try { callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); password = passwordCallback.getPassword(); } catch (IOException | UnsupportedCallbackException e1) { return null; } } } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException e) { if (e instanceof InvalidKeySpecException) { final PasswordCallback passwordCallback = new PasswordCallback("Password", false); try { callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); password = passwordCallback.getPassword(); } catch (IOException | UnsupportedCallbackException e1) { return null; } } else { return null; } } final String name = nameCallback.getName(); if (name == null || password == null) return null; return new PasswordAuthentication(name, password); }

Target:
protected PasswordAuthentication getPasswordAuthentication() { final AuthenticationContext context = AuthenticationContext.captureCurrent(); final AuthenticationConfiguration authenticationConfiguration; try { authenticationConfiguration = client.getAuthenticationConfiguration(getRequestingURL().toURI(), context); } catch (URISyntaxException e) { return null; } if (authenticationConfiguration == null) return null; final CallbackHandler callbackHandler = client.getCallbackHandler(authenticationConfiguration); final NameCallback nameCallback = new NameCallback(getRequestingPrompt()); final CredentialCallback credentialCallback = new CredentialCallback(PasswordCredential.class); char[] password = null; try { callbackHandler.handle(new Callback[] { nameCallback, credentialCallback }); final TwoWayPassword twoWayPassword = credentialCallback.applyToCredential(PasswordCredential.class, c -> c.getPassword().castAs(TwoWayPassword.class)); if (twoWayPassword == null) { return null; } final PasswordFactory factory = PasswordFactory.getInstance(twoWayPassword.getAlgorithm()); final ClearPasswordSpec keySpec = factory.getKeySpec(twoWayPassword, ClearPasswordSpec.class); password = keySpec.getEncodedPassword(); } catch (UnsupportedCallbackException e) { if (e.getCallback() == credentialCallback) { final PasswordCallback passwordCallback = new PasswordCallback("Password", false); try { callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); password = passwordCallback.getPassword(); } catch (IOException | UnsupportedCallbackException e1) { return null; } } } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException e) { return null; } final String name = nameCallback.getName(); if (name == null || password == null) return null; return new PasswordAuthentication(name, password); }