public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback c: callbacks) { if (c instanceof NameCallback) { ((NameCallback) c).setName(username); } else if (c instanceof PasswordCallback) { ((PasswordCallback) c).setPassword(password.toCharArray()); } else if (c instanceof KeyChoiceCallback) { KeyChoiceCallback kcc = (KeyChoiceCallback)c; try { int idx = kcc.lookupKey(key); kcc.setSelectedIndex(idx); } catch (IllegalArgumentException e) { throw new MissingCredsException(kcc); } } else { throw new UnsupportedCallbackException(c); } } }
@Override public boolean login() throws LoginException { final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)}; try { this.callbackHandler.handle(callbacks); } catch (final Exception e) { throw new LoginException(); } final String userName = ((NameCallback) callbacks[0]).getName(); final String password = new String(((PasswordCallback) callbacks[1]).getPassword()); if ("test".equals(userName) && "test".equals(password)) { return true; } throw new LoginException(); }
public void handle(Callback[] callbacks) throws UnsupportedCallbackException { boolean didSetName = false; boolean didSetPassword = false; for (Callback cb : callbacks) if (cb instanceof NameCallback) { ((NameCallback) cb).setName(u); didSetName = true; } else if (cb instanceof PasswordCallback) { ((PasswordCallback) cb).setPassword(p); didSetPassword = true; } else { throw new UnsupportedCallbackException(cb, "Unsupported Callback type: " + cb.getClass().getName()); } if (!didSetName) throw new IllegalStateException( "Supplied Callbacks does not include a NameCallback"); if (!didSetPassword) throw new IllegalStateException("Supplied Callbacks " + "does not include a PasswordCallback"); }
@Override public void handle(final Callback[] callbacks) throws UnsupportedCallbackException { Arrays.stream(callbacks).filter(callback -> { if (callback.getClass().equals(NameCallback.class)) { ((NameCallback) callback).setName(this.userName); return false; } if (callback.getClass().equals(PasswordCallback.class)) { ((PasswordCallback) callback).setPassword(this.password.toCharArray()); return false; } return true; }).findFirst().ifPresent(callback -> { throw new RuntimeException(new UnsupportedCallbackException(callback, "Unrecognized Callback")); }); }
@Override protected Document process(Document document) throws WSSecurityException { WSSecurityEngine secEngine = new WSSecurityEngine(); WSHandlerResult results = secEngine.processSecurityHeader(document, null, new CallbackHandler() { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof WSPasswordCallback) { ((WSPasswordCallback)callback).setPassword(getCertPassword()); } } } }, getCrypto()); return document; }
public boolean login() throws LoginException { final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)}; try { this.callbackHandler.handle(callbacks); } catch (final Exception e) { throw new LoginException(); } final String userName = ((NameCallback) callbacks[0]).getName(); final String password = new String(((PasswordCallback) callbacks[1]).getPassword()); if (userName.equals("test") && password.equals("test")) { return true; } throw new LoginException(); }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { if (callbacks != null) { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName(username); } else if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword(password); } else { throw new UnsupportedCallbackException(callback); } } clearCredentials(); } }
/** * Retrieve or display the information requested in the provided Callbacks. * * @param callbacks * an array of <code>Callback</code> objects provided by an * underlying security service which contains the information * requested to be retrieved or displayed. * * @throws IOException * if an input or output error occurs. * * @throws UnsupportedCallbackException * if the implementation of this method does not support one or * more of the Callbacks specified in the <code>callbacks</code> * parameter. */ @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName(wsProxyInfo .getUserCredentials().getUser()); } else if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword(wsProxyInfo .getUserCredentials().getPassword().toCharArray()); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { System.out.println("Callback Handler - handle called"); for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { NameCallback nameCallback = (NameCallback) callbacks[i]; nameCallback.setName(name); } else if (callbacks[i] instanceof PasswordCallback) { PasswordCallback passwordCallback = (PasswordCallback) callbacks[i]; passwordCallback.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException(callbacks[i], "The submitted Callback is unsupported"); } } }
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback ncb = (NameCallback) callback; ncb.setName(username); } else if (callback instanceof PasswordCallback) { PasswordCallback pwcb = (PasswordCallback) callback; pwcb.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException( callback, "We got a " + callback.getClass().getCanonicalName() + ", but only NameCallback and PasswordCallback is supported"); } } }
@Test public void testSaslClientCallbackHandler() throws UnsupportedCallbackException { final Token<? extends TokenIdentifier> token = createTokenMock(); when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes()); when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes()); final NameCallback nameCallback = mock(NameCallback.class); final PasswordCallback passwordCallback = mock(PasswordCallback.class); final RealmCallback realmCallback = mock(RealmCallback.class); final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class); Callback[] callbackArray = {nameCallback, passwordCallback, realmCallback, realmChoiceCallback}; final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token); saslClCallbackHandler.handle(callbackArray); verify(nameCallback).setName(anyString()); verify(realmCallback).setText(anyString()); verify(passwordCallback).setPassword(any(char[].class)); }
public void handle(Callback[] callbacks) throws UnsupportedCallbackException, IOException { for (int i=0; i<callbacks.length; i++) { Callback callBack = callbacks[i]; if (callBack instanceof NameCallback) { getAnswer(); ((NameCallback)callBack).setName(username); } else if (callBack instanceof PasswordCallback) { getAnswer(); ((PasswordCallback)callBack).setPassword(password); if (password != null) Arrays.fill(password, ' '); } else { throw new UnsupportedCallbackException(callBack, "Call back not supported"); } } }
/** * Retrieve the information requested in the provided Callbacks. This * implementation only recognizes <code>NameCallback</code> and * <code>PasswordCallback</code> instances. * * @param callbacks The set of callbacks to be processed * * @exception IOException if an input/output error occurs * @exception UnsupportedCallbackException if the login method requests * an unsupported callback type */ public void handle(Callback callbacks[]) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { if (realm.getDebug() >= 3) realm.log("Returning username " + username); ((NameCallback) callbacks[i]).setName(username); } else if (callbacks[i] instanceof PasswordCallback) { if (realm.getDebug() >= 3) realm.log("Returning password " + password); ((PasswordCallback) callbacks[i]).setPassword (password.toCharArray()); } else { throw new UnsupportedCallbackException(callbacks[i]); } } }
@Override public ExchangeSession openSession(ExchangeLogin login) { ApiKeyCallback apiKey = new ApiKeyCallback(); ApiSecretCallback apiSecret = new ApiSecretCallback(); PasswordCallback password = new PasswordCallback("GDAX passphrase", false); Callback[] callbacks = new Callback[]{ apiKey, apiSecret, password }; CallbackHandler callbackHandler = login.getCallbackHandler(); try { callbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new RuntimeException(e); } String apiKeyTxt = apiKey.getApiKey(); char[] passphrase = password.getPassword(); SecretKeySpec keySpec = new SecretKeySpec(apiSecret.getSecretData(), "HmacSHA256"); return new GdaxExchangeSession(this, apiKeyTxt, keySpec, passphrase); }
@Override public CallbackHandler getCallbackHandler() { return callbacks -> { for (Callback cb : callbacks) { if (cb instanceof ApiKeyCallback) { ((ApiKeyCallback) cb).setApiKey(apiKey); } else if (cb instanceof ApiSecretCallback) { ((ApiSecretCallback) cb).setSecretData(apiSecret); } else if (cb instanceof PasswordCallback) { ((PasswordCallback) cb).setPassword(passphrase); } else { throw new UnsupportedCallbackException(cb); } } }; }
/** * Handles the callbacks; only supports {@link NameCallback} and {@link PasswordCallback}. * @throws UnsupportedCallbackException if an unsupported callback is encountered */ @Override public void handle(final Callback[] callbacks) throws UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName(username); } else if (callback instanceof PasswordCallback) { ((PasswordCallback) callback) .setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException (callback, "Unrecognized Callback"); } } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nameCallback = (NameCallback) callback; nameCallback.setName(nameCallback.getDefaultName()); } else if (callback instanceof PasswordCallback) { PasswordCallback passwordCallback = (PasswordCallback) callback; passwordCallback.setPassword(TestJaasConfig.PASSWORD.toCharArray()); } else if (callback instanceof RealmCallback) { RealmCallback realmCallback = (RealmCallback) callback; realmCallback.setText(realmCallback.getDefaultText()); } else if (callback instanceof AuthorizeCallback) { AuthorizeCallback authCallback = (AuthorizeCallback) callback; if (TestJaasConfig.USERNAME.equals(authCallback.getAuthenticationID())) { authCallback.setAuthorized(true); authCallback.setAuthorizedID(authCallback.getAuthenticationID()); } } } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; nc.setName(userName); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; pc.setPassword(password); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { System.out.println("TestCallbackHandler will get resolved through" + " auth.login.defaultCallbackHandler property."); for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName(USER_NAME); } else if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword( PASSWORD.toCharArray()); } else { throw new UnsupportedCallbackException(callback); } } }
@Override public boolean login() throws LoginException { if (debug) { logger.debug(this.getClass().getName() + " login called."); } if (Constants.FEDORA_HOME == null || "".equals(Constants.FEDORA_HOME.trim())) { logger.error("FEDORA_HOME constant is not set"); return false; } final NameCallback nc = new NameCallback("username"); final PasswordCallback pc = new PasswordCallback("password", false); final Callback[] callbacks = new Callback[] { nc, pc }; try { handler.handle(callbacks); } catch (IOException ioe) { ioe.printStackTrace(); throw new LoginException("IOException occured: " + ioe.getMessage()); } catch (UnsupportedCallbackException ucbe) { ucbe.printStackTrace(); throw new LoginException("UnsupportedCallbackException encountered: " + ucbe.getMessage()); } // Grab the username and password from the callbacks. final String username = nc.getName(); final String password = new String(pc.getPassword()); successLogin = authenticate(username, password); return successLogin; }
@Override public void handle(final Callback[] callbacks) throws UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback.getClass().equals(NameCallback.class)) { ((NameCallback) callback).setName(this.userName); } else if (callback.getClass().equals(PasswordCallback.class)) { ((PasswordCallback) callback).setPassword(this.password .toCharArray()); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
@Test public void testSaslClientCallbackHandlerWithException() { final Token<? extends TokenIdentifier> token = createTokenMock(); when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes()); when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes()); final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token); try { saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) }); } catch (UnsupportedCallbackException expEx) { //expected } catch (Exception ex) { fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage()); } }
@Override public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { Arrays.stream(callbacks) .filter(WSPasswordCallback.class::isInstance) .map(WSPasswordCallback.class::cast) .forEach(c -> { LOGGER.debug("Evaluating [{}]", c.getIdentifier()); c.setPassword(this.psw); LOGGER.debug("Authenticated [{}] successfully.", c.getIdentifier()); }); }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { if (callbacks != null) { for (final Callback cb : callbacks) { if (cb != null) { // CAN if (cb instanceof CustomTextInputCallback) { ((CustomTextInputCallback)cb).setText(can); return; } else if (cb instanceof CustomAuthorizeCallback) { ((CustomAuthorizeCallback)cb).setAuthorized(true); return; } // PIN else if (cb instanceof PasswordCallback) { ((PasswordCallback)cb).setPassword(pin != null ? pin.toCharArray() : null); return; } else { Log.e("com.mifirma", "Callback no soportada: " + cb.getClass().getName()); //$NON-NLS-1$ } } } } else { Log.w("com.mifirma", "Se ha revibido un array de Callbacks nulo"); //$NON-NLS-1$ } throw new UnsupportedCallbackException(null); }
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback.getClass().equals(NameCallback.class)) { ((NameCallback) callback).setName(this.userName); } else if (callback.getClass().equals(PasswordCallback.class)) { ((PasswordCallback) callback).setPassword(this.password .toCharArray()); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
@Override public boolean login() throws LoginException { NameCallback userNameCallback = new NameCallback("userName"); PasswordCallback passwordCallback = new PasswordCallback("password", false); Callback[] callbacks = { userNameCallback, passwordCallback }; try { callbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new BrokerAuthenticationException("Error while handling callback ", e); } String userName = userNameCallback.getName(); char[] password = passwordCallback.getPassword(); return userName.equals("user") && Arrays.equals(password, new char[] { 'p', 'a', 's', 's' }); }
public void handle(Callback[] callbacks) throws UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { handleNameCallback((NameCallback) callback); } else if (callback instanceof PasswordCallback) { handlePasswordCallback((PasswordCallback) callback); } else if (callback instanceof RealmCallback) { handleRealmCallback((RealmCallback) callback); } else if (callback instanceof AuthorizeCallback) { handleAuthorizeCallback((AuthorizeCallback) callback); } } }
public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { NameCallback nc = (NameCallback) callbacks[i]; nc.setName(username); } else if (callbacks[i] instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callbacks[i]; pc.setPassword(password); } } }
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { try { NameCallback nameCallback = new NameCallback("prompt"); PasswordCallback passwordCallback = new PasswordCallback("prompt", false); callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); } catch (Exception e) { throw new RuntimeException(e); } }
private static CallbackHandler getUsernamePasswordHandler(final String username, final String password) { return callbacks -> { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { final NameCallback nameCallback = (NameCallback) callback; nameCallback.setName(username); } else if (callback instanceof PasswordCallback) { final PasswordCallback passCallback = (PasswordCallback) callback; passCallback.setPassword(password.toCharArray()); } else { System.err.println("Unsupported Callback: " + callback.getClass().getName()); } } }; }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { final String pw = sessionId == null ? "nosession" : sessionId; for( int i = 0; i < callbacks.length; i++ ) { final WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[i]; pwcb.setPassword(pw); } }
/** * Called by login() to acquire the username and password strings for authentication. This method does no validation * of either. * * @return String[], [0] = username, [1] = password */ private String[] getUsernameAndPassword() throws LoginException { if (callbackHandler == null) { throw new LoginException("No CallbackHandler available to collect authentication information"); } NameCallback nc = new NameCallback("User name: ", "guest"); PasswordCallback pc = new PasswordCallback("Password: ", false); Callback[] callbacks = { nc, pc }; String username = null; String password = null; try { callbackHandler.handle(callbacks); username = nc.getName(); char[] tmpPassword = pc.getPassword(); if (tmpPassword != null) { credential = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length); pc.clearPassword(); password = new String(credential); } } catch (IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("CallbackHandler does not support: " + uce.getCallback()); } return new String[] { username, password }; }
/** * Authenticate the user */ public boolean login() throws LoginException { sLog.debug("Performing db authentication ... "); // Get callback parameters if (getCallbackHandler() == null) throw new LoginException("Error: no CallbackHandler available "); Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("User Name: "); callbacks[1] = new PasswordCallback("Password: ", true); try { getCallbackHandler().handle(callbacks); String n = ((NameCallback) callbacks[0]).getName(); String p = String.valueOf(((PasswordCallback) callbacks[1]).getPassword()); HashMap userProps = new HashMap(); userProps.put("username", n); userProps.put("password", p); if (doAuthenticate(userProps)) return true; // Authentication failed sLog.debug("Db authentication failed ... "); setAuthSucceeded(false); return false; } catch (Exception ex) { sLog.debug("Db authentication failed ... " + ex.getMessage(), ex); setAuthSucceeded(false); return false; } }