Java Code Examples for javax.security.auth.callback.Callback

The following are top voted examples for showing how to use javax.security.auth.callback.Callback. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: fcrepo3-security-jaas   File: AuthFilterJAAS.java   View source code 6 votes vote down vote up
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);
        }
    }
}
 
Example 2
Project: springboot-shiro-cas-mybatis   File: MockLoginModule.java   View source code 6 votes vote down vote up
@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();
}
 
Example 3
Project: OpenDiabetes   File: JaasAuthBean.java   View source code 6 votes vote down vote up
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");
}
 
Example 4
Project: cas-5.1.0   File: JaasAuthenticationHandler.java   View source code 6 votes vote down vote up
@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"));
    });
}
 
Example 5
Project: cas-5.1.0   File: MockLoginModule.java   View source code 6 votes vote down vote up
@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();
}
 
Example 6
Project: jmeter-wssecurity   File: WSSDecryptionPostProcessor.java   View source code 6 votes vote down vote up
@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;
}
 
Example 7
Project: cas4.0.x-server-wechat   File: MockLoginModule.java   View source code 6 votes vote down vote up
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();
}
 
Example 8
Project: message-broker   File: PlainSaslCallbackHandler.java   View source code 6 votes vote down vote up
@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();
    }
}
 
Example 9
Project: oscm   File: UserCredentialsHandler.java   View source code 6 votes vote down vote up
/**
 * 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");
        }
    }
}
 
Example 10
Project: oscm   File: WSCallbackHandler.java   View source code 6 votes vote down vote up
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");
        }
    }
}
 
Example 11
Project: cas-server-4.2.1   File: MockLoginModule.java   View source code 6 votes vote down vote up
@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();
}
 
Example 12
Project: Transwarp-Sample-Code   File: KerberosAuthenticator2.java   View source code 6 votes vote down vote up
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");
        }
    }
}
 
Example 13
Project: dev-courses   File: JaasAuthBean.java   View source code 6 votes vote down vote up
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");
}
 
Example 14
Project: ditb   File: TestHBaseSaslRpcClient.java   View source code 6 votes vote down vote up
@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));
}
 
Example 15
Project: OpenJSharp   File: NegotiateCallbackHandler.java   View source code 6 votes vote down vote up
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");
        }
    }
}
 
Example 16
Project: jerrydog   File: JAASCallbackHandler.java   View source code 6 votes vote down vote up
/**
 * 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]);
        }


    }

}
 
Example 17
Project: libcwfincore   File: GdaxExchangeConnection.java   View source code 6 votes vote down vote up
@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);
}
 
Example 18
Project: libcwfincore   File: GdaxExchangeCredentials.java   View source code 6 votes vote down vote up
@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);
            }
        }
    };
}
 
Example 19
Project: OperatieBRP   File: JMXCallbackHandler.java   View source code 6 votes vote down vote up
/**
 * 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");
        }
    }
}
 
Example 20
Project: kafka-0.11.0.0-src-with-comment   File: TestDigestLoginModule.java   View source code 6 votes vote down vote up
@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());
            }
        }
    }
}
 
Example 21
Project: jdk8u-jdk   File: DynamicConfigurationTest.java   View source code 6 votes vote down vote up
@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");
        }
    }
}
 
Example 22
Project: openjdk-jdk10   File: NegotiateCallbackHandler.java   View source code 6 votes vote down vote up
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");
        }
    }
}
 
Example 23
Project: openjdk-jdk10   File: TestCallbackHandler.java   View source code 6 votes vote down vote up
@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);
        }
    }
}
 
Example 24
Project: openjdk-jdk10   File: DynamicConfigurationTest.java   View source code 6 votes vote down vote up
@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");
        }
    }
}
 
Example 25
Project: fcrepo3-security-jaas   File: XmlUsersFileModule.java   View source code 5 votes vote down vote up
@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;
}
 
Example 26
Project: springboot-shiro-cas-mybatis   File: JaasAuthenticationHandler.java   View source code 5 votes vote down vote up
@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");
        }
    }
}
 
Example 27
Project: springboot-shiro-cas-mybatis   File: JaasAuthenticationHandler.java   View source code 5 votes vote down vote up
@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");
        }
    }
}
 
Example 28
Project: ditb   File: TestHBaseSaslRpcClient.java   View source code 5 votes vote down vote up
@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());
  }
}
 
Example 29
Project: cas-5.1.0   File: RealmPasswordVerificationCallbackHandler.java   View source code 5 votes vote down vote up
@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());
            });
}
 
Example 30
Project: mi-firma-android   File: CanResult.java   View source code 5 votes vote down vote up
@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);
}
 
Example 31
Project: cas4.0.x-server-wechat   File: JaasAuthenticationHandler.java   View source code 5 votes vote down vote up
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");
        }
    }
}
 
Example 32
Project: message-broker   File: TestLoginModule.java   View source code 5 votes vote down vote up
@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' });
}
 
Example 33
Project: fuck_zookeeper   File: SaslServerCallbackHandler.java   View source code 5 votes vote down vote up
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);
        }
    }
}
 
Example 34
Project: ats-framework   File: JaasKerberosConfiguration.java   View source code 5 votes vote down vote up
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);
        }
    }
}
 
Example 35
Project: taskana   File: SampleLoginModule.java   View source code 5 votes vote down vote up
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);
	}
}
 
Example 36
Project: ARCLib   File: PasswordTicketValidator.java   View source code 5 votes vote down vote up
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());
            }
        }
    };
}
 
Example 37
Project: Equella   File: BlackboardConnectorServiceImpl.java   View source code 5 votes vote down vote up
@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);
	}
}
 
Example 38
Project: lams   File: UniversalLoginModule.java   View source code 5 votes vote down vote up
/**
    * 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 };
   }
 
Example 39
Project: https-github.com-apache-zookeeper   File: SaslServerCallbackHandler.java   View source code 5 votes vote down vote up
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);
        }
    }
}
 
Example 40
Project: unitimes   File: DbAuthenticateModule.java   View source code 5 votes vote down vote up
/**
 * 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;
	}
}