Search in sources :

Example 61 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project activemq-artemis by apache.

the class CertificateLoginModule method login.

/**
 * Overriding to allow for certificate-based login. Standard JAAS.
 */
@Override
public boolean login() throws LoginException {
    Callback[] callbacks = new Callback[1];
    callbacks[0] = new CertificateCallback();
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException ioe) {
        throw new LoginException(ioe.getMessage());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("Unable to obtain client certificates: " + uce.getMessage());
    }
    certificates = ((CertificateCallback) callbacks[0]).getCertificates();
    username = getUserNameForCertificates(certificates);
    if (username == null) {
        throw new FailedLoginException("No user for client certificate: " + getDistinguishedName(certificates));
    }
    if (debug) {
        logger.debug("Certificate for user: " + username);
    }
    return true;
}
Also used : Callback(javax.security.auth.callback.Callback) FailedLoginException(javax.security.auth.login.FailedLoginException) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 62 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project activemq-artemis by apache.

the class LDAPLoginModule method login.

@Override
public boolean login() throws LoginException {
    if (!authenticateUser) {
        return false;
    }
    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback("User name");
    callbacks[1] = new PasswordCallback("Password", false);
    try {
        handler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw (LoginException) new LoginException().initCause(e);
    }
    String password;
    username = ((NameCallback) callbacks[0]).getName();
    if (username == null)
        return false;
    if (((PasswordCallback) callbacks[1]).getPassword() != null)
        password = new String(((PasswordCallback) callbacks[1]).getPassword());
    else
        password = "";
    // authenticate will throw LoginException
    // in case of failed authentication
    authenticate(username, password);
    userAuthenticated = true;
    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) FailedLoginException(javax.security.auth.login.FailedLoginException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 63 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project activemq-artemis by apache.

the class PropertiesLoginModule method login.

@Override
public boolean login() throws LoginException {
    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback("Username: ");
    callbacks[1] = new PasswordCallback("Password: ", false);
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException ioe) {
        throw new LoginException(ioe.getMessage());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException(uce.getMessage() + " not available to obtain information from user");
    }
    user = ((NameCallback) callbacks[0]).getName();
    char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
    if (tmpPassword == null) {
        tmpPassword = new char[0];
    }
    if (user == null) {
        throw new FailedLoginException("User is null");
    }
    String password = users.getProperty(user);
    if (password == null) {
        throw new FailedLoginException("User does not exist: " + user);
    }
    try {
        hashProcessor = PasswordMaskingUtil.getHashProcessor(password);
    } catch (Exception e) {
        throw new FailedLoginException("Failed to get hash processor");
    }
    if (!hashProcessor.compare(tmpPassword, password)) {
        throw new FailedLoginException("Password does not match for user: " + user);
    }
    loginSucceeded = true;
    if (debug) {
        logger.debug("login " + user);
    }
    return loginSucceeded;
}
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) FailedLoginException(javax.security.auth.login.FailedLoginException) PasswordCallback(javax.security.auth.callback.PasswordCallback) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) FailedLoginException(javax.security.auth.login.FailedLoginException)

Example 64 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project activemq-artemis by apache.

the class JaasCallbackHandler method handle.

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            if (password == null) {
                passwordCallback.setPassword(null);
            } else {
                passwordCallback.setPassword(password.toCharArray());
            }
        } else if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callback;
            if (username == null) {
                nameCallback.setName(null);
            } else {
                nameCallback.setName(username);
            }
        } else if (callback instanceof CertificateCallback) {
            CertificateCallback certCallback = (CertificateCallback) callback;
            certCallback.setCertificates(getCertsFromConnection(remotingConnection));
        } else if (callback instanceof Krb5Callback) {
            Krb5Callback krb5Callback = (Krb5Callback) callback;
            Subject peerSubject = remotingConnection.getSubject();
            if (peerSubject != null) {
                for (Principal principal : peerSubject.getPrivateCredentials(KerberosPrincipal.class)) {
                    krb5Callback.setPeerPrincipal(principal);
                    return;
                }
            }
            krb5Callback.setPeerPrincipal(getPeerPrincipalFromConnection(remotingConnection));
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
Also used : KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) 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) Subject(javax.security.auth.Subject) Principal(java.security.Principal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal)

Example 65 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project atlas by apache.

the class SSLAndKerberosTest method loginTestUser.

protected Subject loginTestUser() throws LoginException, IOException {
    LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback callback : callbacks) {
                if (callback instanceof PasswordCallback) {
                    PasswordCallback passwordCallback = (PasswordCallback) callback;
                    passwordCallback.setPassword(TESTPASS.toCharArray());
                }
                if (callback instanceof NameCallback) {
                    NameCallback nameCallback = (NameCallback) callback;
                    nameCallback.setName(TESTUSER);
                }
            }
        }
    });
    // attempt authentication
    lc.login();
    return lc.getSubject();
}
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) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Aggregations

UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)332 Callback (javax.security.auth.callback.Callback)213 IOException (java.io.IOException)201 NameCallback (javax.security.auth.callback.NameCallback)182 PasswordCallback (javax.security.auth.callback.PasswordCallback)177 LoginException (javax.security.auth.login.LoginException)89 CallbackHandler (javax.security.auth.callback.CallbackHandler)63 FailedLoginException (javax.security.auth.login.FailedLoginException)45 LoginContext (javax.security.auth.login.LoginContext)43 Subject (javax.security.auth.Subject)36 Principal (java.security.Principal)34 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)31 RealmCallback (javax.security.sasl.RealmCallback)27 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HashMap (java.util.HashMap)23 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)23 Test (org.junit.Test)21 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)20 SaslException (javax.security.sasl.SaslException)19 AuthException (javax.security.auth.message.AuthException)18