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); } } }
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; }
@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"); } } }
static SaslClient createSaslClient(final String user, final String password) throws SaslException { return Sasl.createSaslClient(new String[]{"PLAIN"}, user, null, null, null, new CallbackHandler() { @Override public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword(password.toCharArray()); } else if (callback instanceof NameCallback) { ((NameCallback) callback).setName(user); } } } }); }
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"); } } }
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 protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getPrincipal().getName()); WSUsernameTokenPrincipal principal = callback.getPrincipal(); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( principal, principal.getPassword(), user.getAuthorities()); if (logger.isDebugEnabled()) { logger.debug("Authentication success: " + authRequest.toString()); } SecurityContextHolder.getContext().setAuthentication(authRequest); if (user instanceof IUser) { HttpSession session=ContextHolder.getHttpSession(); session.setAttribute(ContextHolder.LOGIN_USER_SESSION_KEY, user); session.setAttribute(ContextHolder.USER_LOGIN_WAY_KEY,IWebservice.WS_LOGIN_WAY); } }
@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)); }
/** * Here, we attempt to get the password from the private * alias/passwords map. */ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { try { String id = (String)callback.getClass().getMethod("getIdentifier").invoke(callback); String pass = passwords.get(id); if (pass != null) { callback.getClass().getMethod("setPassword", String.class).invoke(callback, pass); return; } } catch (Exception ex) { UnsupportedCallbackException e = new UnsupportedCallbackException(callback); e.initCause(ex); throw e; } } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { // prompt the user for a username NameCallback nameCallback = (NameCallback) callback; nameCallback.setName(username); } else if (callback instanceof PasswordCallback) { // prompt the user for a password PasswordCallback passwordCallback = (PasswordCallback) callback; passwordCallback.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback"); } } }
public void handle( Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { NameCallback ncb = (NameCallback) callbacks[i]; ncb.setName(username); } else if (callbacks[i] instanceof PasswordCallback) { PasswordCallback pcb = (PasswordCallback) callbacks[i]; pcb.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException( callbacks[i], "Unrecognized Callback"); } } }
@Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback nc = (NameCallback) callback; nc.setName(nc.getDefaultName()); } else if (callback instanceof PasswordCallback) { String errorMessage = "Could not login: the client is being asked for a password, but the Kafka" + " client code does not currently support obtaining a password from the user."; throw new UnsupportedCallbackException(callback, errorMessage); } else if (callback instanceof RealmCallback) { RealmCallback rc = (RealmCallback) callback; rc.setText(rc.getDefaultText()); } else { throw new UnsupportedCallbackException(callback, "Unrecognized SASL Login callback"); } } }
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { NameCallback ncb = (NameCallback) callbacks[i]; ncb.setName(username); } else if (callbacks[i] instanceof PasswordCallback) { PasswordCallback pcb = (PasswordCallback) callbacks[i]; pcb.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException (callbacks[i], "Unrecognized Callback"); } } }
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { //When the server side need to authenticate the user WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; if (pwcb.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) { if(pwcb.getIdentifer().equals("alice") && pwcb.getPassword().equals("bobPW")) { return; } else { throw new UnsupportedCallbackException(callbacks[i], "check failed"); } } //When the client requests for the password to be added in to the //UT element pwcb.setPassword("bobPW"); } }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI()); CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, ""); GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{UserGroupMapping.GUEST_ROLE_ID}); Callback[] callbacks = {callerPrincipalCallback, groupPrincipalCallback}; try { callbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new AuthException(e.getMessage()); } return AuthStatus.SUCCESS; }
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof WSPasswordCallback) { WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; String id = pc.getIdentifier(); if (keystorePassword.get(id) != null) { pc.setPassword(keystorePassword.get(id)); } else { throw new UnsupportedCallbackException(callbacks[i], "no password found for " + id); } } } }
void start() throws KeyStoreException, NoSuchAlgorithmException, IOException, UnsupportedCallbackException, UnrecoverableKeyException, CertificateException { if (Configuration.DEBUG) log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$ // 1. get the key entry and certificate chain associated to alias Key privateKey = getAliasPrivateKey(); Certificate[] chain = store.getCertificateChain(alias); // 2. replace the old entry setNewKeyPassword(_newPassword); store.setKeyEntry(alias, privateKey, newPasswordChars, chain); // 3. persist the key store saveKeyStore(); if (Configuration.DEBUG) log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$ }