Search in sources :

Example 16 with PasswordCallback

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

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

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

use of javax.security.auth.callback.PasswordCallback 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)

Example 20 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback 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

PasswordCallback (javax.security.auth.callback.PasswordCallback)181 NameCallback (javax.security.auth.callback.NameCallback)147 Callback (javax.security.auth.callback.Callback)122 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)80 IOException (java.io.IOException)48 LoginException (javax.security.auth.login.LoginException)39 CallbackHandler (javax.security.auth.callback.CallbackHandler)30 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)24 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)21 RealmCallback (javax.security.sasl.RealmCallback)19 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)18 FailedLoginException (javax.security.auth.login.FailedLoginException)16 LoginContext (javax.security.auth.login.LoginContext)15 Test (org.junit.Test)15 Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)14 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)14 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)14 Subject (javax.security.auth.Subject)13 IdRepoException (com.sun.identity.idm.IdRepoException)12