use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class HTTPBasic method authenticateToBackEndModule.
private int authenticateToBackEndModule() throws LoginException {
Callback[] callbacks = new Callback[2];
NameCallback nameCallback = new NameCallback("dummy");
nameCallback.setName(userName);
callbacks[0] = nameCallback;
PasswordCallback passwordCallback = new PasswordCallback("dummy", false);
passwordCallback.setPassword(userPassword.toCharArray());
callbacks[1] = passwordCallback;
return amLoginModule.process(callbacks, ISAuthConstants.LOGIN_START);
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class LDAP method processLoginScreen.
private void processLoginScreen(ModuleState newState) throws AuthLoginException {
try {
switch(newState) {
case SUCCESS:
validatedUserID = ldapUtil.getUserId();
createProfile();
currentState = ISAuthConstants.LOGIN_SUCCEED;
setForceCallbacksRead(false);
break;
case PASSWORD_EXPIRING:
{
String fmtMsg = bundle.getString("PasswordExp");
String msg = com.sun.identity.shared.locale.Locale.formatMessage(fmtMsg, ldapUtil.getExpTime());
/**
* In case of sharedstate if the chain breaks in ldap
* because of abnormal condition like pwd expiring
* then the callbacks has to be read fresh so that new
* screen appears for the user.
*/
setForceCallbacksRead(true);
forceCallbacksInit();
replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), msg);
}
currentState = LoginScreen.PASSWORD_CHANGE.intValue();
break;
case PASSWORD_RESET_STATE:
case CHANGE_AFTER_RESET:
isReset = true;
String resetMsg = bundle.getString("PasswordReset");
/**
* In case of sharedstate if the chain breaks in ldap
* because of abnormal condition like pwd reset
* then the callbacks has to be read fresh so that new
* screen appears for the user.
*/
setForceCallbacksRead(true);
forceCallbacksInit();
replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), resetMsg);
currentState = LoginScreen.PASSWORD_CHANGE.intValue();
break;
case PASSWORD_EXPIRED_STATE:
setFailureID(ldapUtil.getUserId(userName));
currentState = LoginScreen.PASSWORD_EXPIRED_SCREEN.intValue();
break;
case ACCOUNT_LOCKED:
setFailureID(ldapUtil.getUserId(userName));
currentState = LoginScreen.ACCOUNT_LOCKED.intValue();
break;
case GRACE_LOGINS:
{
String fmtMsg = bundle.getString("GraceLogins");
String msg = com.sun.identity.shared.locale.Locale.formatMessage(fmtMsg, ldapUtil.getGraceLogins());
setForceCallbacksRead(true);
forceCallbacksInit();
if (ldapUtil.getGraceLogins() == 1) {
Callback[] callback = getCallback(LoginScreen.PASSWORD_CHANGE.intValue());
for (int i = 0; i < callback.length; i++) {
Callback cbk = callback[i];
if (cbk instanceof ConfirmationCallback) {
ConfirmationCallback confirm = (ConfirmationCallback) cbk;
String[] options = confirm.getOptions();
String[] newOptions = new String[1];
System.arraycopy(options, 0, newOptions, 0, 1);
ConfirmationCallback newConfirm = new ConfirmationCallback(confirm.getMessageType(), newOptions, confirm.getDefaultOption());
replaceCallback(LoginScreen.PASSWORD_CHANGE.intValue(), i, newConfirm);
}
}
}
replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), msg);
}
currentState = LoginScreen.PASSWORD_CHANGE.intValue();
break;
case TIME_BEFORE_EXPIRATION:
{
String fmtMsg = bundle.getString("TimeBeforeExpiration");
String msg = com.sun.identity.shared.locale.Locale.formatMessage(fmtMsg, ldapUtil.getExpTime());
setForceCallbacksRead(true);
forceCallbacksInit();
replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), msg);
}
currentState = LoginScreen.PASSWORD_CHANGE.intValue();
case USER_NOT_FOUND:
throw new LDAPUtilException("noUserMatchFound", (Object[]) null);
case SERVER_DOWN:
throw new AuthLoginException(AM_AUTH, "LDAPex", null);
default:
}
} catch (LDAPUtilException ex) {
if (getCredentialsFromSharedState && !isUseFirstPassEnabled()) {
getCredentialsFromSharedState = false;
currentState = LoginScreen.LOGIN_START.intValue();
return;
}
if (newState != ModuleState.USER_NOT_FOUND) {
debug.error("Unknown Login State:", ex);
}
throw new AuthLoginException(AM_AUTH, "LDAPex", null, ex);
}
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class LDAPCallbacks method chgPwdCallback.
private void chgPwdCallback() throws LoginException {
char[] pwd = null;
if (callbackHandler == null) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
}
Callback[] callbacks = new Callback[4];
callbacks[0] = new TextOutputCallback(TextOutputCallback.INFORMATION, "Change Password");
callbacks[1] = new PasswordCallback("EnterOld Password", false);
callbacks[2] = new PasswordCallback("Enter New Password", false);
callbacks[3] = new PasswordCallback("Confirm Password", false);
try {
callbackHandler.handle(callbacks);
oldPassword = charToString(((PasswordCallback) callbacks[1]).getPassword(), callbacks[1]);
newPassword = charToString(((PasswordCallback) callbacks[2]).getPassword(), callbacks[2]);
confirmPassword = charToString(((PasswordCallback) callbacks[3]).getPassword(), callbacks[3]);
} catch (java.io.IOException ioe) {
throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
}
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class Membership method updateRegistrationCallbackFields.
private void updateRegistrationCallbackFields(Callback[] submittedCallbacks) throws AuthLoginException {
Callback[] origCallbacks = getCallback(ModuleState.REGISTRATION.intValue());
for (int c = 0; c < origCallbacks.length; c++) {
if (origCallbacks[c] instanceof NameCallback) {
NameCallback nc = (NameCallback) origCallbacks[c];
nc.setName(((NameCallback) submittedCallbacks[c]).getName());
replaceCallback(ModuleState.REGISTRATION.intValue(), c, nc);
} else if (origCallbacks[c] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) origCallbacks[c];
pc.setPassword(((PasswordCallback) submittedCallbacks[c]).getPassword());
replaceCallback(ModuleState.REGISTRATION.intValue(), c, pc);
} else {
continue;
}
}
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class Membership method loginUser.
private ModuleState loginUser(Callback[] callbacks) throws AuthLoginException {
String password = null;
Callback[] idCallbacks = new Callback[2];
try {
if (callbacks != null && callbacks.length == 0) {
userName = (String) sharedState.get(getUserKey());
password = (String) sharedState.get(getPwdKey());
if (userName == null || password == null) {
return ModuleState.LOGIN_START;
}
getCredentialsFromSharedState = true;
NameCallback nameCallback = new NameCallback("dummy");
nameCallback.setName(userName);
idCallbacks[0] = nameCallback;
PasswordCallback passwordCallback = new PasswordCallback("dummy", false);
passwordCallback.setPassword(password.toCharArray());
idCallbacks[1] = passwordCallback;
} else {
idCallbacks = callbacks;
//callbacks is not null
userName = ((NameCallback) callbacks[0]).getName();
password = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());
}
if (password == null || password.length() == 0) {
if (debug.messageEnabled()) {
debug.message("Membership.loginUser: Password is null/empty");
}
throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
}
//store username password both in success and failure case
storeUsernamePasswd(userName, password);
initAuthConfig();
AMIdentityRepository idrepo = getAMIdentityRepository(getRequestOrg());
boolean success = idrepo.authenticate(idCallbacks);
if (success) {
validatedUserID = userName;
return ModuleState.COMPLETE;
} else {
throw new AuthLoginException(amAuthMembership, "authFailed", null);
}
} catch (IdRepoException ex) {
if (getCredentialsFromSharedState && !isUseFirstPassEnabled()) {
getCredentialsFromSharedState = false;
return ModuleState.LOGIN_START;
}
if (debug.warningEnabled()) {
debug.warning("idRepo Exception");
}
setFailureID(userName);
throw new AuthLoginException(amAuthMembership, "authFailed", null, ex);
}
}
Aggregations