/** * 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; }
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 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); } } }
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 { 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; }
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();
@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); } } }
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();
private byte[] getPredigestedSaltedPassword() throws AuthenticationMechanismException { if (realmChoiceCallBack != null) { try { callbackHandler.handle(new Callback[]{ realmChoiceCallBack }); int[] selected = realmChoiceCallBack.getSelectedIndexes(); if (selected == null || selected.length == 0) { callbackHandler.handle(new Callback[]{ realmCallback }); if (realmCallback.getText() != null) realm = realmCallback.getText(); } catch (UnsupportedCallbackException e) { callbackHandler.handle(new Callback[]{ nameCallback }); if ( ! readOnlyRealmUsername) { username = nameCallback.getName(); if (username == null) { throw log.mechNotProvidedUserName();
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];
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; } }
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); } }
@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; }
private byte[] getSaltedPasswordFromTwoWay() throws AuthenticationMechanismException { if (realmChoiceCallBack != null) { try { callbackHandler.handle(new Callback[]{ realmChoiceCallBack }); int[] selected = realmChoiceCallBack.getSelectedIndexes(); if (selected == null || selected.length == 0) { callbackHandler.handle(new Callback[]{ realmCallback }); if (realmCallback.getText() != null) realm = realmCallback.getText(); } catch (UnsupportedCallbackException e) { char[] passwordChars = null; try { callbackHandler.handle(new Callback[]{ nameCallback, credentialCallback }); if ( ! readOnlyRealmUsername) { username = nameCallback.getName(); if (username == null) { throw log.mechNotProvidedUserName();
@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()); }
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; } }
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 handleNameCallback() throws Exception { NameCallback cb = new NameCallback("prompt"); callbackHandler.handle(new Callback[] {cb}); assertEquals("id", cb.getName()); }
final NameCallback nameCallback = new NameCallback("Username: "); final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false); try { handler.handle(new Callback[]{nameCallback, passwordCallback}); } catch (UnsupportedCallbackException e) { return NO_AUTHENTICATION_TOKEN; if (nameCallback.getName() != null && !nameCallback.getName().equals(AnonymousPrincipal.getInstance().getName())) { byte[] encodedTargetName = secMech.as_context_mech.target_name; String name = nameCallback.getName(); if (name.indexOf('@') < 0) { byte[] decodedTargetName = CSIv2Util.decodeGssExportedName(encodedTargetName); if (passwordCallback.getPassword() != null) password = new String(passwordCallback.getPassword()).getBytes(StandardCharsets.UTF_8);