/** * Retrieves the user name by querying the property of * {@link PropertyKey#SECURITY_LOGIN_USERNAME} through {@link AppCallbackHandler}. * * @return true if user name provided by application is set and not empty * @throws LoginException when the login fails */ @Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[1]; callbacks[0] = new NameCallback("user name: "); try { mCallbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new LoginException(e.getMessage()); } String userName = ((NameCallback) callbacks[0]).getName(); if (!userName.isEmpty()) { mUser = new User(userName); return true; } return false; }
@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();
protected Object getCredential() throws LoginException { NameCallback nc = new NameCallback("Alias: "); ObjectCallback oc = new ObjectCallback("Credential: "); Callback[] callbacks = { nc, oc }; try { callbackHandler.handle(callbacks); return oc.getCredential(); } catch (IOException ioe) { LoginException le = new LoginException(); le.initCause(ioe); throw le; } catch (UnsupportedCallbackException uce) { LoginException le = new LoginException(); le.initCause(uce); throw le; } }
/** * @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; }
throw saslAnonymous.mechInvalidServerMessage().toSaslException(); NameCallback nameCallback = new NameCallback("Authentication name", "anonymous"); handleCallbacks(nameCallback); String name = nameCallback.getName(); if (name == null) { throw saslAnonymous.mechNotProvidedUserName().toSaslException();
@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); }
@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");
AuthenticationConfiguration configuration = authClient.getAuthenticationConfiguration(uri, authenticationContext, 0, null, null); NameCallback nameCallback = new NameCallback("LDAP principal"); CredentialCallback credentialCallback = new CredentialCallback(PasswordCredential.class, ClearPassword.ALGORITHM_CLEAR); try { authClient.getCallbackHandler(configuration).handle(new Callback[]{nameCallback, credentialCallback}); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); securityPrincipal = nameCallback.getName(); PasswordCredential credential = credentialCallback.getCredential(PasswordCredential.class); if (credential == null) throw log.couldNotObtainCredential();
NameCallback nameCallback = new NameCallback("username", username); PlainAuthenticateCallback authenticateCallback = new PlainAuthenticateCallback(password.toCharArray()); try { callbackHandler.handle(new Callback[]{nameCallback, authenticateCallback}); } catch (Throwable e) { throw new SaslAuthenticationException("Authentication failed: credentials for user could not be verified", e);
new NameCallback("User name") : new NameCallback("User name", authorizationId); try { MechanismUtil.handleCallbacks(saslScram, callbackHandler, nameCallback); throw saslScram.mechCallbackHandlerDoesNotSupportUserName(e); final String name = nameCallback.getName(); if (name == null) { throw saslScram.mechNoLoginNameGiven();
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; }
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();
private String getUsername(CallbackHandler handler) { if (handler == null) { return null; } try { NameCallback usernameCallBack = new NameCallback("user"); handler.handle(new Callback[]{usernameCallBack }); return usernameCallBack.getName(); } catch (Exception e) { return null; } }
NameCallback ncb = new NameCallback("PLAIN authentication ID: ",principal); VerifyPasswordCallback vpcb = new VerifyPasswordCallback(password.toCharArray()); cbh.handle(new Callback[]{ncb,vpcb}); cbh.handle(new Callback[]{acb}); if(acb.isAuthorized()) { username = acb.getAuthorizedID();
@Override public byte[] evaluateResponse(byte[] response) throws SaslException { NameCallback nc = new NameCallback("ANONYMOUS identity", UUID.randomUUID().toString()); handleCallbacks(nc); this.authorizedId = nc.getName() != null ? nc.getName() : nc.getDefaultName(); if (this.authorizedId == null) { throw new XmppSaslException(SaslError.temporary_auth_failure); } complete = true; 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); }
@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()); }