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