本文整理汇总了Java中javax.security.auth.callback.NameCallback.getName方法的典型用法代码示例。如果您正苦于以下问题:Java NameCallback.getName方法的具体用法?Java NameCallback.getName怎么用?Java NameCallback.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.auth.callback.NameCallback
的用法示例。
在下文中一共展示了NameCallback.getName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newInstance
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public SaslMechanism newInstance(CallbackHandler callbackHandler,
Map<String, ?> sharedState,
Map<String, ?> options) {
NameCallback nameCallback = new NameCallback("Username: ");
PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
try {
callbackHandler.handle(new Callback[] { nameCallback, passwordCallback });
} catch (IOException ioe) {
return null;
} catch (UnsupportedCallbackException e) {
return null;
}
return new PlainMechanism(nameCallback.getName(), passwordCallback.getPassword());
}
示例2: login
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public boolean login() throws LoginException {
if (debug) {
logger.debug(this.getClass().getName() + " login called.");
}
if (Constants.FEDORA_HOME == null || "".equals(Constants.FEDORA_HOME.trim())) {
logger.error("FEDORA_HOME constant is not set");
return false;
}
final NameCallback nc = new NameCallback("username");
final PasswordCallback pc = new PasswordCallback("password", false);
final Callback[] callbacks = new Callback[] {
nc, pc
};
try {
handler.handle(callbacks);
} catch (IOException ioe) {
ioe.printStackTrace();
throw new LoginException("IOException occured: " + ioe.getMessage());
} catch (UnsupportedCallbackException ucbe) {
ucbe.printStackTrace();
throw new LoginException("UnsupportedCallbackException encountered: "
+ ucbe.getMessage());
}
// Grab the username and password from the callbacks.
final String username = nc.getName();
final String password = new String(pc.getPassword());
successLogin = authenticate(username, password);
return successLogin;
}
示例3: login
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public boolean login() throws LoginException {
NameCallback userNameCallback = new NameCallback("userName");
PasswordCallback passwordCallback = new PasswordCallback("password", false);
Callback[] callbacks = { userNameCallback, passwordCallback };
try {
callbackHandler.handle(callbacks);
} catch (IOException | UnsupportedCallbackException e) {
throw new BrokerAuthenticationException("Error while handling callback ", e);
}
String userName = userNameCallback.getName();
char[] password = passwordCallback.getPassword();
return userName.equals("user") && Arrays.equals(password, new char[] { 'p', 'a', 's', 's' });
}
示例4: getUsernameAndPassword
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
/**
* Called by login() to acquire the username and password strings for authentication. This method does no validation
* of either.
*
* @return String[], [0] = username, [1] = password
*/
private String[] getUsernameAndPassword() throws LoginException {
if (callbackHandler == null) {
throw new LoginException("No CallbackHandler available to collect authentication information");
}
NameCallback nc = new NameCallback("User name: ", "guest");
PasswordCallback pc = new PasswordCallback("Password: ", false);
Callback[] callbacks = { nc, pc };
String username = null;
String password = null;
try {
callbackHandler.handle(callbacks);
username = nc.getName();
char[] tmpPassword = pc.getPassword();
if (tmpPassword != null) {
credential = new char[tmpPassword.length];
System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length);
pc.clearPassword();
password = new String(credential);
}
} catch (IOException ioe) {
throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
throw new LoginException("CallbackHandler does not support: " + uce.getCallback());
}
return new String[] { username, password };
}
示例5: handle
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
iHandler.handle(callbacks);
if (iRealm != null)
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nc = (NameCallback) callback;
if (nc.getName() != null && !nc.getName().contains("@"))
nc.setName(nc.getName() + "@" + iRealm);
}
}
}
示例6: setTheAlias
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
/**
* Set the alias to delete from the key store.
* <p>
* Unlike in other keytool handlers, the default value (<i>mykey</i>) for the
* Alias is not used. Instead, if an alias was not found on the command line,
* the user is prompted to enter one.
*
* @param anAlias a possibly null Alias gleaned from the command line.
* @throws IOException if an I/O related exception occurs during the process.
* @throws UnsupportedCallbackException if no implementation of a password
* callback handler was found.
*/
private void setTheAlias(String anAlias) throws IOException,
UnsupportedCallbackException
{
if (anAlias == null || anAlias.trim().length() == 0)
{
String prompt = Messages.getString("DeleteCmd.19"); //$NON-NLS-1$
NameCallback ncb = new NameCallback(prompt);
getCallbackHandler().handle(new Callback[] { ncb });
anAlias = ncb.getName();
if (anAlias == null || anAlias.trim().length() == 0)
throw new SecurityException(Messages.getString("DeleteCmd.20")); //$NON-NLS-1$
}
alias = anAlias.trim();
}
示例7: setDestinationAlias
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
private void setDestinationAlias(String name) throws IOException,
UnsupportedCallbackException
{
if (name == null || name.trim().length() == 0) // ask user to provide one
{
NameCallback ncb = new NameCallback(Messages.getString("KeyCloneCmd.26")); //$NON-NLS-1$
getCallbackHandler().handle(new Callback[] { ncb });
name = ncb.getName();
if (name == null || name.trim().length() == 0)
throw new IllegalArgumentException(Messages.getString("KeyCloneCmd.27")); //$NON-NLS-1$
}
destinationAlias = name.trim();
}
示例8: isAuthenticatedUsingCerts
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
private boolean isAuthenticatedUsingCerts(List<X509Certificate> certs) throws IOException, UnsupportedCallbackException {
NameCallback nameHandler = new NameCallback("user:");
CertificateCallback certificateCallback = new CertificateCallback();
callbackHandler.handle(new Callback[] { nameHandler, certificateCallback });
X509Certificate[] certArray = certificateCallback.getCertificates();
if(certArray != null) {
certs.addAll(Arrays.asList(certArray));
}
return nameHandler.getName() == null && !certs.isEmpty();
}
示例9: login
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
@Override
public boolean login() throws LoginException {
if (debug) {
logger.debug(String.format("%s login called.", DrupalMultisiteAuthModule.class.getName()));
for (String key : sharedState.keySet()) {
String value = sharedState.get(key).toString();
logger.debug(key + ": " + value);
}
}
String[] keys = config.keySet().toArray(new String[0]);
NameCallback nc = new NameCallback("username");
PasswordCallback pc = new PasswordCallback("password", false);
KeyChoiceCallback kcc = new KeyChoiceCallback(keys);
Callback[] callbacks = new Callback[] {
nc, pc, kcc
};
try {
handler.handle(callbacks);
username = nc.getName();
char[] passwordCharArray = pc.getPassword();
String password = new String(passwordCharArray);
int[] key_selections = kcc.getSelectedIndexes();
// Should only be exactly one item in key_selections; however,
// let's iterate for brevity.
for (int i : key_selections) {
findUser(username, password, keys[i]);
}
}
catch (IOException ioe) {
ioe.printStackTrace();
throw new LoginException("IOException occured: " + ioe.getMessage());
}
catch (MissingCredsException mce) {
throw new CredentialNotFoundException(
String.format("Missing \"key\", required for module %s.", this.getClass().getName()));
}
catch (UnsupportedCallbackException ucbe) {
throw new LoginException("UnsupportedCallbackException: " + ucbe.getMessage());
}
return successLogin;
}
示例10: saveAlias
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
private void saveAlias(NameCallback cb) {
keyStoreAlias = cb.getName();
}