Search in sources :

Example 86 with NameCallback

use of javax.security.auth.callback.NameCallback in project cxf by apache.

the class NameDigestPasswordCallbackHandler method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        Callback callback = callbacks[i];
        if (handleCallback(callback)) {
            continue;
        } else if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(username);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pwCallback = (PasswordCallback) callback;
            pwCallback.setPassword(password.toCharArray());
        } else if (!invokePasswordCallback(callback)) {
            org.apache.cxf.common.i18n.Message errorMsg = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_CALLBACK_TYPE", BUNDLE, callbacks[i].getClass().getName());
            LOG.info(errorMsg.toString());
            throw new UnsupportedCallbackException(callbacks[i], errorMsg.toString());
        }
    }
}
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 87 with NameCallback

use of javax.security.auth.callback.NameCallback in project cxf by apache.

the class NamePasswordCallbackHandler method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        Callback callback = callbacks[i];
        if (handleCallback(callback)) {
            continue;
        } else if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(username);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pwCallback = (PasswordCallback) callback;
            pwCallback.setPassword(password.toCharArray());
        } else if (!invokePasswordCallback(callback)) {
            org.apache.cxf.common.i18n.Message errorMsg = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_CALLBACK_TYPE", BUNDLE, callbacks[i].getClass().getName());
            LOG.info(errorMsg.toString());
            throw new UnsupportedCallbackException(callbacks[i], errorMsg.toString());
        }
    }
}
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 88 with NameCallback

use of javax.security.auth.callback.NameCallback in project cxf by apache.

the class WSDLGetAuthenticatorInterceptor method doAuthenticate.

public Subject doAuthenticate(final String username, final String password) {
    try {
        Subject subject = new Subject();
        LoginContext loginContext = new LoginContext(getContextName(), subject, new CallbackHandler() {

            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                    if (callbacks[i] instanceof NameCallback) {
                        ((NameCallback) callbacks[i]).setName(username);
                    } else if (callbacks[i] instanceof PasswordCallback) {
                        ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                }
            }
        });
        loginContext.login();
        return subject;
    } catch (FailedLoginException e) {
        LOG.log(Level.FINE, "Login failed ", e);
        return null;
    } catch (AccountException e) {
        LOG.log(Level.WARNING, "Account failure ", e);
        return null;
    } catch (GeneralSecurityException e) {
        LOG.log(Level.SEVERE, "General Security Exception ", e);
        return null;
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) FailedLoginException(javax.security.auth.login.FailedLoginException) AccountException(javax.security.auth.login.AccountException) GeneralSecurityException(java.security.GeneralSecurityException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Subject(javax.security.auth.Subject)

Example 89 with NameCallback

use of javax.security.auth.callback.NameCallback in project cxf by apache.

the class KerberosClientPasswordCallback method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callbacks[i];
            nameCallback.setName("alice");
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
            passwordCallback.setPassword("alice".toCharArray());
        }
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 90 with NameCallback

use of javax.security.auth.callback.NameCallback in project tomee by apache.

the class TestLoginModule method login.

public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback("Username:");
    callbacks[1] = new PasswordCallback("Password:", false);
    try {
        callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException("Failed to perform emulated login: " + e.getMessage());
    }
    user = ((NameCallback) callbacks[0]).getName();
    return true;
}
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) LoginException(javax.security.auth.login.LoginException)

Aggregations

NameCallback (javax.security.auth.callback.NameCallback)203 PasswordCallback (javax.security.auth.callback.PasswordCallback)161 Callback (javax.security.auth.callback.Callback)140 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)101 IOException (java.io.IOException)60 LoginException (javax.security.auth.login.LoginException)51 CallbackHandler (javax.security.auth.callback.CallbackHandler)27 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)22 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)22 RealmCallback (javax.security.sasl.RealmCallback)22 Subject (javax.security.auth.Subject)19 FailedLoginException (javax.security.auth.login.FailedLoginException)19 LoginContext (javax.security.auth.login.LoginContext)18 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)18 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)17 Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 IdRepoException (com.sun.identity.idm.IdRepoException)13 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)11