use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class OAuth method getContent.
// Obtain the user profile information from the OAuth 2.0 Identity Provider
// Profile service configured for this module, either using first GET and
// POST as a fall back
private String getContent(String serviceUrl, String authorizationHeader) throws LoginException {
BufferedReader in = new BufferedReader(new InputStreamReader(getContentStreamByGET(serviceUrl, authorizationHeader)));
StringBuilder buf = new StringBuilder();
try {
String str;
while ((str = in.readLine()) != null) {
buf.append(str);
}
} catch (IOException ioe) {
OAuthUtil.debugError("OAuth.getContent: IOException: " + ioe.getMessage());
throw new AuthLoginException(BUNDLE_NAME, "ioe", null, ioe);
} finally {
try {
in.close();
} catch (IOException ioe) {
OAuthUtil.debugError("OAuth.getContent: IOException: " + ioe.getMessage());
throw new AuthLoginException(BUNDLE_NAME, "ioe", null, ioe);
}
}
return buf.toString();
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class Membership method process.
/**
* Takes an array of submitted <code>Callback</code>,
* process them and decide the order of next state to go.
* Return STATE_SUCCEED if the login is successful, return STATE_FAILED
* if the LoginModule should be ignored.
*
* @param callbacks an array of <code>Callback</cdoe> for this Login state
* @param state order of state. State order starts with 1.
* @return int order of next state. Return STATE_SUCCEED if authentication
* is successful, return STATE_FAILED if the
* LoginModule should be ignored.
* @throws AuthLoginException
*/
public int process(Callback[] callbacks, int state) throws AuthLoginException {
if (debug.messageEnabled()) {
debug.message("in process(), login state is " + state);
}
this.callbacks = callbacks;
ModuleState moduleState = ModuleState.get(state);
ModuleState nextState = null;
switch(moduleState) {
case LOGIN_START:
int action = 0;
// action == 0 is a Submit Button
if (callbacks != null && callbacks.length != 0) {
action = ((ConfirmationCallback) callbacks[2]).getSelectedIndex();
if (debug.messageEnabled()) {
debug.message("LOGIN page button index: " + action);
}
}
if (action == 0) {
// loginUser will attempt to validate the user and return
// the next state to display, either an error state or
// SUCCESS
nextState = loginUser(callbacks);
} else {
// new user registration
initAuthConfig();
clearInfoText(ModuleState.REGISTRATION.intValue());
nextState = ModuleState.REGISTRATION;
}
break;
case CHOOSE_USERNAMES:
// user name entered already exists, generate
// a set of user names for user to choose
nextState = chooseUserID(callbacks);
break;
case DISCLAIMER:
// when disclaimer page exists the user is created
// after the user agrees to disclaimer
// callbacks[0] is user selected button index
int agree = ((ConfirmationCallback) callbacks[0]).getSelectedIndex();
if (debug.messageEnabled()) {
debug.message("DISCLAIMER page button index: " + agree);
}
if (agree == 0) {
RegistrationResult result = registerNewUser();
if (result.equals(RegistrationResult.NO_ERROR)) {
return ISAuthConstants.LOGIN_SUCCEED;
} else {
switch(result) {
case USER_EXISTS_ERROR:
setErrorMessage(result, 0);
nextState = ModuleState.REGISTRATION;
break;
case PROFILE_ERROR:
nextState = ModuleState.PROFILE_ERROR;
break;
case NO_ERROR:
nextState = ModuleState.COMPLETE;
break;
}
}
} else if (agree == 1) {
nextState = ModuleState.DISCLAIMER_DECLINED;
} else {
throw new AuthLoginException(amAuthMembership, "loginException", null);
}
break;
case REGISTRATION:
// this is REGISTRATION state, registration will attempt to
// create a new user profile
// callbacks[len-1] is a user selected button index
// next == 0 is a Submit button
// next == 1 is a Cancel button
int next = ((ConfirmationCallback) callbacks[callbacks.length - 1]).getSelectedIndex();
if (debug.messageEnabled()) {
debug.message("REGISTRATION page button index: " + next);
}
if (next == 0) {
//clear infotexts in case they had error messages in the
//previous run
clearInfoText(ModuleState.REGISTRATION.intValue());
ModuleState result = getAndCheckRegistrationFields(callbacks);
switch(result) {
case DISCLAIMER:
nextState = processRegistrationResult();
break;
case REGISTRATION:
case CHOOSE_USERNAMES:
case PROFILE_ERROR:
if (debug.messageEnabled()) {
debug.message("Recoverable error: " + result.toString());
}
nextState = result;
break;
}
} else if (next == 1) {
clearCallbacks(callbacks);
nextState = ModuleState.LOGIN_START;
} else {
return ISAuthConstants.LOGIN_IGNORE;
}
}
return nextState.intValue();
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class Membership method initAuthConfig.
/**
* Initializes registration configurations.
*/
private void initAuthConfig() throws AuthLoginException {
if (options == null || options.isEmpty()) {
debug.error("options is null or empty");
throw new AuthLoginException(amAuthMembership, "unable-to-initialize-options", null);
}
try {
String authLevel = CollectionHelper.getMapAttr(options, "iplanet-am-auth-membership-auth-level");
if (authLevel != null) {
try {
int tmp = Integer.parseInt(authLevel);
setAuthLevel(tmp);
} catch (NumberFormatException e) {
// invalid auth level
debug.error("invalid auth level " + authLevel, e);
}
}
regEx = CollectionHelper.getMapAttr(options, INVALID_CHARS);
serviceStatus = CollectionHelper.getMapAttr(options, "iplanet-am-auth-membership-default-user-status", "Active");
if (getNumberOfStates() >= ModuleState.DISCLAIMER.intValue()) {
isDisclaimerExist = true;
} else {
isDisclaimerExist = false;
}
defaultRoles = (Set) options.get("iplanet-am-auth-membership-default-roles");
if (debug.messageEnabled()) {
debug.message("defaultRoles is : " + defaultRoles);
}
String tmp = CollectionHelper.getMapAttr(options, "iplanet-am-auth-membership-min-password-length");
if (tmp != null) {
requiredPasswordLength = Integer.parseInt(tmp);
}
} catch (Exception ex) {
debug.error("unable to initialize in initAuthConfig(): ", ex);
throw new AuthLoginException(amAuthMembership, "Membershipex", null, ex);
}
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class LoginAuthenticator method startLoginProcess.
/**
* Starts the login process by calling the appropriate login() method on the underlying AuthContextLocal.
*
* @param loginProcess The Login Process object that will maintain the login process state for the request.
* @return The Login Process object.
* @throws AuthLoginException If there is a problem starting the login process.
*/
LoginProcess startLoginProcess(LoginProcess loginProcess) throws AuthLoginException {
LoginConfiguration loginConfiguration = loginProcess.getLoginConfiguration();
HttpServletRequest request = loginConfiguration.getHttpRequest();
AuthIndexType indexType = loginConfiguration.getIndexType();
String indexValue = loginConfiguration.getIndexValue();
AuthenticationContext authContext = loginProcess.getAuthContext();
if (indexType != null && indexType.equals(AuthIndexType.RESOURCE)) {
Map<String, Set<String>> envMap = coreServicesWrapper.getEnvMap(request);
// If the resource value is the string "true" then get the value from the resourceURL or goto parameter
if (StringUtils.isBlank(indexValue) || Boolean.parseBoolean(indexValue)) {
indexValue = coreServicesWrapper.getResourceURL(request);
}
authContext.login(indexType.getIndexType(), indexValue, envMap, null);
} else if (indexType != null && indexType.getIndexType() != null) {
authContext.login(indexType.getIndexType(), indexValue);
} else {
authContext.login();
}
// When starting a new login process, add the load balancer cookies to the response.
try {
HttpServletResponse response = loginConfiguration.getHttpResponse();
coreServicesWrapper.setLbCookie(authContext.getAuthContext(), request, response);
} catch (AuthException e) {
throw new AuthLoginException(e);
}
return loginProcess;
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class AuthContextLocal method logout.
/**
* Logs out the user and also invalidates the <code>SSOToken</code>
* associated with this <code>AuthContextLocal</code>.
*
* @throws AuthLoginException if an error occurred during logout
* @supported.api
*/
public void logout() throws AuthLoginException {
authDebug.message("AuthContextLocal::logout()");
try {
amlc.logout();
} catch (Exception e) {
if (authDebug.messageEnabled()) {
authDebug.message("Exception in AMLoginContext::logout() " + e.getMessage());
}
throw new AuthLoginException(amAuthContextLocal, "logoutError", null, e);
}
authDebug.message("Called AMLoginContext::logout()");
loginStatus = AuthContext.Status.COMPLETED;
}
Aggregations