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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations