@Override public Optional<Subject> map(final Optional<Object> wrapper) { try { LOG.info("logging in user as {}", username); LoginContext lc = new LoginContext("PropertyFile", callbacks -> { LOG.info("Callback Handler invoked "); Stream.of(callbacks).forEach(cb -> { if (cb instanceof NameCallback) { ((NameCallback) cb).setName(username); } else if (cb instanceof PasswordCallback) { ((PasswordCallback) cb).setPassword(password.toCharArray()); } }); }); lc.login(); return Optional.of(lc.getSubject()); } catch (LoginException e) { LOG.error("Authentication failed", e); return Optional.empty(); } }
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 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")); }); }
private void fillResultFromCallback ( final Callback cb, final javax.security.auth.callback.Callback jcb ) { if ( cb instanceof TextCallback && jcb instanceof TextInputCallback ) { ( (TextCallback)cb ).setValue ( ( (TextInputCallback)jcb ).getText () ); } else if ( cb instanceof UserNameCallback && jcb instanceof NameCallback ) { ( (UserNameCallback)cb ).setValue ( ( (NameCallback)jcb ).getName () ); } else if ( cb instanceof PasswordCallback && jcb instanceof javax.security.auth.callback.PasswordCallback ) { ( (PasswordCallback)cb ).setPassword ( String.valueOf ( ( (javax.security.auth.callback.PasswordCallback)jcb ).getPassword () ) ); } else { cb.cancel (); } }
private javax.security.auth.callback.Callback convert ( final Callback cb ) { if ( cb instanceof UserNameCallback ) { return new NameCallback ( ( (UserNameCallback)cb ).getLabel () ); } else if ( cb instanceof TextCallback ) { return new TextInputCallback ( ( (TextCallback)cb ).getLabel () ); } if ( cb instanceof PasswordCallback ) { return new javax.security.auth.callback.PasswordCallback ( ( (PasswordCallback)cb ).getLabel (), false ); } return null; }
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"); } } }
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]); } } }
/** * 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); } } }
@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)); }
@Override public SaslClient createSaslClient(final UserGroupInformation ugi, final Map<String, ?> properties) throws SaslException { final String userName = (String) properties.get(DrillProperties.USER); final String password = (String) properties.get(DrillProperties.PASSWORD); return FastSaslClientFactory.getInstance().createSaslClient(new String[]{SIMPLE_NAME}, null /** authorization ID */, null, null, properties, new CallbackHandler() { @Override public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback instanceof NameCallback) { NameCallback.class.cast(callback).setName(userName); continue; } if (callback instanceof PasswordCallback) { PasswordCallback.class.cast(callback).setPassword(password.toCharArray()); continue; } throw new UnsupportedCallbackException(callback); } } }); }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback && username != null) { NameCallback nc = (NameCallback) callback; nc.setName(username); } else if (callback instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callback; pc.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException( callback, "Unrecognized Callback"); //$NON-NLS-1$ } } }
@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"); } } }