Search in sources :

Example 41 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project alluxio by Alluxio.

the class PlainSaslServerCallbackHandlerTest method authenticateNameMatch.

/**
   * Tests that the authentication callbacks matches.
   *
   * @throws Exception thrown if the handler fails
   */
@Test
public void authenticateNameMatch() throws Exception {
    String authenticateId = "alluxio-1";
    NameCallback ncb = new NameCallback(" authentication id: ");
    ncb.setName(authenticateId);
    PasswordCallback pcb = new PasswordCallback(" password: ", false);
    pcb.setPassword("password".toCharArray());
    Callback[] callbacks = new Callback[] { ncb, pcb, new AuthorizeCallback(authenticateId, authenticateId) };
    mPlainServerCBHandler.handle(callbacks);
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) Test(org.junit.Test)

Example 42 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 43 with PasswordCallback

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

the class CommandLineTokenLoginCallback method handle.

@Override
public synchronized void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof PasswordCallback) {
            final Console cons = System.console();
            char[] passwd = null;
            if (cons != null) {
                passwd = cons.readPassword("[%s]", "Enter hardware token password: ");
                java.util.Arrays.fill(passwd, ' ');
            } else {
                System.out.print("Enter hardware token password: ");
                final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                passwd = reader.readLine().toCharArray();
            }
            ((PasswordCallback) callback).setPassword(passwd);
        }
    }
    this.notifyAll();
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) InputStreamReader(java.io.InputStreamReader) Console(java.io.Console) BufferedReader(java.io.BufferedReader) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 44 with PasswordCallback

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

the class TokenLoginCallback method handle.

@Override
public synchronized void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof PasswordCallback) {
            final JPanel panel = new JPanel();
            final JLabel label = new JLabel("Enter hardware token password:");
            final JPasswordField pass = new JPasswordField(20);
            panel.add(label);
            panel.add(pass);
            final String[] options = new String[] { "OK", "Cancel" };
            int option = JOptionPane.showOptionDialog(null, panel, "Token ", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
            if (// pressing OK button
            option == JOptionPane.OK_OPTION) {
                ((PasswordCallback) callback).setPassword(pass.getPassword());
            }
        }
    }
    this.notifyAll();
}
Also used : JPanel(javax.swing.JPanel) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) JPasswordField(javax.swing.JPasswordField) PasswordCallback(javax.security.auth.callback.PasswordCallback) JLabel(javax.swing.JLabel)

Example 45 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)

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