use of com.iplanet.dpro.session.service.InternalSession in project OpenAM by OpenRock.
the class LoginViewBean method getPrevSuccessURLAndSetCookie.
/** Retrieves the original AuthContext and the session,
* sets the cookie and retrieves the original
* success login url.
* @return redirect_url, a String
*/
String getPrevSuccessURLAndSetCookie() {
loginDebug.message("Restoring original Session !");
InternalSession oldSession = AuthUtils.getOldSession(ac);
clearCookieAndDestroySession(ac);
if (oldSession != null) {
ac.getLoginState().setSession(oldSession);
}
String redirect_url = oldSession.getProperty(ISAuthConstants.SUCCESS_URL);
return redirect_url;
}
use of com.iplanet.dpro.session.service.InternalSession in project OpenAM by OpenRock.
the class LogoutViewBean method forwardTo.
/**
* Forwards the request to this view bean, displaying the page. This
* method is the equivalent of <code>RequestDispatcher.forward()</code>,
* meaning that the same semantics apply to the use of this method.
* This method makes implicit use of the display URL returned
* by the <code>getDisplayURL()</code> method.
* @param requestContext servlet context for auth request
*/
public void forwardTo(RequestContext requestContext) {
SessionID sessionID = null;
SSOToken token = null;
InternalSession intSess = null;
java.util.Locale locale = null;
logoutDebug.message("In forwardTo()");
if (requestContext != null) {
request = requestContext.getRequest();
response = requestContext.getResponse();
}
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0");
gotoUrl = request.getParameter("goto");
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto query param : " + gotoUrl);
}
try {
sessionID = new SessionID(request);
intSess = AuthD.getSession(sessionID);
if (intSess != null) {
populateL10NFileAttrs(intSess);
String localeStr = intSess.getProperty(ISAuthConstants.LOCALE);
// I18N get resource bundle
locale = com.sun.identity.shared.locale.Locale.getLocale(localeStr);
fallbackLocale = locale;
} else {
ISLocaleContext localeContext = new ISLocaleContext();
localeContext.setLocale(request);
locale = localeContext.getLocale();
if (locale == null) {
String localeStr = AuthD.getAuth().getPlatformLocale();
locale = com.sun.identity.shared.locale.Locale.getLocale(localeStr);
}
}
rb = (ResourceBundle) rbCache.getResBundle("amAuthUI", locale);
clientType = AuthUtils.getClientType(request);
if (logoutDebug.messageEnabled()) {
logoutDebug.message("clienttype is : " + clientType);
}
token = SSOTokenManager.getInstance().createSSOToken(sessionID.toString());
} catch (Exception e) {
ResultVal = getL10NMessage(e, locale);
}
// Get the Login URL and query map
if (token != null) {
try {
loginURL = token.getProperty(ISAuthConstants.FULL_LOGIN_URL);
} catch (com.iplanet.sso.SSOException ssoExp) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("LogoutViewBean.forwardTo: " + " Cannot get Login URL");
}
}
}
// If there is a gotoUrl value and the orgDN is null do some additional processing
if (orgDN == null && isGotoSet()) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("OrgDN was null, getting from request for goto validation");
}
// First check if there is a org parameter in request, for example realm=/sub-realm
String orgParm = AuthUtils.getOrgParam(AuthUtils.parseRequestParameters(request));
if (orgParm == null) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Attempting to get orgDN from AuthUtils for serverName " + request.getServerName());
}
orgDN = AuthUtils.getOrganizationDN(request.getServerName(), true, request);
} else {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Attempting to get orgDN from AuthUtils for orgParm " + orgParm);
}
orgDN = AuthUtils.getOrganizationDN(orgParm, true, request);
}
if (orgDN == null) {
// Last resort, get it from the root domain
orgDN = DNMapper.orgNameToDN("/");
}
}
if (isGotoSet()) {
gotoUrl = AuthUtils.getValidGotoURL(request, orgDN);
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto after validation for orgDN: " + orgDN + " gotoUrl: " + gotoUrl);
}
}
// set the cookie Value or set the logoutcookie string in
// the case of URL rewriting otherwise set in the responsed
// header
Cookie[] cookieArr = request.getCookies();
if ((cookieArr != null) && (cookieArr.length != 0)) {
cookieSupported = true;
} else {
cookieSupported = false;
}
if (cookieSupported) {
logoutDebug.message("Cookie is supported");
AuthUtils.clearAllCookies(request, response);
} else {
logoutDebug.message("Cookie is not supported");
if ((sessionID != null) && (sessionID.toString().length() != 0)) {
logoutCookie = AuthUtils.getLogoutCookieString(sessionID);
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Logout Cookie is " + logoutCookie);
}
}
}
// get the Logout JSP page path
jsp_page = appendLogoutCookie(getFileName(LOGOUT_JSP));
if ((intSess != null) && intSess.isTimedOut()) {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto Login URL : " + loginURL);
}
if (doSendRedirect(loginURL)) {
response.sendRedirect(appendLogoutCookie(loginURL));
return;
} else {
int queryIndex = loginURL.indexOf("?");
String qString = null;
if (queryIndex != -1) {
qString = loginURL.substring(queryIndex);
}
if (qString != null) {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP) + qString);
} else {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
}
}
} catch (Exception e) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Redirect failed : " + loginURL, e);
}
ResultVal = getL10NMessage(e, locale);
}
super.forwardTo(requestContext);
return;
}
boolean wasTokenValid = false;
try {
wasTokenValid = AuthUtils.logout(intSess, token, request, response);
ResultVal = rb.getString("logout.successful");
String postProcessURL = AuthUtils.getPostProcessURL(request, AMPostAuthProcessInterface.POST_PROCESS_LOGOUT_URL);
if (postProcessURL != null) {
gotoUrl = postProcessURL;
}
} catch (SSOException ssoe) {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Exception during logout", ssoe);
logoutDebug.message("Goto Login URL : " + LOGINURL);
}
if (doSendRedirect(LOGINURL)) {
response.sendRedirect(appendLogoutCookie(LOGINURL));
return;
} else {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
}
} catch (Exception ex) {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Redirect failed:" + LOGINURL, ex);
}
ResultVal = ex.getMessage();
}
super.forwardTo(requestContext);
return;
}
if (!wasTokenValid) {
if (!isGotoSet()) {
String originalRedirectURL = AuthUtils.getOrigRedirectURL(request, sessionID);
if (originalRedirectURL != null) {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Original Redirect URL: " + originalRedirectURL);
}
int index = originalRedirectURL.indexOf("/Login");
if (index != -1) {
originalRedirectURL = originalRedirectURL.substring(0, index) + "/Logout";
}
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Redirect to Original Redirect URL :" + originalRedirectURL);
}
if (doSendRedirect(originalRedirectURL)) {
response.sendRedirect(appendLogoutCookie(originalRedirectURL));
return;
}
} catch (Exception e) {
ResultVal = getL10NMessage(e, locale);
}
} else {
try {
if (logoutDebug.messageEnabled()) {
logoutDebug.message("Goto LOGINURL : " + LOGINURL);
}
if (doSendRedirect(LOGINURL)) {
response.sendRedirect(appendLogoutCookie(LOGINURL));
return;
} else {
jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
}
} catch (Exception e) {
ResultVal = getL10NMessage(e, locale);
}
}
}
}
if (!redirectToGoto(locale)) {
super.forwardTo(requestContext);
}
}
Aggregations