Search in sources :

Example 1 with ObjectCallback

use of org.jboss.security.auth.callback.ObjectCallback in project wildfly by wildfly.

the class GuestDelegationLoginModule method login.

// Public methods --------------------------------------------------------
@SuppressWarnings("unchecked")
@Override
public boolean login() throws LoginException {
    if (super.login() == true) {
        log.debug("super.login()==true");
        return true;
    }
    // Time to see if this is a delegation request.
    NameCallback ncb = new NameCallback("Username:");
    ObjectCallback ocb = new ObjectCallback("Password:");
    try {
        callbackHandler.handle(new Callback[] { ncb, ocb });
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        // If the CallbackHandler can not handle the required callbacks then no chance.
        return false;
    }
    String name = ncb.getName();
    Object credential = ocb.getCredential();
    if (credential instanceof CurrentUserCredential) {
        // This credential type will only be seen for a delegation request, if not seen then the request is not for us.
        final CurrentUserCredential cuCredential = (CurrentUserCredential) credential;
        // only the "guest" can be switched to another identity
        if ("guest".equals(cuCredential.getUser())) {
            identity = new SimplePrincipal(name);
            if (getUseFirstPass()) {
                String userName = identity.getName();
                if (log.isDebugEnabled())
                    log.debug("Storing username '" + userName + "' and empty password");
                // Add the username and an empty password to the shared state map
                sharedState.put("javax.security.auth.login.name", identity);
                sharedState.put("javax.security.auth.login.password", "");
            }
            loginOk = true;
            return true;
        }
    }
    // Attempted login but not successful.
    return false;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) ObjectCallback(org.jboss.security.auth.callback.ObjectCallback) LoginException(javax.security.auth.login.LoginException) SimplePrincipal(org.jboss.security.SimplePrincipal)

Example 2 with ObjectCallback

use of org.jboss.security.auth.callback.ObjectCallback in project wildfly by wildfly.

the class ExternalLoginModule method login.

// Public methods --------------------------------------------------------
@SuppressWarnings("unchecked")
@Override
public boolean login() throws LoginException {
    if (super.login()) {
        log.debug("super.login()==true");
        return true;
    }
    // Time to see if this is a delegation request.
    NameCallback ncb = new NameCallback("Username:");
    ObjectCallback ocb = new ObjectCallback("Credential:");
    try {
        callbackHandler.handle(new Callback[] { ncb, ocb });
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        // If the CallbackHandler can not handle the required callbacks then no chance.
        return false;
    }
    String name = ncb.getName();
    Object credential = ocb.getCredential();
    if (credential instanceof ExternalCredential) {
        identity = new SimplePrincipal(name);
        loginOk = true;
        return true;
    }
    // Attempted login but not successful.
    return false;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) ObjectCallback(org.jboss.security.auth.callback.ObjectCallback) LoginException(javax.security.auth.login.LoginException) ExternalCredential(io.undertow.security.idm.ExternalCredential) SimplePrincipal(org.jboss.security.SimplePrincipal)

Example 3 with ObjectCallback

use of org.jboss.security.auth.callback.ObjectCallback in project wildfly by wildfly.

the class RealmDirectLoginModule method getDigestCredential.

private DigestCredential getDigestCredential() {
    ObjectCallback oc = new ObjectCallback("Credential:");
    try {
        super.callbackHandler.handle(new Callback[] { oc });
    } catch (IOException | UnsupportedCallbackException e) {
        return null;
    }
    Object credential = oc.getCredential();
    if (credential instanceof DigestCredential) {
        /*
             * This change is an intermediate change to allow the use of a DigestCredential until we are ready to switch to
             * JAAS.
             *
             * However we only wish to accept trusted implementations so perform this final check.
             */
        if (credential.getClass().getName().equals("org.wildfly.extension.undertow.security.DigestCredentialImpl")) {
            return (DigestCredential) credential;
        }
    }
    return null;
}
Also used : ObjectCallback(org.jboss.security.auth.callback.ObjectCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 4 with ObjectCallback

use of org.jboss.security.auth.callback.ObjectCallback in project wildfly by wildfly.

the class RemotingLoginModule method getCredential.

protected Object getCredential() throws LoginException {
    NameCallback nc = new NameCallback("Alias: ");
    ObjectCallback oc = new ObjectCallback("Credential: ");
    Callback[] callbacks = { nc, oc };
    try {
        callbackHandler.handle(callbacks);
        return oc.getCredential();
    } catch (IOException ioe) {
        LoginException le = new LoginException();
        le.initCause(ioe);
        throw le;
    } catch (UnsupportedCallbackException uce) {
        LoginException le = new LoginException();
        le.initCause(uce);
        throw le;
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) ObjectCallback(org.jboss.security.auth.callback.ObjectCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) ObjectCallback(org.jboss.security.auth.callback.ObjectCallback) LoginException(javax.security.auth.login.LoginException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Aggregations

ObjectCallback (org.jboss.security.auth.callback.ObjectCallback)4 NameCallback (javax.security.auth.callback.NameCallback)3 LoginException (javax.security.auth.login.LoginException)3 IOException (java.io.IOException)2 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)2 SimplePrincipal (org.jboss.security.SimplePrincipal)2 ExternalCredential (io.undertow.security.idm.ExternalCredential)1 Callback (javax.security.auth.callback.Callback)1