本文整理汇总了Java中com.sun.security.auth.callback.TextCallbackHandler类的典型用法代码示例。如果您正苦于以下问题:Java TextCallbackHandler类的具体用法?Java TextCallbackHandler怎么用?Java TextCallbackHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextCallbackHandler类属于com.sun.security.auth.callback包,在下文中一共展示了TextCallbackHandler类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.sun.security.auth.callback.TextCallbackHandler; //导入依赖的package包/类
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");
}
}
示例2: loginAndAction
import com.sun.security.auth.callback.TextCallbackHandler; //导入依赖的package包/类
public static void loginAndAction(String name, PrivilegedExceptionAction action)
throws LoginException, PrivilegedActionException {
// Create a callback handler
CallbackHandler callbackHandler = new TextCallbackHandler();
LoginContext context = null;
try {
// Create a LoginContext with a callback handler
context = new LoginContext(name, callbackHandler);
// Perform authentication
context.login();
} catch (LoginException e) {
System.err.println("Login failed");
e.printStackTrace();
System.exit(-1);
}
// Perform action as authenticated user
Subject subject = context.getSubject();
if (verbose) {
System.out.println(subject.toString());
} else {
System.out.println("Authenticated principal: " + subject.getPrincipals());
}
Subject.doAs(subject, action);
context.logout();
}
示例3: main
import com.sun.security.auth.callback.TextCallbackHandler; //导入依赖的package包/类
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)});
}
示例4: main
import com.sun.security.auth.callback.TextCallbackHandler; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.setIn(new ByteArrayInputStream(new byte[0]));
try {
new TextCallbackHandler().handle(new Callback[] {
new NameCallback("Name: ") }
);
} catch (IOException ioe) {
// This is OK
}
}
示例5: main
import com.sun.security.auth.callback.TextCallbackHandler; //导入依赖的package包/类
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()));
}
示例6: getDeprivilegedClasses
import com.sun.security.auth.callback.TextCallbackHandler; //导入依赖的package包/类
private static List<Class<?>> getDeprivilegedClasses() {
List<Class<?>> classes = new ArrayList<Class<?>>();
// Test from java.xml.crypto/javax/xml/crypto/dsig package
classes.add(XMLSignatureFactory.class);
// Test from java.xml.crypto/javax/xml/crypto package
classes.add(KeySelectorException.class);
// Test From java.security.jgss/javax/security/auth/kerberos package
classes.add(KeyTab.class);
// Test from jdk.security.jgss/com/sun/security/jgss package
classes.add(AuthorizationDataEntry.class);
// Test from jdk.security.auth/com/sun/security/auth/callback package
classes.add(TextCallbackHandler.class);
return classes;
}