@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); } } }
NameCallback nc = new NameCallback("SASL PLAIN"); nc.setName(parts[1]); PasswordCallback pc = new PasswordCallback("SASL PLAIN", false); pc.setPassword(parts[2].toCharArray()); AuthorizeCallback ac = new AuthorizeCallback(parts[1], parts[0]); cbh.handle(new Callback[]{ nc, pc, ac }); if (ac.isAuthorized()) { authz = ac.getAuthorizedID();
public Callback[] configureCallbacks () { Callback[] callbacks = new Callback[3]; callbacks[0] = new NameCallback("Enter user name"); callbacks[1] = new ObjectCallback(); callbacks[2] = new PasswordCallback("Enter password", false); //only used if framework does not support the ObjectCallback return callbacks; }
/** * @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; }
NameCallback nameCallback = new NameCallback("User"); nameCallback.setName(authenticationId); PasswordCallback passwordCallback = new PasswordCallback("Password", false); passwordCallback.setPassword(passwd.toCharArray()); AuthorizeCallback authCallback = new AuthorizeCallback(authenticationId, authorizationId); mHandler.handle(cbList); if (!authCallback.isAuthorized()) { throw new SaslException("AuthorizeCallback authorized failure");
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 boolean login() throws LoginException { final NameCallback nameCb = new NameCallback("Enter user: "); final PasswordCallback passCb = new PasswordCallback("Enter user password: ", false); return login(nameCb, passCb); }
: 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];
NameCallback nc = new NameCallback("SASL PLAIN"); nc.setName(parts[1]); PasswordCallback pc = new PasswordCallback("SASL PLAIN", false); pc.setPassword(parts[2].toCharArray()); AuthorizeCallback ac = new AuthorizeCallback(parts[1], parts[0]); cbh.handle(new Callback[]{nc, pc, ac}); if (ac.isAuthorized()) { authz = ac.getAuthorizedID();
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()); } } }
public Callback[] configureCallbacks () { Callback[] callbacks = new Callback[3]; callbacks[0] = new NameCallback("Enter user name"); callbacks[1] = new ObjectCallback(); callbacks[2] = new PasswordCallback("Enter password", false); //only used if framework does not support the ObjectCallback return callbacks; }
@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()); }
/** * Tests that the authentication callbacks matches. */ @Test public void authenticateNameMatch() throws Exception { String authenticateId = "alluxio-1"; NameCallback ncb = new NameCallback(" authentication id: "); ncb.setName(authenticateId); PasswordCallback pcb = new PasswordCallback(" password: ", false); pcb.setPassword("password".toCharArray()); Callback[] callbacks = new Callback[] {ncb, pcb, new AuthorizeCallback(authenticateId, authenticateId)}; mPlainServerCBHandler.handle(callbacks); }
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();
@Override public boolean login() throws LoginException { final NameCallback nameCb = new NameCallback("Enter user: "); final PasswordCallback passCb = new PasswordCallback("Enter user password: ", false); return login(nameCb, passCb); }