Search in sources :

Example 6 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project jstorm by alibaba.

the class ClientCallbackHandler method handle.

/**
     * This method is invoked by SASL for authentication challenges
     * 
     * @param callbacks a collection of challenge callbacks
     */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback c : callbacks) {
        if (c instanceof NameCallback) {
            LOG.debug("name callback");
        } else if (c instanceof PasswordCallback) {
            LOG.debug("password callback");
            LOG.warn("Could not login: the client is being asked for a password, but the " + " client code does not currently support obtaining a password from the user." + " Make sure that the client is configured to use a ticket cache (using" + " the JAAS configuration setting 'useTicketCache=true)' and restart the client. If" + " you still get this message after that, the TGT in the ticket cache has expired and must" + " be manually refreshed. To do so, first determine if you are using a password or a" + " keytab. If the former, run kinit in a Unix shell in the environment of the user who" + " is running this client using the command" + " 'kinit <princ>' (where <princ> is the name of the client's Kerberos principal)." + " If the latter, do" + " 'kinit -k -t <keytab> <princ>' (where <princ> is the name of the Kerberos principal, and" + " <keytab> is the location of the keytab file). After manually refreshing your cache," + " restart this client. If you continue to see this message after manually refreshing" + " your cache, ensure that your KDC host's clock is in sync with this host's clock.");
        } else if (c instanceof AuthorizeCallback) {
            LOG.debug("authorization callback");
            AuthorizeCallback ac = (AuthorizeCallback) c;
            String authid = ac.getAuthenticationID();
            String authzid = ac.getAuthorizationID();
            if (authid.equals(authzid)) {
                ac.setAuthorized(true);
            } else {
                ac.setAuthorized(false);
            }
            if (ac.isAuthorized()) {
                ac.setAuthorizedID(authzid);
            }
        } else {
            throw new UnsupportedCallbackException(c);
        }
    }
}
Also used : RealmCallback(javax.security.sasl.RealmCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthorizeCallback(javax.security.sasl.AuthorizeCallback)

Example 7 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project jetty.project by eclipse.

the class AbstractLoginModule method configureCallbacks.

public Callback[] configureCallbacks() {
    Callback[] callbacks = new Callback[3];
    callbacks[0] = new NameCallback("Enter user name");
    callbacks[1] = new ObjectCallback();
    //only used if framework does not support the ObjectCallback
    callbacks[2] = new PasswordCallback("Enter password", false);
    return callbacks;
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ObjectCallback(org.eclipse.jetty.jaas.callback.ObjectCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) ObjectCallback(org.eclipse.jetty.jaas.callback.ObjectCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 8 with PasswordCallback

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

the class SaslPlainServer method evaluateResponse.

@Override
public byte[] evaluateResponse(byte[] response) throws SaslException {
    if (completed) {
        throw new IllegalStateException("PLAIN authentication has completed");
    }
    if (response == null) {
        throw new IllegalArgumentException("Received null response");
    }
    try {
        String payload;
        try {
            payload = new String(response, "UTF-8");
        } catch (Exception e) {
            throw new IllegalArgumentException("Received corrupt response", e);
        }
        // [ authz, authn, password ]
        String[] parts = payload.split("", 3);
        if (parts.length != 3) {
            throw new IllegalArgumentException("Received corrupt response");
        }
        if (parts[0].isEmpty()) {
            // authz = authn
            parts[0] = parts[1];
        }
        NameCallback nc = new NameCallback("SASL PLAIN");
        nc.setName(parts[1]);
        PasswordCallback pc = new PasswordCallback("SASL PLAIN", false);
        pc.setPassword(parts[2].toCharArray());
        AuthorizeCallback ac = new AuthorizeCallback(parts[1], parts[0]);
        cbh.handle(new Callback[] { nc, pc, ac });
        if (ac.isAuthorized()) {
            authz = ac.getAuthorizedID();
        }
    } catch (Exception e) {
        throw new SaslException("PLAIN auth failed: " + e.toString(), e);
    } finally {
        completed = true;
    }
    return null;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) SaslException(javax.security.sasl.SaslException) SaslException(javax.security.sasl.SaslException) AuthorizeCallback(javax.security.sasl.AuthorizeCallback)

Example 9 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project Smack by igniterealtime.

the class SASLJavaXMechanism method authenticateInternal.

@Override
protected void authenticateInternal() throws SmackException {
    String[] mechanisms = { getName() };
    Map<String, String> props = getSaslProps();
    String authzid = null;
    if (authorizationId != null) {
        authzid = authorizationId.toString();
    }
    try {
        sc = Sasl.createSaslClient(mechanisms, authzid, "xmpp", getServerName().toString(), props, new CallbackHandler() {

            @Override
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                    if (callbacks[i] instanceof NameCallback) {
                        NameCallback ncb = (NameCallback) callbacks[i];
                        ncb.setName(authenticationId);
                    } else if (callbacks[i] instanceof PasswordCallback) {
                        PasswordCallback pcb = (PasswordCallback) callbacks[i];
                        pcb.setPassword(password.toCharArray());
                    } else if (callbacks[i] instanceof RealmCallback) {
                        RealmCallback rcb = (RealmCallback) callbacks[i];
                        // Retrieve the REALM from the challenge response that
                        // the server returned when the client initiated the
                        // authentication exchange. If this value is not null or
                        // empty, *this value* has to be sent back to the server
                        // in the client's response to the server's challenge
                        String text = rcb.getDefaultText();
                        // The SASL client (sc) created in smack uses
                        // rcb.getText when creating the negotiatedRealm to send
                        // it back to the server. Make sure that this value
                        // matches the server's realm
                        rcb.setText(text);
                    } else if (callbacks[i] instanceof RealmChoiceCallback) {
                    // unused, prevents UnsupportedCallbackException
                    // RealmChoiceCallback rccb =
                    // (RealmChoiceCallback)callbacks[i];
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                }
            }
        });
    } catch (SaslException e) {
        throw new SmackException(e);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) NameCallback(javax.security.auth.callback.NameCallback) SmackException(org.jivesoftware.smack.SmackException) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) SaslException(javax.security.sasl.SaslException) RealmChoiceCallback(javax.security.sasl.RealmChoiceCallback) RealmCallback(javax.security.sasl.RealmCallback)

Example 10 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project storm by nathanmarz.

the class ClientCallbackHandler method handle.

/**
     * This method is invoked by SASL for authentication challenges
     * @param callbacks a collection of challenge callbacks 
     */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback c : callbacks) {
        if (c instanceof NameCallback) {
            LOG.debug("name callback");
            NameCallback nc = (NameCallback) c;
            nc.setName(_username);
        } else if (c instanceof PasswordCallback) {
            LOG.debug("password callback");
            PasswordCallback pc = (PasswordCallback) c;
            if (_password != null) {
                pc.setPassword(_password.toCharArray());
            }
        } else if (c instanceof AuthorizeCallback) {
            LOG.debug("authorization callback");
            AuthorizeCallback ac = (AuthorizeCallback) c;
            String authid = ac.getAuthenticationID();
            String authzid = ac.getAuthorizationID();
            if (authid.equals(authzid)) {
                ac.setAuthorized(true);
            } else {
                ac.setAuthorized(false);
            }
            if (ac.isAuthorized()) {
                ac.setAuthorizedID(authzid);
            }
        } else if (c instanceof RealmCallback) {
            RealmCallback rc = (RealmCallback) c;
            ((RealmCallback) c).setText(rc.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(c);
        }
    }
}
Also used : RealmCallback(javax.security.sasl.RealmCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) RealmCallback(javax.security.sasl.RealmCallback)

Aggregations

PasswordCallback (javax.security.auth.callback.PasswordCallback)198 NameCallback (javax.security.auth.callback.NameCallback)162 Callback (javax.security.auth.callback.Callback)135 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)90 IOException (java.io.IOException)55 LoginException (javax.security.auth.login.LoginException)43 CallbackHandler (javax.security.auth.callback.CallbackHandler)36 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)25 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)23 RealmCallback (javax.security.sasl.RealmCallback)21 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)18 FailedLoginException (javax.security.auth.login.FailedLoginException)18 LoginContext (javax.security.auth.login.LoginContext)18 Subject (javax.security.auth.Subject)16 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)16 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)15 Test (org.junit.Test)15 Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)14 IdRepoException (com.sun.identity.idm.IdRepoException)12