/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: FSPreLogin.java,v 1.6 2008/08/19 19:11:04 veiming Exp $
*
* Portions Copyrighted 2015 ForgeRock AS.
*/
/**
* This class has methods for pre login operations.
*/
public class FSPreLogin {
private boolean doLocalAuth = false;
static {
}
/**
* Removes metaAlias,goto, and org keys and values
* from query string if present.
*
* @param httpRequest the HttpServletRequest object.
* @return a query string.
*/
while (paramEnum.hasMoreElements()) {
+ "found metaAlias or gotoKey or org.");
}
} else {
} else {
returnString +=
}
}
}
"FSPreLogin::removeMetaGotoOrg returning with " + returnString);
}
return returnString;
}
/**
* Forms the login url and append the required queryString.
* If showFederatePage is false then the federate page is not shown
* in postlogin.
*
* @param showFederatePage true if request should be redirected to
* Federation Page.
* @param metaAlias the provider alias.
* @param request the HttpServletRequest.
* @return the login URL String.
*/
{
.toString();
+ returnURL );
}
return returnURL;
}
/**
* Forms the required queryString to be append to login URL.
*
* @param showFederatePage true if request should be redirected to
* Federation Page.
* @param metaAlias alias of the provider.
* @param httpRequest the HttpServletRequest object.
* @return the login URL String.
*/
{
+ "no goto in queryString.Assinging LRURL = "
+ homePage);
}
}
"FSPreLogin::getQueryString.RelayState =" + lrURL
+ " Required QueryString =" + reqQueryString);
}
.toString();
/*
String gotoURL = new StringBuffer().append(postLoginURL)
.append(IFSConstants.QUESTION_MARK).append(IFSConstants.META_ALIAS)
.append(IFSConstants.EQUAL_TO)
.append(metaAlias)
.toString();
*/
if (showFederatePage) {
}
+ gotoURL);
}
}
return returnURLBuf.toString();
}
/**
* Retrieves hosted provider and local configuration attributes.
*
* @param metaAlias the provider alias.
* @param httpRequest the HttpServletRequest object.
* @exception FSPreLoginException on error.
*/
throws FSPreLoginException
{
"FSPreLogin::setMetaInfo called with metaAlias =" +
metaAlias );
}
try {
if (metaManager != null) {
} else {
+ "meta manager is null. "
+ "Cannot proceed so throwing error page");
throw new FSPreLoginException(
"FSPreLogin:: could not get meta manager handle.");
}
if (hostedProviderRole != null) {
}
}
if (hostedConfig != null) {
} else {
+ "getDescriptorConfig retured null. "
+ "Cannot proceed so throwing error page");
throw new FSPreLoginException(
"FSPreLogin:: could not get sp config.");
}
{
doLocalAuth = true;
} else {
+ "authType=" + authType
+ "Setting authType to default false.");
}
"FSPreLogin::setMetaInfo.realm = " + realm
+ " doLocalAuth = " + doLocalAuth);
}
} catch (IDFFMetaException allianExp) {
+ " IDFFMetaException caught. ", allianExp);
throw new FSPreLoginException(
"FSPreLogin::IDFFMetaException. ");
+ " General Exception caught. " , exp);
throw new FSPreLoginException("Prelogin exception");
}
}
/**
* Returns a map of cookies from the cookie array.
*
* @param cookieArray Array of cookies.
* @return a Map of Cookies with cookieName as key and
* value the cookie value.
*/
if (cookieArray != null) {
cookieArray[i].getValue());
+ cookieArray[i].getValue());
}
}
}
return cookieMap;
}
/**
* Sets the required headers in the HTTP response.
*
* @param response the HttpServletResponse object.
* be set in the request.
*/
"FSPreLogin::setResponse with header with name " + name
+ " with value " + value);
}
}
}
}
}
/**
* Forwards request to an error page .
*
* @param request the HttpServletRequest object.
* @param response the HttpServletResponse object.
*/
{
try {
+ "Error during sending error page");
}
}
/**
* Validates the OpenAM Session Token String.
*
* @param token the Session Token String.
* @return a boolean value true if valid otherwise false.
*/
boolean isValidToken = false;
try {
} catch (SessionException ssoe) {
}
return isValidToken;
}
/**
* Returns a Map of header contained in the HTTP Request.
*
* @param httpRequest the HttpServletRequest object.
*/
while(headerNames.hasMoreElements()) {
}
}
return headerMap;
}
/**
* Initiates call to create Authentication Request.
* Returns a Map of request headers/attributes key/values pairs,
* where key is the attribute name and value is the attribute
* value.
*
* @param authLevel the AuthLevel parameter value.
* @param metaAlias the provider alias.
* @param httpRequest the HttpServletRequest object.
* @param httpResponse the HttpServletResponse object.
* @exception FSPreLoginException on error.
*/
boolean isFedCookiePresent,
throws FSPreLoginException
{
try {
"FSPreLogin::createSSOMap called with authLevel =" +
}
if (!isFedCookiePresent) {
if (actionOnNoFedCookie != null &&
{
return null;
}
}
+ "no goto in queryString.Assinging targetURL = "
+ homePage);
}
}
null,
return retMap;
}
}
//show list page
.toString();
"FSPreLogin::createSSOMap framedlogin url " +
}
}
return retMap;
} catch (FSLoginHelperException exp) {
+ " FSLoginHelperException Exception caught. ", exp);
throw new FSPreLoginException("FSPreLogin::FSLoginHelperException");
}
}
/**
* Redirects request to URL based on whether a Single Sign-On needs to
* be done or local Authentication. The decision is based on AuthFlag
*
* @param request the <code>HttpServletRequest</code> object.
* @param response the <code>HttpServletResponse</code> object.
*/
{
try {
boolean isTokenValid = false;
boolean isFedCookie = true;
}
}
if (doLocalAuth) {
"FSPreLogin::doPreLogin. do local auth is true ");
"FSPreLogin::doPreLogin. returning with url " +
}
return;
}
isTokenValid = true;
"FSPreLogin::doPreLogin. OpenSSO Token is valid");
}
boolean isFedCookiePresent = false;
isFedCookiePresent = true;
"FSPreLogin::doPreLogin. fedCookie is present");
.equalsIgnoreCase("no"))
{
isFedCookie = false;
"FSPreLogin::doPreLogin. fedCookie is no");
}
}
/**
* This authlevel in http session will be used while
* redirecting to local login from the common login page
*/
if (authLevelParam != null) {
}
if (!isFedCookie) {
// no FedCookie
// redirect to local login page no post login
// Also, Check if there's any no liberty URL
+ "In case where ISToken invalid and"
+ "fedcookie no");
}
if (gotoOnFedCookieNoURL != null) {
} else {
"FSPreLogin::doPreLogin. returning with url " +
}
}
return;
} else { // fedCookie is present
if (isTokenValid) {
// this is the case where token is valid and
// fedCookie is present
//do sso if auth level present in queryString
//else append queryString and send to localLogin
if (authLevelParam != null) {
+ "In case where ISToken valid and "
+ "fedcookie yes and dolocalauth false and "
+ "authLevel present");
}
if (responseData != null &&
{
responseData.getBytes());
} else {
"FSPreLogin::doPreLogin."
+ "returning with url "
+ returnURL);
}
}
}
return;
} else {
+ "In case where ISToken valid and"
+ "fedcookie yes and dolocalauth false and "
+ "authLevel not present");
}
+ "returning with url " + returnURL);
}
return;
}
} else { // Token not valid
// do sso with gettin authlevel from request or default auth
+ "In case where ISToken invalid and"
+ "fedcookie yes");
}
{
responseData.getBytes());
} else {
+ "returning with url " + returnURL);
}
}
}
return;
}
}
} catch (FSPreLoginException preLoginExp) {
//redirect to error page
}
}
}