use of com.sun.security.auth.callback.TextCallbackHandler in project jdk8u_jdk by JetBrains.
the class PrincipalSystemPropTest method runTest.
private static void runTest(boolean expected, String jaasConfigEntry, String expectedLoginUser, String loginUserBySysProp) {
if (loginUserBySysProp != null) {
System.setProperty("sun.security.krb5.principal", loginUserBySysProp);
} else {
System.clearProperty("sun.security.krb5.principal");
}
try {
LoginContext lc = new LoginContext(jaasConfigEntry, new TextCallbackHandler());
lc.login();
System.out.println(String.format("Authentication completed with Subject '%s' ", lc.getSubject()));
if (!expected) {
throw new RuntimeException("TEST FAILED - JAAS login success isn't expected");
}
if (expectedLoginUser != null && !lc.getSubject().getPrincipals().stream().map(p -> p.getName()).filter(expectedLoginUser::equals).findFirst().isPresent()) {
throw new RuntimeException(String.format("TEST FAILED - Login principal is not matched " + "to expected principal '%s'.", expectedLoginUser));
}
System.out.println("TEST PASSED - JAAS login success is expected.");
} catch (LoginException ie) {
System.out.println(String.format("Authentication failed with exception: %s", ie.getMessage()));
if (expected) {
System.out.println("TEST FAILED - JAAS login failure isn't expected");
throw new RuntimeException(ie);
}
System.out.println("TEST PASSED - JAAS login failure is expected.");
}
}
use of com.sun.security.auth.callback.TextCallbackHandler in project jdk8u_jdk by JetBrains.
the class Default method main.
public static void main(String[] args) throws Exception {
TextCallbackHandler h = new TextCallbackHandler();
NameCallback nc = new NameCallback("Name: ", "charlie");
ConfirmationCallback cc = new ConfirmationCallback("Correct?", ConfirmationCallback.INFORMATION, ConfirmationCallback.YES_NO_OPTION, ConfirmationCallback.NO);
Callback[] callbacks = { nc, cc };
h.handle(callbacks);
if (cc.getSelectedIndex() == ConfirmationCallback.YES) {
System.out.println("yes");
} else {
System.out.println("no");
}
}
use of com.sun.security.auth.callback.TextCallbackHandler in project jdk8u_jdk by JetBrains.
the class GSSUtil method login.
/**
* Authenticate using the login module from the specified
* configuration entry.
*
* @param caller the caller of JAAS Login
* @param mech the mech to be used
* @return the authenticated subject
*/
public static Subject login(GSSCaller caller, Oid mech) throws LoginException {
CallbackHandler cb = null;
if (caller instanceof HttpCaller) {
cb = new sun.net.www.protocol.http.spnego.NegotiateCallbackHandler(((HttpCaller) caller).info());
} else {
String defaultHandler = java.security.Security.getProperty(DEFAULT_HANDLER);
// get the default callback handler
if ((defaultHandler != null) && (defaultHandler.length() != 0)) {
cb = null;
} else {
cb = new TextCallbackHandler();
}
}
// New instance of LoginConfigImpl must be created for each login,
// since the entry name is not passed as the first argument, but
// generated with caller and mech inside LoginConfigImpl
LoginContext lc = new LoginContext("", null, cb, new LoginConfigImpl(caller, mech));
lc.login();
return lc.getSubject();
}
use of com.sun.security.auth.callback.TextCallbackHandler in project jdk8u_jdk by JetBrains.
the class Password method main.
public static void main(String[] args) throws Exception {
TextCallbackHandler h = new TextCallbackHandler();
PasswordCallback nc = new PasswordCallback("Invisible: ", false);
PasswordCallback nc2 = new PasswordCallback("Visible: ", true);
System.out.println("Two passwords will be prompted for. The first one " + "should have echo off, the second one on. Otherwise, this test fails");
Callback[] callbacks = { nc, nc2 };
h.handle(callbacks);
System.out.println("You input " + new String(nc.getPassword()) + " and " + new String(nc2.getPassword()));
}
use of com.sun.security.auth.callback.TextCallbackHandler in project jdk8u_jdk by JetBrains.
the class Confirm method main.
public static void main(String[] args) throws Exception {
// Provide answer in an individual stream so that the program
// does not block.
System.setIn(new ByteArrayInputStream("1\n".getBytes()));
new TextCallbackHandler().handle(new Callback[] { new ConfirmationCallback("Prince", ConfirmationCallback.INFORMATION, new String[] { "To be", "Not to be" }, 0) });
}
Aggregations