public ConnectionProxy connect(Properties info) throws SQLException { this.properties = info; PasswordCallback passwordCallback = this.config.getPasswordCallback(); if (passwordCallback != null) { char[] chars = passwordCallback.getPassword(); String password = new String(chars); info.put("password", password); } NameCallback userCallback = this.config.getUserCallback(); if (userCallback != null) { String user = userCallback.getName(); info.put("user", user); } FilterChain chain = new FilterChainImpl(this); return chain.connection_connect(info); }
@Override public boolean login() throws LoginException { succeeded = true; if (credentialsInvalidate) { PasswordCallback passwordCallback = new PasswordCallback("Password: ", false); try { callbackHandler.handle(new Callback[]{passwordCallback}); if (passwordCallback.getPassword() != null) { if (debug) { LOG.debug("Guest login failing (credentialsInvalidate=true) on presence of a password"); } succeeded = false; passwordCallback.clearPassword(); }; } catch (IOException ioe) { } catch (UnsupportedCallbackException uce) { } } if (debug) { LOG.debug("Guest login " + succeeded); } return succeeded; }
@Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { try { NameCallback nameCallback = new NameCallback("name:"); PasswordCallback passwordCallback = new PasswordCallback("password:", false); callbackHandler.handle(new Callback[]{nameCallback, passwordCallback}); subject.getPublicCredentials().add(nameCallback.getName()); subject.getPrivateCredentials().add(new String(passwordCallback.getPassword())); } catch (Exception e) { throw new SaslAuthenticationException("Login initialization failed", e); } } }
/** * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword() */ @Override protected String getUsersPassword() throws LoginException { if (validationMode == ValidationMode.VALIDATION) { return null; } RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); String password = null; switch (validationMode) { case DIGEST: CredentialCallback cc = new CredentialCallback(PasswordCredential.class, ALGORITHM_DIGEST_MD5); handle(new Callback[]{rcb, ncb, cc}); PasswordCredential passwordCredential = (PasswordCredential) cc.getCredential(); DigestPassword digestPassword = passwordCredential.getPassword(DigestPassword.class); password = ByteIterator.ofBytes(digestPassword.getDigest()).hexEncode().drainToString(); break; case PASSWORD: PasswordCallback pcb = new PasswordCallback("Password", false); handle(new Callback[]{rcb, ncb, pcb}); password = String.valueOf(pcb.getPassword()); break; } return password; }
final PasswordCallback passwordCallback = new PasswordCallback("User password", false); final char[] password = passwordCallback.getPassword(); if (password != null) { if (matchParameters != null) {
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("User name"); callbacks[1] = new PasswordCallback("Password", false); try { handler.handle(callbacks); } catch (IOException ioe) { throw (LoginException)new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException)new LoginException().initCause(uce); } String password; String username = ((NameCallback)callbacks[0]).getName(); if (username == null) return false; if (((PasswordCallback)callbacks[1]).getPassword() != null) password = new String(((PasswordCallback)callbacks[1]).getPassword()); else password=""; // authenticate will throw LoginException // in case of failed authentication authenticate(username, password); user = new UserPrincipal(username); succeeded = true; return true; }
public <C extends Credential> C getCredential(final Class<C> credentialType, final String algorithmName, final AlgorithmParameterSpec parameterSpec) throws IOException { if (PasswordCredential.class.isAssignableFrom(credentialType) && (algorithmName == null || algorithmName.equals(ClearPassword.ALGORITHM_CLEAR)) && parameterSpec == null) { try { final PasswordCallback passwordCallback = new PasswordCallback("Password", false); callbackHandler.handle(new Callback[] { passwordCallback }); final char[] chars = passwordCallback.getPassword(); return chars == null ? null : credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, chars))); } catch (UnsupportedCallbackException e) { // fall out and try CredentialCallback } } try { final CredentialCallback credentialCallback = new CredentialCallback(credentialType, algorithmName, parameterSpec); callbackHandler.handle(new Callback[] { credentialCallback }); return credentialCallback.getCredential(credentialType, algorithmName, parameterSpec); } catch (UnsupportedCallbackException e) { // no credentials can be acquired; fall out } return null; } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { String username = null; String password = null; AuthorizeCallback ac = null; for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; username = nc.getName(); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; password = new String(pc.getPassword()); } else if (callback instanceof AuthorizeCallback) { ac = (AuthorizeCallback) callback; } else { throw new UnsupportedCallbackException(callback); } } PasswdAuthenticationProvider provider = AuthenticationProviderFactory.getAuthenticationProvider(authMethod); provider.Authenticate(username, password); if (ac != null) { ac.setAuthorized(true); } } }
: PASSWORD_FORMAT_TYPES[passwordFormatTypeChoiceCallback.getDefaultChoice()]; PasswordCallback passwordCallback = new PasswordCallback(NEW_PASSWORD_PROMPT, false); switch (newPasswordFormatType) { case PASS_PHRASE: final char[] newPassPhraseChars = passwordCallback.getPassword(); passwordCallback.clearPassword(); if (newPassPhraseChars != null) {
Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("Username: "); callbacks[1] = new PasswordCallback("Password: ", false); try { callbackHandler.handle(callbacks); } catch (IOException ioe) { throw new LoginException(ioe.getMessage()); throw new LoginException(uce.getMessage() + " not available to obtain information from user"); user = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { tmpPassword = new char[0];
static char[] getPasswordFromCallBack(KeyStore.ProtectionParameter protParam) throws UnrecoverableEntryException { if (protParam == null) { return null; } if (!(protParam instanceof KeyStore.CallbackHandlerProtection)) { throw new UnrecoverableEntryException("Incorrect ProtectionParameter"); } String clName = Security.getProperty("auth.login.defaultCallbackHandler"); if (clName == null) { throw new UnrecoverableEntryException("Default CallbackHandler was not defined"); } try { Class<?> cl = Class.forName(clName); CallbackHandler cbHand = (CallbackHandler) cl.newInstance(); PasswordCallback[] pwCb = { new PasswordCallback("password: ", true) }; cbHand.handle(pwCb); return pwCb[0].getPassword(); } catch (Exception e) { throw new UnrecoverableEntryException(e.toString()); } } }
private static void log(String type, AuthorizeCallback ac, NameCallback nc, PasswordCallback pc, RealmCallback rc) { if (LOG.isDebugEnabled()) { String acs = "null"; if (ac != null) { acs = "athz: " + ac.getAuthorizationID() + " athn: " + ac.getAuthenticationID() + " authorized: " + ac.getAuthorizedID(); } String ncs = "null"; if (nc != null) { ncs = "default: " + nc.getDefaultName() + " name: " + nc.getName(); } String pcs = "null"; if (pc != null) { char[] pwd = pc.getPassword(); pcs = "password: " + (pwd == null ? "null" : "not null " + pwd.length); } String rcs = "null"; if (rc != null) { rcs = "default: " + rc.getDefaultText() + " text: " + rc.getText(); } LOG.debug("{}\nAC: {}\nNC: {}\nPC: {}\nRC: {}", type, acs, ncs, pcs, rcs); } }
@Test public void handlePasswordCallback() throws Exception { PasswordCallback cb = new PasswordCallback("prompt", false); callbackHandler.handle(new Callback[] {cb}); assertArrayEquals(simpleCreds.getPassword(), cb.getPassword()); }
@Override public DirContext obtainDirContext(CallbackHandler handler, ReferralMode mode) throws NamingException { NameCallback nameCallback = new NameCallback("Principal Name"); PasswordCallback passwordCallback = new PasswordCallback("Password", false); try { handler.handle(new Callback[] {nameCallback, passwordCallback}); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); } String securityPrincipal = nameCallback.getName(); if (securityPrincipal == null) { throw log.couldNotObtainPrincipal(); } char[] securityCredential = passwordCallback.getPassword(); if (securityCredential == null) { throw log.couldNotObtainCredential(); } return createDirContext(securityPrincipal, securityCredential, mode, getSocketFactory()); }
Security.addProvider(p); ks = KeyStore.getInstance("PKCS11",p); pcb = new PasswordCallback("PKCS11 Password: ",false); callbackHandler.handle(new Callback[] {pcb}); ks.load(null,pcb.getPassword()); if (callbackHandler != null && StringUtils.isNotEmpty(keystorePath)) { try { pcb = new PasswordCallback("Keystore Password: ", false); callbackHandler.handle(new Callback[] { pcb }); ks.load(new FileInputStream(keystorePath), pcb.getPassword()); kmf.init(ks, pcb.getPassword()); pcb.clearPassword();
private void validateCallbacks(String user, String passwd, Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback cb : callbacks) { if (cb instanceof NameCallback) { assertEquals(user, ((NameCallback) cb).getName()); } else if (cb instanceof PasswordCallback) { char[] passwordChar = ((PasswordCallback) cb).getPassword(); assertEquals(passwd, passwordChar == null ? null : String.copyValueOf(passwordChar)); } } } }
@Test public void handlePasswordCallback2() throws Exception { PasswordCallback cb = new PasswordCallback("prompt", false); create(new Credentials() {}).handle(new Callback[]{cb}); assertNull(cb.getPassword()); }
/** * Creates a new {@link OAuth2CredentialSource} instance. * * @return a OAuth2 credential source */ public OAuth2CredentialSource build() { if (authenticationHandler == null) { authenticationHandler = parameters -> { AuthenticationContext context = AuthenticationContext.captureCurrent(); AuthenticationContextConfigurationClient client = AccessController.doPrivileged(AuthenticationContextConfigurationClient.ACTION); AuthenticationConfiguration configuration = client.getAuthenticationConfiguration(URI.create(tokenEndpointUrl.toString()), context); CallbackHandler handler = client.getCallbackHandler(configuration); NameCallback nameCallback = new NameCallback("Client ID"); PasswordCallback password1 = new PasswordCallback("Client Secret", false); try { handler.handle(new Callback[]{nameCallback, password1}); } catch (Exception ignore) { } String userName = nameCallback.getName(); char[] password = password1.getPassword(); configureClientCredentialsParameters(parameters, userName, password); }; } return new OAuth2CredentialSource(tokenEndpointUrl, authenticationHandler.andThen(parameters -> { if (!parameters.containsKey("client_id") || !parameters.containsKey("client_secret")) { throw saslOAuth2.oauth2ClientCredentialsNotProvided(); } }), scopes, sslContextSupplier, hostnameVerifierSupplier); }
PasswordCallback pwdcb = new PasswordCallback(GT.tr("Enter SSL password: "), false); try { cbh.handle(new Callback[]{pwdcb}); } catch (UnsupportedCallbackException ucex) { if ((cbh instanceof LibPQFactory.ConsoleCallbackHandler) PBEKeySpec pbeKeySpec = new PBEKeySpec(pwdcb.getPassword()); pwdcb.clearPassword();
if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; username = nc.getName(); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; password = new String(pc.getPassword()); } else if (callback instanceof AuthorizeCallback) { ac = (AuthorizeCallback) callback;