use of javax.security.auth.callback.PasswordCallback in project wildfly by wildfly.
the class CustomEjbAccessingLoginModule method getUsernameAndPassword.
protected void getUsernameAndPassword() throws LoginException {
// prompt for a username and password
if (callbackHandler == null) {
throw new LoginException("Error: no CallbackHandler available " + "to collect authentication information");
}
NameCallback nc = new NameCallback("User name: ", "guest");
PasswordCallback pc = new PasswordCallback("Password: ", false);
Callback[] callbacks = { nc, pc };
try {
callbackHandler.handle(callbacks);
username = nc.getName();
char[] tmpPassword = pc.getPassword();
if (tmpPassword != null) {
pc.clearPassword();
password = new String(tmpPassword);
}
} catch (IOException e) {
LoginException le = new LoginException("Failed to get username/password");
le.initCause(e);
throw le;
} catch (UnsupportedCallbackException e) {
LoginException le = new LoginException("CallbackHandler does not support: " + e.getCallback());
le.initCause(e);
throw le;
}
}
use of javax.security.auth.callback.PasswordCallback in project wildfly by wildfly.
the class CustomTestLoginModule method getUsernameAndPassword.
protected String[] getUsernameAndPassword() throws LoginException {
String[] info = { null, null };
// prompt for a username and password
if (callbackHandler == null) {
throw new LoginException("Error: 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) {
pc.clearPassword();
password = new String(tmpPassword);
}
} catch (IOException e) {
LoginException le = new LoginException("Failed to get username/password");
le.initCause(e);
throw le;
} catch (UnsupportedCallbackException e) {
LoginException le = new LoginException("CallbackHandler does not support: " + e.getCallback());
le.initCause(e);
throw le;
}
info[0] = username;
info[1] = password;
return info;
}
use of javax.security.auth.callback.PasswordCallback in project spring-security by spring-projects.
the class JaasPasswordCallbackHandler method handle.
// ~ Methods
// ========================================================================================================
/**
* If the callback passed to the 'handle' method is an instance of PasswordCallback,
* the JaasPasswordCallbackHandler will call,
* callback.setPassword(authentication.getCredentials().toString()).
*
* @param callback
* @param auth
*
* @throws IOException
* @throws UnsupportedCallbackException
*/
public void handle(Callback callback, Authentication auth) throws IOException, UnsupportedCallbackException {
if (callback instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callback;
pc.setPassword(auth.getCredentials().toString().toCharArray());
}
}
use of javax.security.auth.callback.PasswordCallback in project spring-security by spring-projects.
the class UsernameEqualsPasswordLoginModule method initialize.
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
this.subject = subject;
try {
NameCallback nameCallback = new NameCallback("prompt");
PasswordCallback passwordCallback = new PasswordCallback("prompt", false);
callbackHandler.handle(new Callback[] { nameCallback, passwordCallback });
password = new String(passwordCallback.getPassword());
username = nameCallback.getName();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.security.auth.callback.PasswordCallback in project felix by apache.
the class SampleConfigLoginModule method login.
@Override
public boolean login() throws LoginException {
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Name");
callbacks[1] = new PasswordCallback("Password", false);
try {
handler.handle(callbacks);
} catch (IOException e) {
throw new LoginException(e.getMessage());
} catch (UnsupportedCallbackException e) {
throw new LoginException(e.getMessage());
}
String name = ((NameCallback) callbacks[0]).getName();
char[] password = ((PasswordCallback) callbacks[1]).getPassword();
boolean result = Arrays.equals(name.toCharArray(), password);
succeeded = result;
this.name = name;
return result;
}
Aggregations