Search in sources :

Example 31 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project midpoint by Evolveum.

the class PasswordCallback method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    LOGGER.trace("Invoked PasswordCallback with {} callbacks: {}", callbacks.length, callbacks);
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    String username = pc.getIdentifier();
    String wssPasswordType = pc.getType();
    LOGGER.trace("Username: '{}', Password type: {}", username, wssPasswordType);
    try {
        ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
        pc.setPassword(passwordAuthenticationEvaluatorImpl.getAndCheckUserPassword(connEnv, username));
    } catch (Exception e) {
        LOGGER.trace("Exception in password callback: {}: {}", e.getClass().getSimpleName(), e.getMessage(), e);
        throw new PasswordCallbackException("Authentication failed");
    }
}
Also used : WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment)

Example 32 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project AuthMeReloaded by AuthMe.

the class OAuth2SaslClient method evaluateChallenge.

public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
    if (isComplete) {
        // Empty final response from server, just ignore it.
        return new byte[] {};
    }
    NameCallback nameCallback = new NameCallback("Enter name");
    Callback[] callbacks = new Callback[] { nameCallback };
    try {
        callbackHandler.handle(callbacks);
    } catch (UnsupportedCallbackException e) {
        throw new SaslException("Unsupported callback: " + e);
    } catch (IOException e) {
        throw new SaslException("Failed to execute callback: " + e);
    }
    String email = nameCallback.getName();
    byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", email, oauthToken).getBytes();
    isComplete = true;
    return response;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) SaslException(javax.security.sasl.SaslException)

Example 33 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project OpenAM by OpenRock.

the class Anonymous method sendCallback.

private String sendCallback() throws AuthLoginException {
    if (callbackHandler == null) {
        throw new AuthLoginException(amAuthAnonymous, "NoCallbackHandler", null);
    }
    String username = null;
    try {
        Callback[] callbacks = new Callback[2];
        String header = bundle.getString("moduleHeader");
        PagePropertiesCallback ppc = new PagePropertiesCallback(null, header, null, 0, null, false, null);
        callbacks[0] = ppc;
        callbacks[1] = new NameCallback(bundle.getString("username"));
        if (debug.messageEnabled()) {
            debug.message("Callback 0 is.. :" + callbacks[0]);
            debug.message("Callback 1 is.. :" + callbacks[1]);
        }
        callbackHandler.handle(callbacks);
        username = ((NameCallback) callbacks[1]).getName();
        return username;
    } catch (IllegalArgumentException ill) {
        debug.message("message type missing");
        throw new AuthLoginException(amAuthAnonymous, "IllegalArgs", null);
    } catch (java.io.IOException ioe) {
        throw new AuthLoginException(ioe);
    } catch (UnsupportedCallbackException uce) {
        throw new AuthLoginException(amAuthAnonymous, "NoCallbackHandler", null);
    }
}
Also used : PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 34 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project jdk8u_jdk by JetBrains.

the class AuthRealmChoices method main.

public static void main(String[] args) throws Exception {
    Map props = new HashMap();
    props.put("com.sun.security.sasl.digest.realm", "IMC.ORG foo.bar machineX");
    SaslClient clnt = Sasl.createSaslClient(new String[] { MECH }, null, PROTOCOL, SERVER_FQDN, null, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback cb : callbacks) {
                if (cb instanceof RealmChoiceCallback) {
                    // 2. No index set at all
                    if (args[0].equals("1")) {
                        ((RealmChoiceCallback) cb).setSelectedIndex(10);
                    }
                }
            }
        }
    });
    SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, props, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback cb : callbacks) {
                System.out.println(cb);
            }
        }
    });
    byte[] challenge = srv.evaluateResponse(EMPTY);
    try {
        clnt.evaluateChallenge(challenge);
        throw new Exception();
    } catch (SaslException se) {
        System.out.println(se);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) Callback(javax.security.auth.callback.Callback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 35 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project jdk8u_jdk by JetBrains.

the class SampleCallbackHandler method handle.

public void handle(Callback[] callbacks) throws java.io.IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback cb = (NameCallback) callbacks[i];
            cb.setName(getInput(cb.getPrompt()));
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback cb = (PasswordCallback) callbacks[i];
            String pw = getInput(cb.getPrompt());
            char[] passwd = new char[pw.length()];
            pw.getChars(0, passwd.length, passwd, 0);
            cb.setPassword(passwd);
        } else if (callbacks[i] instanceof RealmCallback) {
            RealmCallback cb = (RealmCallback) callbacks[i];
            cb.setText(getInput(cb.getPrompt()));
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RealmCallback(javax.security.sasl.RealmCallback)

Aggregations

UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)197 IOException (java.io.IOException)123 Callback (javax.security.auth.callback.Callback)123 NameCallback (javax.security.auth.callback.NameCallback)105 PasswordCallback (javax.security.auth.callback.PasswordCallback)96 LoginException (javax.security.auth.login.LoginException)51 CallbackHandler (javax.security.auth.callback.CallbackHandler)31 FailedLoginException (javax.security.auth.login.FailedLoginException)24 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)20 Principal (java.security.Principal)19 Subject (javax.security.auth.Subject)18 AuthException (javax.security.auth.message.AuthException)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)18 HashMap (java.util.HashMap)17 LoginContext (javax.security.auth.login.LoginContext)17 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)17 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)16 RealmCallback (javax.security.sasl.RealmCallback)15 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)11 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)10