Search in sources :

Example 1 with FSLoginHelperException

use of com.sun.identity.federation.services.FSLoginHelperException in project OpenAM by OpenRock.

the class FSPreLogin method createSSOMap.

/**
    * 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.
    * @return Map of request headers key/value pairs.
    * @exception FSPreLoginException on error.
    */
private Map createSSOMap(String authLevel, String metaAlias, boolean isFedCookiePresent, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws FSPreLoginException {
    try {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSPreLogin::createSSOMap called with authLevel =" + authLevel + " metaAlias =" + metaAlias);
        }
        if (!isFedCookiePresent) {
            String actionOnNoFedCookie = httpRequest.getParameter(IFSConstants.ACTION_ON_NO_FED_COOKIE);
            if (actionOnNoFedCookie != null && actionOnNoFedCookie.equals(IFSConstants.LOCAL_LOGIN)) {
                FSUtils.forwardRequest(httpRequest, httpResponse, getLoginURL(false, metaAlias, httpRequest));
                return null;
            }
        }
        Map headerMap = setHeaderMap(httpRequest);
        FSLoginHelper loginHelper = new FSLoginHelper(httpRequest);
        String targetURL = httpRequest.getParameter(IFSConstants.GOTOKEY);
        if (targetURL == null || targetURL.length() <= 0) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSPreLogin::createSSOMap." + "no goto in queryString.Assinging targetURL = " + homePage);
            }
            targetURL = homePage;
        }
        Map retMap = loginHelper.createAuthnRequest(headerMap, targetURL, authLevel, metaAlias, null, isFedCookiePresent);
        String requestID = null;
        String responseData = (String) retMap.get(IFSConstants.RESPONSE_DATA_KEY);
        if (responseData != null && responseData.length() != 0) {
            return retMap;
        }
        requestID = (String) retMap.get(IFSConstants.AUTH_REQUEST_ID);
        String URL = (String) retMap.get(IFSConstants.URL_KEY);
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSPreLogin::createSSOMap requestID" + requestID + " URL " + URL);
        }
        if (requestID != null && URL == null) {
            //show list page
            String queryString = getQueryString(true, metaAlias, httpRequest);
            String returnURL = new StringBuffer().append(commonLoginPage).append(IFSConstants.QUESTION_MARK).append(queryString).append(IFSConstants.AMPERSAND).append(IFSConstants.AUTH_REQUEST_ID).append(IFSConstants.EQUAL_TO).append(URLEncDec.encode(requestID)).append(IFSConstants.AMPERSAND).append(IFSConstants.META_ALIAS).append(IFSConstants.EQUAL_TO).append(httpRequest.getParameter(IFSConstants.META_ALIAS)).toString();
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSPreLogin::createSSOMap framedlogin url " + returnURL);
            }
            retMap.put(IFSConstants.URL_KEY, returnURL);
        }
        return retMap;
    } catch (FSLoginHelperException exp) {
        FSUtils.debug.error("FSPreLogin::setMetaInfo." + " FSLoginHelperException Exception caught. ", exp);
        throw new FSPreLoginException("FSPreLogin::FSLoginHelperException");
    }
}
Also used : FSLoginHelper(com.sun.identity.federation.services.FSLoginHelper) FSLoginHelperException(com.sun.identity.federation.services.FSLoginHelperException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FSLoginHelperException

use of com.sun.identity.federation.services.FSLoginHelperException in project OpenAM by OpenRock.

the class FSPostLogin method doFederation.

/**
     * Returns the URL to which request should be redirected
     * for federation. This method reads the request parameters
     * and creates an Authentication Request to send to
     * initiate the Single Sign-On / Federation process.
     *
     * @param request the <code>HttpServletRequest</code> object.
     * @param response the <code>HttpServletResponse</code> object.
     * @return the URL to redirect request to.
     * @exception FSPostLoginException on error.
     */
public String doFederation(HttpServletRequest request, HttpServletResponse response) throws FSPostLoginException {
    String metaAlias = request.getParameter(IFSConstants.META_ALIAS);
    String LRURL = request.getParameter(IFSConstants.LRURL);
    String selectedProvider = request.getParameter(IFSConstants.SELECTEDPROVIDER);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSPostLogin::doFederation metaAlias " + metaAlias);
        FSUtils.debug.message("FSPostLogin::doFederation lrurl " + LRURL);
        FSUtils.debug.message("FSPostLogin::doFederation selected provider" + selectedProvider);
    }
    Map headerMap = new HashMap();
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String hn = headerNames.nextElement().toString();
        String hv = request.getHeader(hn);
        headerMap.put(hn, hv);
    }
    FSLoginHelper plh = new FSLoginHelper(request);
    Map retMap = new HashMap();
    String authLevel = null;
    HttpSession httpSession = request.getSession(false);
    if (httpSession != null) {
        authLevel = (String) httpSession.getAttribute(IFSConstants.AUTH_LEVEL_KEY);
    }
    try {
        retMap = plh.createAuthnRequest(headerMap, LRURL, authLevel, metaAlias, selectedProvider, true);
    } catch (FSLoginHelperException fsLoginExp) {
        FSUtils.debug.error("FSPostLogin::doFederate in exception ", fsLoginExp);
        throw new FSPostLoginException("FSPostLogin::doFederate exception " + fsLoginExp.getMessage());
    }
    Map retHeaderMap = (Map) retMap.get(IFSConstants.HEADER_KEY);
    Iterator hdrNames = retHeaderMap.keySet().iterator();
    while (hdrNames.hasNext()) {
        String name = hdrNames.next().toString();
        String value = (String) retHeaderMap.get(name);
        response.addHeader(name, value);
    }
    String urlKey = (String) retMap.get(IFSConstants.URL_KEY);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSPostLogin::doFederation returning with " + urlKey);
    }
    return urlKey;
}
Also used : FSLoginHelper(com.sun.identity.federation.services.FSLoginHelper) Enumeration(java.util.Enumeration) FSLoginHelperException(com.sun.identity.federation.services.FSLoginHelperException) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with FSLoginHelperException

use of com.sun.identity.federation.services.FSLoginHelperException in project OpenAM by OpenRock.

the class LibertyManager method getNewRequest.

/** 
     * Creates New Request ID from the <code>HttpRequestServlet</code>.
     *
     * @param request HTTP servlet request.
     * @return New Request ID from the <code>HttpRequestServlet</code>.
     */
public static String getNewRequest(HttpServletRequest request) {
    String targetURL = request.getParameter(IFSConstants.LRURL);
    String metaAlias = request.getParameter(IFSConstants.META_ALIAS);
    String entityID = getEntityID(metaAlias);
    String realm = IDFFMetaUtils.getRealmByMetaAlias(metaAlias);
    Map headerMap = getHeaderMap(request);
    String homePage = null;
    if (targetURL == null || targetURL.length() <= 0) {
        try {
            if (metaManager != null) {
                BaseConfigType providerConfig = metaManager.getSPDescriptorConfig(realm, entityID);
                homePage = IDFFMetaUtils.getFirstAttributeValue(IDFFMetaUtils.getAttributes(providerConfig), IFSConstants.PROVIDER_HOME_PAGE_URL);
            }
        } catch (IDFFMetaException ame) {
            debug.error("LibertyManager: getNewRequest: Error" + " while getting the HostedProvider from meta mgmt", ame);
        }
        if (debug.messageEnabled()) {
            debug.message("LibertyManager: getNewRequestID." + " no goto in queryString.Assinging targetURL = " + homePage);
        }
        targetURL = homePage;
    }
    try {
        FSLoginHelper loginHelper = new FSLoginHelper(request);
        // get the authlevel key
        HttpSession httpSession = request.getSession();
        String authLevel = (String) httpSession.getAttribute(IFSConstants.AUTH_LEVEL_KEY);
        Map retMap = loginHelper.createAuthnRequest(headerMap, targetURL, authLevel, metaAlias, null, true);
        if (retMap != null) {
            String reqID = (String) retMap.get(IFSConstants.AUTH_REQUEST_ID);
            if (debug.messageEnabled()) {
                debug.message("LibertyManager: getNewRequestID: " + "new request created with id " + reqID);
            }
            return reqID;
        } else {
            debug.error("LibertyManager: getNewRequestID " + " Could not create new request ");
            return null;
        }
    } catch (FSLoginHelperException exp) {
        debug.error("LibertyManager::getNewRequestID" + "In login helper exception ", exp);
        return null;
    }
}
Also used : BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) FSLoginHelper(com.sun.identity.federation.services.FSLoginHelper) FSLoginHelperException(com.sun.identity.federation.services.FSLoginHelperException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) HttpSession(javax.servlet.http.HttpSession) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FSLoginHelper (com.sun.identity.federation.services.FSLoginHelper)3 FSLoginHelperException (com.sun.identity.federation.services.FSLoginHelperException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HttpSession (javax.servlet.http.HttpSession)2 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)1 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1