Search in sources :

Example 11 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project nhin-d by DirectProject.

the class TestUtils method setupSafeNetToken.

/**
     * used for testing with a pkcs11 token
     * @return The Security provider name if the token is loaded successfully... an empty string other wise 
     * @throws Exception
     */
public static String setupSafeNetToken() throws Exception {
    final CallbackHandler handler = new CallbackHandler() {

        public void handle(Callback[] callbacks) {
            for (Callback callback : callbacks) {
                if (callback instanceof PasswordCallback) {
                    ((PasswordCallback) callback).setPassword("1Kingpuff".toCharArray());
                }
            }
        }
    };
    sun.security.pkcs11.SunPKCS11 p = null;
    try {
        final String configName = "./src/test/resources/pkcs11Config/pkcs11.cfg";
        p = new sun.security.pkcs11.SunPKCS11(configName);
        Security.addProvider(p);
        p.login(null, handler);
    } catch (Exception e) {
        return "";
    }
    return p.getName();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 12 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project nhin-d by DirectProject.

the class TestUtils method setupSafeNetToken.

/**
     * used for testing with a pkcs11 token
     * @return The Security provider name if the token is loaded successfully... an empty string other wise 
     * @throws Exception
     */
public static String setupSafeNetToken() throws Exception {
    final CallbackHandler handler = new CallbackHandler() {

        public void handle(Callback[] callbacks) {
            for (Callback callback : callbacks) {
                if (callback instanceof PasswordCallback) {
                    ((PasswordCallback) callback).setPassword("1Kingpuff".toCharArray());
                }
            }
        }
    };
    sun.security.pkcs11.SunPKCS11 p = null;
    try {
        final String configName = "./src/test/resources/pkcs11Config/pkcs11.cfg";
        p = new sun.security.pkcs11.SunPKCS11(configName);
        Security.addProvider(p);
        p.login(null, handler);
    } catch (Exception e) {
        return "";
    }
    return p.getName();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) NHINDException(org.nhindirect.stagent.NHINDException)

Example 13 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project nhin-d by DirectProject.

the class TestUtils method setupSafeNetToken.

/**
     * used for testing with a pkcs11 token
     * @return The Security provider name if the token is loaded successfully... an empty string other wise 
     * @throws Exception
     */
public static String setupSafeNetToken() throws Exception {
    final CallbackHandler handler = new CallbackHandler() {

        public void handle(Callback[] callbacks) {
            for (Callback callback : callbacks) {
                if (callback instanceof PasswordCallback) {
                    ((PasswordCallback) callback).setPassword("1Kingpuff".toCharArray());
                }
            }
        }
    };
    sun.security.pkcs11.SunPKCS11 p = null;
    final String configName = "./src/test/resources/pkcs11Config/pkcs11.cfg";
    try {
        p = new sun.security.pkcs11.SunPKCS11(configName);
        Security.addProvider(p);
        p.login(null, handler);
    } catch (Exception e) {
        return "";
    }
    return p.getName();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException)

Example 14 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler 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 15 with CallbackHandler

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

the class CleanState method go.

void go() throws Exception {
    Krb5LoginModule krb5 = new Krb5LoginModule();
    final String name = OneKDC.USER;
    final char[] password = OneKDC.PASS;
    char[] badpassword = "hellokitty".toCharArray();
    Map<String, String> map = new HashMap<>();
    map.put("useTicketCache", "false");
    map.put("doNotPrompt", "false");
    map.put("tryFirstPass", "true");
    Map<String, Object> shared = new HashMap<>();
    shared.put("javax.security.auth.login.name", name);
    shared.put("javax.security.auth.login.password", badpassword);
    krb5.initialize(new Subject(), new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) {
            for (Callback callback : callbacks) {
                if (callback instanceof NameCallback) {
                    ((NameCallback) callback).setName(name);
                }
                if (callback instanceof PasswordCallback) {
                    ((PasswordCallback) callback).setPassword(password);
                }
            }
        }
    }, shared, map);
    krb5.login();
}
Also used : Krb5LoginModule(com.sun.security.auth.module.Krb5LoginModule) CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) Subject(javax.security.auth.Subject) 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)

Aggregations

CallbackHandler (javax.security.auth.callback.CallbackHandler)89 IOException (java.io.IOException)38 Callback (javax.security.auth.callback.Callback)36 PasswordCallback (javax.security.auth.callback.PasswordCallback)30 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)27 HashMap (java.util.HashMap)25 Subject (javax.security.auth.Subject)24 NameCallback (javax.security.auth.callback.NameCallback)22 LoginContext (javax.security.auth.login.LoginContext)17 LoginException (javax.security.auth.login.LoginException)15 Test (org.junit.Test)15 Map (java.util.Map)10 URL (java.net.URL)8 RealmCallback (javax.security.sasl.RealmCallback)7 QName (javax.xml.namespace.QName)6 Service (javax.xml.ws.Service)6 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)6 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)5 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)5 TokenValidatorResponse (org.apache.cxf.sts.token.validator.TokenValidatorResponse)5