Search in sources :

Example 51 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project felix by apache.

the class ConfigLoginModule method login.

@Override
public boolean login() throws LoginException {
    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback("Name");
    callbacks[1] = new PasswordCallback("Name", false);
    try {
        handler.handle(callbacks);
    } catch (IOException e) {
        throw new LoginException(e.getMessage());
    } catch (UnsupportedCallbackException e) {
        throw new LoginException(e.getMessage());
    }
    String name = ((NameCallback) callbacks[0]).getName();
    char[] password = ((PasswordCallback) callbacks[1]).getPassword();
    boolean result = Arrays.equals(name.toCharArray(), password);
    if (result) {
        result = validateConfig();
    }
    succeeded = result;
    this.name = name;
    return result;
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) LoginException(javax.security.auth.login.LoginException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 52 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.

the class ChainContextCallbackHandler method getFormCredentials.

private void getFormCredentials(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callback;
            String login = chainContext.getUserName();
            nameCallback.setName(login);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            String password = chainContext.getRequestParameter(AuthenticationConstants.PASSWORD);
            passwordCallback.setPassword(null);
            if (password != null) {
                passwordCallback.setPassword(password.toCharArray());
            }
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 53 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.

the class WsPlainTextCallbackHandler method handle.

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callback;
            nameCallback.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            passwordCallback.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 54 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.

the class ChainContextCallbackHandlerTest method testHandleFormBasedLogin_testPassword.

@Test
public void testHandleFormBasedLogin_testPassword() throws Exception {
    when(contextMock.getRequestParameter(AuthenticationConstants.PASSWORD)).thenReturn(PASSWORD);
    Callback[] callbacks = new Callback[1];
    PasswordCallback passwordCallback = new PasswordCallback(AuthenticationConstants.PASSWORD, false);
    callbacks[0] = passwordCallback;
    callbackHandler.handle(callbacks);
    assertNotNull(passwordCallback.getPassword());
    assertEquals(PASSWORD, new String(passwordCallback.getPassword()));
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) LanguageCallback(javax.security.auth.callback.LanguageCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Test(org.junit.Test)

Example 55 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project simba-os by cegeka.

the class ChainContextCallbackHandlerTest method testHandleFormBasedLogin_passwordNull.

@Test
public void testHandleFormBasedLogin_passwordNull() throws Exception {
    when(contextMock.getRequestParameter(AuthenticationConstants.PASSWORD)).thenReturn(null);
    Callback[] callbacks = new Callback[1];
    PasswordCallback passwordCallback = new PasswordCallback(AuthenticationConstants.PASSWORD, false);
    callbacks[0] = passwordCallback;
    callbackHandler.handle(callbacks);
    assertEquals(null, passwordCallback.getPassword());
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) LanguageCallback(javax.security.auth.callback.LanguageCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Test(org.junit.Test)

Aggregations

PasswordCallback (javax.security.auth.callback.PasswordCallback)316 NameCallback (javax.security.auth.callback.NameCallback)255 Callback (javax.security.auth.callback.Callback)207 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)167 IOException (java.io.IOException)102 LoginException (javax.security.auth.login.LoginException)72 CallbackHandler (javax.security.auth.callback.CallbackHandler)66 LoginContext (javax.security.auth.login.LoginContext)39 FailedLoginException (javax.security.auth.login.FailedLoginException)35 RealmCallback (javax.security.sasl.RealmCallback)35 Subject (javax.security.auth.Subject)31 Test (org.junit.Test)28 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)26 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)26 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)24 Principal (java.security.Principal)21 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)18 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)18 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)15