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