use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class AMLoginContext method executeLogin.
/**
* Starts login process, the map passed to this method is the parameters
* required to start the login process. These parameters are
* <code>indexType</code>, <code>indexName</code> , <code>principal</code>,
* <code>subject</code>, <code>password</code>,
* <code>organization name</code>. Based on these parameters Module
* Configuration name is retrieved using Configuration component. Creates
* a new LoginContext and starts login process and returns. On error
* LoginException is thrown.
*
* @param loginParamsMap login parameters HashMap
* @throws AuthLoginException if execute login fails
*/
public void executeLogin(Map<String, Object> loginParamsMap) throws AuthLoginException {
boolean errorState = false;
internalAuthError = false;
processDone = false;
isFailed = false;
setLoginHash();
/*
* Ensure loginState created and loginParamsMap provided
*/
if (loginState == null || loginParamsMap == null) {
debug.error("Error: loginState or loginParams is null");
loginStatus.setStatus(LoginStatus.AUTH_FAILED);
if (loginState != null) {
loginState.setErrorCode(AMAuthErrorCode.AUTH_ERROR);
}
setErrorMsgAndTemplate();
internalAuthError = true;
throw new AuthLoginException(BUNDLE_NAME, AMAuthErrorCode.AUTH_ERROR, null);
}
/*
* Lookup resource bundle and locale specific settings based on locale associated with LoginState
*/
java.util.Locale loginLocale = com.sun.identity.shared.locale.Locale.getLocale(loginState.getLocale());
bundle = AMResourceBundleCache.getInstance().getResBundle(BUNDLE_NAME, loginLocale);
exceedRetryLimit = AMResourceBundleCache.getInstance().getResBundle("amAuthLDAP", loginLocale).getString(ISAuthConstants.EXCEED_RETRY_LIMIT);
if (debug.messageEnabled()) {
debug.message("LoginState : " + loginState);
}
/*
* Handle redirection if applicable
*/
String redirectUrl = (String) loginParamsMap.get(AuthContextLocal.REDIRECT_URL);
if (redirectUrl != null) {
// Resource/IP/Env based auth case with Redirection Advice
Callback[] redirectCallback = new Callback[1];
redirectCallback[0] = new RedirectCallback(redirectUrl, null, "GET");
if (isPureJAAS()) {
loginState.setReceivedCallback_NoThread(redirectCallback);
} else {
loginState.setReceivedCallback(redirectCallback, this);
}
return;
}
/*
* Initialize instance fields from loginParamsMap
*/
parseLoginParams(loginParamsMap);
/*
* Copy orgDN and clientType values from LoginState
*/
if (authContext.getOrgDN() != null && !authContext.getOrgDN().isEmpty()) {
orgDN = authContext.getOrgDN();
loginState.setQualifiedOrgDN(orgDN);
} else {
orgDN = loginState.getOrgDN();
}
clientType = loginState.getClientType();
if (debug.messageEnabled()) {
debug.message("orgDN : " + orgDN);
debug.message("clientType : " + clientType);
}
/*
* Throw an exception if module-based authentication is disabled and an authentication module other
* than APPLICATION_MODULE or FEDERATION_MODULE is explicitly requested.
*/
if (indexType == IndexType.MODULE_INSTANCE && !loginState.getEnableModuleBasedAuth() && !indexName.equals(ISAuthConstants.APPLICATION_MODULE)) {
String moduleClassName = null;
try {
AMAuthenticationManager authManager = new AMAuthenticationManager(AccessController.doPrivileged(AdminTokenAction.getInstance()), orgDN);
AMAuthenticationInstance authInstance = authManager.getAuthenticationInstance(indexName);
moduleClassName = authInstance.getType();
} catch (AMConfigurationException amce) {
debug.error("AMLoginContext.executeLogin(): Unable to get authentication config", amce);
}
if (moduleClassName != null && !moduleClassName.equalsIgnoreCase(ISAuthConstants.FEDERATION_MODULE)) {
throwExceptionIfModuleBasedAuthenticationDisabled();
}
}
/*
* Update LoginState indexType and indexName
* (after storing current loginState indexType if required for HTTP callback processing)
*/
IndexType prevIndexType = loginState.getIndexType();
if (prevIndexType == IndexType.LEVEL || prevIndexType == IndexType.COMPOSITE_ADVICE) {
loginState.setPreviousIndexType(prevIndexType);
}
loginState.setIndexType(indexType);
loginState.setIndexName(indexName);
/*
* Delegate actual processing of requested authentication type to the dispatch method 'processIndexType'
*/
try {
if (processIndexType(indexType, indexName, orgDN)) {
return;
}
} catch (AuthLoginException le) {
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
debug.message("Error : ", le);
throw le;
} catch (Exception e) {
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
debug.message("Error : ", e);
throw new AuthLoginException(e);
}
/*
* Establish configName based on indexType, indexName, orgDN and clientType
*
* If configName can't be established, throw an exception
*/
configName = getConfigName(indexType, indexName, orgDN, clientType);
if (configName == null) {
loginState.setErrorCode(AMAuthErrorCode.AUTH_CONFIG_NOT_FOUND);
debug.message("Config not found");
setErrorMsgAndTemplate();
internalAuthError = true;
loginStatus.setStatus(LoginStatus.AUTH_FAILED);
loginState.logFailed(bundle.getString("noConfig"), "NOCONFIG");
auditor.auditLoginFailure(loginState, NO_CONFIG);
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
throw new AuthLoginException(BUNDLE_NAME, AMAuthErrorCode.AUTH_CONFIG_NOT_FOUND, null);
}
/*
* Create the LoginContext object that actually handles login/logout
*/
if (debug.messageEnabled()) {
debug.message("Creating login context object\n" + "\n orgDN : " + orgDN + "\n configName : " + configName);
}
try {
jaasCheck = AuthUtils.isPureJAASModulePresent(configName, this);
if (isPureJAAS()) {
debug.message("Using pure jaas mode.");
if (authThread == null) {
authThread = new AuthThreadManager();
authThread.start();
}
}
DSAMECallbackHandler dsameCallbackHandler = new DSAMECallbackHandler(this);
if (isPureJAAS()) {
if (subject != null) {
loginContext = new javax.security.auth.login.LoginContext(configName, subject, dsameCallbackHandler);
} else {
loginContext = new javax.security.auth.login.LoginContext(configName, dsameCallbackHandler);
}
} else {
debug.message("Using non pure jaas mode.");
if (subject != null) {
jaasLoginContext = new com.sun.identity.authentication.jaas.LoginContext(entries, subject, dsameCallbackHandler);
} else {
jaasLoginContext = new com.sun.identity.authentication.jaas.LoginContext(entries, dsameCallbackHandler);
}
}
} catch (AuthLoginException ae) {
debug.error("JAAS module for config: " + configName + ", " + ae.getMessage());
if (debug.messageEnabled()) {
debug.message("AuthLoginException", ae);
}
/* The user based authentication errors should not be different
* for users who exist and who don't, which can lead to
* possiblity of enumerating existing users.
* The AMAuthErrorCode.AUTH_LOGIN_FAILED error code is used for
* all user based authentication errors.
* Refer issue3278
*/
if (indexType == IndexType.USER && AMAuthErrorCode.AUTH_CONFIG_NOT_FOUND.equals(ae.getErrorCode())) {
loginState.setErrorCode(AMAuthErrorCode.AUTH_LOGIN_FAILED);
} else {
loginState.setErrorCode(ae.getErrorCode());
}
setErrorMsgAndTemplate();
loginState.logFailed(bundle.getString("loginContextCreateFailed"));
auditor.auditLoginFailure(loginState);
internalAuthError = true;
loginStatus.setStatus(LoginStatus.AUTH_FAILED);
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
throw ae;
} catch (LoginException le) {
debug.error("in creating LoginContext.");
if (debug.messageEnabled()) {
debug.message("Exception ", le);
}
loginState.setErrorCode(AMAuthErrorCode.AUTH_ERROR);
loginState.logFailed(bundle.getString("loginContextCreateFailed"));
auditor.auditLoginFailure(loginState);
setErrorMsgAndTemplate();
loginStatus.setStatus(LoginStatus.AUTH_FAILED);
internalAuthError = true;
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
throw new AuthLoginException(BUNDLE_NAME, AMAuthErrorCode.AUTH_ERROR, null, le);
} catch (SecurityException se) {
debug.error("security in creating LoginContext.");
if (debug.messageEnabled()) {
debug.message("Exception ", se);
}
loginState.setErrorCode(AMAuthErrorCode.AUTH_ERROR);
setErrorMsgAndTemplate();
loginState.logFailed(bundle.getString("loginContextCreateFailed"));
auditor.auditLoginFailure(loginState);
internalAuthError = true;
loginStatus.setStatus(LoginStatus.AUTH_FAILED);
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
throw new AuthLoginException(BUNDLE_NAME, AMAuthErrorCode.AUTH_ERROR, null);
} catch (Exception e) {
debug.error("Creating DSAMECallbackHandler: " + e.getMessage());
loginState.setErrorCode(AMAuthErrorCode.AUTH_ERROR);
setErrorMsgAndTemplate();
loginState.logFailed(bundle.getString("loginContextCreateFailed"));
auditor.auditLoginFailure(loginState);
internalAuthError = true;
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
loginStatus.setStatus(LoginStatus.AUTH_FAILED);
throw new AuthLoginException(BUNDLE_NAME, AMAuthErrorCode.AUTH_ERROR, null, e);
}
/*
* Perform the login using the objects this method has setup
*/
try {
if (isPureJAAS()) {
if (jaasThread != null) {
jaasThread.interrupt();
jaasThread = null;
errorState = true;
} else {
jaasThread = new JAASLoginThread(this);
jaasThread.start();
}
} else {
runLogin();
}
} catch (IllegalThreadStateException ite) {
errorState = true;
} catch (Exception e) {
errorState = true;
}
if (errorState) {
loginStatus.setStatus(LoginStatus.AUTH_RESET);
loginState.setErrorCode(AMAuthErrorCode.AUTH_ERROR);
setErrorMsgAndTemplate();
internalAuthError = true;
if (MonitoringUtil.isRunning()) {
if (authImpl == null) {
authImpl = Agent.getAuthSvcMBean();
}
if (authImpl != null) {
authImpl.incSsoServerAuthenticationFailureCount();
}
}
throw new AuthLoginException(BUNDLE_NAME, AMAuthErrorCode.AUTH_ERROR, null);
}
debug.message("AMLoginContext:Thread started... returning.");
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class AMLoginContext method getRequiredInfo.
/**
* Returns array of received callbacks from module.
*
* @return array of received callbacks from module.
*/
public Callback[] getRequiredInfo() {
if (loginStatus.getStatus() != LoginStatus.AUTH_IN_PROGRESS) {
return null;
}
if (indexType == IndexType.LEVEL || indexType == IndexType.COMPOSITE_ADVICE) {
debug.message("IndexType level/composite_advice, send choice callback");
// reset indexType since UI will start module based auth
indexType = null;
} else {
if (isPureJAAS()) {
recdCallback = getRequiredInfoCallback();
} else {
recdCallback = getRequiredInfoCallback_NoThread();
}
}
if (recdCallback != null) {
if (debug.messageEnabled()) {
for (Callback callback : recdCallback) {
debug.message("Recd Callback in amlc.getRequiredInfo : " + callback);
}
}
} else {
debug.message("Recd Callback in amlc.getRequiredInfo is NULL");
}
return recdCallback;
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class CompositeAdvices method createChoiceCallback.
/**
* Returns array of choice callback.
* Get module matching the level and generate choice callback.
* @return array of choice callback.
* @throws AuthException
*/
public Callback[] createChoiceCallback() throws AuthException {
debug.message("In createChoiceCallback");
String[] moduleList = getModuleList();
Callback[] callbacks = new Callback[1];
try {
ChoiceCallback choiceCallback = new ChoiceCallback(Locale.getString(rb, "modulePrompt", debug), moduleList, 0, false);
callbacks[0] = choiceCallback;
} catch (IllegalArgumentException ie) {
debug.error("Number of arguments not correct", ie);
throw new AuthException("callbackError", null);
} catch (Exception e) {
debug.error("Error: ", e);
throw new AuthException("callbackError", null);
}
if (debug.messageEnabled()) {
debug.message("Callback is.. :" + callbacks[0]);
}
return callbacks;
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class AuthLevel method createChoiceCallback.
/**
* Returns choice callback. Gets module matching the level and
* generates choice callback.
*
* @return choice callback.
* @throws AuthException
*/
public Callback[] createChoiceCallback() throws AuthException {
debug.message("In createChoiceCallback");
String[] moduleList = getModuleList();
Callback[] callbacks = new Callback[1];
try {
ChoiceCallback choiceCallback = new ChoiceCallback(Locale.getString(rb, "modulePrompt", debug), moduleList, 0, false);
callbacks[0] = choiceCallback;
} catch (IllegalArgumentException ie) {
debug.error("Number of arguments not correct", ie);
throw new AuthException("callbackError", null);
} catch (Exception e) {
debug.error("Error: ", e);
throw new AuthException("callbackError", null);
}
if (debug.messageEnabled()) {
debug.message("Callback is.. :" + callbacks[0]);
}
return callbacks;
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class ServerConfigMgr method authenticateDsameUser.
private static boolean authenticateDsameUser(SSOToken ssoToken, String oldPassword, String newPassword) {
Callback[] idCallbacks = new Callback[2];
NameCallback nameCallback = new NameCallback("dummy");
nameCallback.setName("dsameuser");
idCallbacks[0] = nameCallback;
PasswordCallback passwordCallback = new PasswordCallback("dummy", false);
passwordCallback.setPassword(oldPassword.toCharArray());
idCallbacks[1] = passwordCallback;
try {
AMIdentityRepository amir = new AMIdentityRepository("/", ssoToken);
if (!amir.authenticate(idCallbacks)) {
passwordCallback.setPassword(newPassword.toCharArray());
return amir.authenticate(idCallbacks);
}
return true;
} catch (AuthLoginException ex) {
return false;
} catch (IdRepoException ex) {
return false;
}
}
Aggregations