Search in sources :

Example 6 with CompleteRequestException

use of com.iplanet.jato.CompleteRequestException in project OpenAM by OpenRock.

the class AuthenticationServletBase method onRequestHandlerNotFound.

/**
     * Forwards to login view bean, in case of an invalid target
     * request handler (page).
     *
     * @param requestContext - request context
     * @param handlerName - name of handler
     * @throws ServletException
     */
protected void onRequestHandlerNotFound(RequestContext requestContext, String handlerName) throws ServletException {
    ViewBeanManager viewBeanManager = requestContext.getViewBeanManager();
    AuthExceptionViewBean vb = (AuthExceptionViewBean) viewBeanManager.getViewBean(com.sun.identity.authentication.UI.AuthExceptionViewBean.class);
    vb.forwardTo(requestContext);
    throw new CompleteRequestException();
}
Also used : CompleteRequestException(com.iplanet.jato.CompleteRequestException) ViewBeanManager(com.iplanet.jato.ViewBeanManager)

Example 7 with CompleteRequestException

use of com.iplanet.jato.CompleteRequestException in project OpenAM by OpenRock.

the class LoginServlet method rerouteRequest.

private void rerouteRequest(HttpServletRequest request, HttpServletResponse response, String cookieURL) {
    debug.message("Routing the request to Original Auth server");
    Set<String> domains = AuthUtils.getCookieDomainsForRequest(request);
    try {
        Map<String, Object> origRequestData = AuthUtils.sendAuthRequestToOrigServer(request, response, cookieURL);
        Exception fwdEx = (Exception) origRequestData.get("EXCEPTION");
        if (fwdEx != null) {
            AuthUtils.clearHostUrlCookie(response);
            AuthUtils.clearlbCookie(request, response);
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw fwdEx;
        }
        String redirect_url = null;
        String clientType = null;
        String output_data = null;
        String contentType = null;
        // OK by default, origRequestData should override it
        int responseCode = HttpServletResponse.SC_OK;
        if (!origRequestData.isEmpty()) {
            redirect_url = (String) origRequestData.get("AM_REDIRECT_URL");
            output_data = (String) origRequestData.get("OUTPUT_DATA");
            clientType = (String) origRequestData.get("AM_CLIENT_TYPE");
            contentType = (String) origRequestData.get("CONTENT_TYPE");
            responseCode = (Integer) origRequestData.get("RESPONSE_CODE");
        }
        if (debug.messageEnabled()) {
            debug.message("redirect_url : " + redirect_url);
            debug.message("clientType : " + clientType);
        }
        response.setStatus(responseCode);
        if (responseCode >= HttpServletResponse.SC_BAD_REQUEST) {
            if (debug.warningEnabled()) {
                debug.warning("Received " + responseCode + " response code " + "while forwarding request, throwing CompleteRequestException");
            }
            AuthUtils.clearHostUrlCookie(response);
            AuthUtils.clearlbCookie(request, response);
            throw new CompleteRequestException();
        }
        if (((redirect_url != null) && !redirect_url.equals("")) && (AuthUtils.isGenericHTMLClient(clientType))) {
            debug.message("Redirecting the response");
            response.sendRedirect(redirect_url);
        }
        if ((output_data != null) && (!output_data.equals(""))) {
            debug.message("Printing the forwarded response");
            if (contentType != null) {
                if (debug.messageEnabled()) {
                    debug.message("Content type is " + contentType);
                }
                response.setContentType(contentType);
            } else {
                if (debug.messageEnabled()) {
                    debug.message("Content type is default; " + DEFAULT_CONTENT_TYPE);
                }
                response.setContentType(DEFAULT_CONTENT_TYPE);
            }
            java.io.PrintWriter outP = response.getWriter();
            outP.println(output_data);
        }
        if ((redirect_url == null || redirect_url.length() == 0) && (output_data == null || output_data.length() == 0) && (responseCode == 200 || responseCode == -1)) {
            if (debug.messageEnabled()) {
                debug.message("LoginServlet:initializeRequestContext" + " No Response from original Auth server");
            }
            String refererURL = request.getHeader("Referer");
            String refererDomain = null;
            if (refererURL != null && !(refererURL.length() == 0)) {
                URL u = new URL(refererURL);
                int pos = u.getHost().indexOf(".");
                if (pos != -1) {
                    refererDomain = u.getHost().substring(pos);
                }
            } else {
                refererURL = request.getRequestURL().toString();
                if (request.getQueryString() != null) {
                    refererURL = refererURL + "?" + request.getQueryString();
                }
            }
            if (debug.messageEnabled()) {
                debug.message("LoginServlet:initializeRequestContext" + " referer domain is " + refererDomain);
            }
            //remove amAuthCookie and amLBCookie cookies
            Cookie[] cookies = request.getCookies();
            if (cookies != null && cookies.length > 0) {
                for (int i = 0; i < cookies.length; i++) {
                    if (cookies[i].getName().equalsIgnoreCase(AuthUtils.getAuthCookieName()) || cookies[i].getName().equalsIgnoreCase(AuthUtils.getlbCookieName())) {
                        if (debug.messageEnabled()) {
                            debug.message("LoginServlet:" + "initializeRequestContext removing" + "cookie " + cookies[i].getName());
                        }
                        cookies[i].setValue("");
                        cookies[i].setMaxAge(0);
                        response.addCookie(cookies[i]);
                        for (String domain : domains) {
                            if (debug.messageEnabled()) {
                                debug.message("LoginServlet:initializeRequestContext removing cookie " + domain);
                            }
                            Cookie cookie = AuthUtils.createCookie(cookies[i].getName(), "", domain);
                            cookie.setMaxAge(0);
                            response.addCookie(cookie);
                        }
                    }
                }
            }
            if (debug.messageEnabled()) {
                debug.message("LoginServlet:initializeRequestContextredirecting to: " + refererURL);
            }
            response.sendRedirect(refererURL);
        }
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("LoginServlet error in Request Routing : ", e);
        }
        String authCookieName = AuthUtils.getAuthCookieName();
        for (String domain : domains) {
            response.addCookie(AuthUtils.createCookie(authCookieName, "LOGOUT", 0, domain));
            if (debug.messageEnabled()) {
                debug.message("LoginServlet reset Auth Cookie in domain: " + domain);
            }
        }
    }
    throw new CompleteRequestException();
}
Also used : Cookie(javax.servlet.http.Cookie) CompleteRequestException(com.iplanet.jato.CompleteRequestException) ServletException(javax.servlet.ServletException) CompleteRequestException(com.iplanet.jato.CompleteRequestException) URL(java.net.URL)

Example 8 with CompleteRequestException

use of com.iplanet.jato.CompleteRequestException in project OpenAM by OpenRock.

the class DSAMEHrefTag method doEndTag.

/**
     * does end tag
     *
     * @return SKIP_PAGE if tag is not going to be displayed
     */
public int doEndTag() throws JspException {
    try {
        if (abortedException != null) {
            throw abortedException;
        }
        if (displayed) {
            BodyContent bodyContent = getBodyContent();
            if (bodyContent != null) {
                // Assume that "true" is default for trim
                if (getTrim() == null || isTrue(getTrim())) {
                    buffer.append(bodyContent.getString().trim());
                } else {
                    buffer.append(bodyContent.getString());
                }
            }
            buffer.append("</a>");
            writeOutput(fireEndDisplayEvent(buffer.toString()));
        }
    } catch (CompleteRequestException e) {
        // CompleteRequestException tunneling workaround:
        // Workaround to allow developers to stop the request
        // from a display event by throwing a CompleteRequestException.
        // The problem is that some containers catch this exception in
        // their JSP rendering subsystem, and so we need to tunnel it
        // through for the developer.
        // Mark the JSP rendering as cancelled.  The calling
        // ViewBean.foward() or ViewBean.include() methods
        // should pick this up and then throw a complete request
        // exception that was properly thrown here.
        getRequestContext().getRequest().setAttribute(ViewBeanBase.DISPLAY_EVENT_COMPLETED_REQUEST_ATTRIBUTE_NAME, e);
        return SKIP_PAGE;
    }
    return EVAL_PAGE;
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) CompleteRequestException(com.iplanet.jato.CompleteRequestException)

Example 9 with CompleteRequestException

use of com.iplanet.jato.CompleteRequestException in project OpenAM by OpenRock.

the class ConsoleServletBase method onBeforeRequest.

/**
     * Forwards request to login view bean if user has not logged in.
     *
     * @param requestContext request context.
     * @throws ServletException if redirection fails.
     */
protected void onBeforeRequest(RequestContext requestContext) throws ServletException {
    HttpServletRequest req = requestContext.getRequest();
    String host = req.getHeader("Host");
    if (host == null) {
        /*
             * This case will not happen, unless the user agent does not set
             * this header while making this connection.
             */
        host = getConsoleHost();
    } else {
        String validHost = validateHost(host);
        if (validHost != null) {
            try {
                requestContext.getResponse().sendRedirect(replaceHostNameInUrl(req, validHost));
            } catch (IOException ioe) {
                getDebug().error("ConsoleServletBase.onBeforeRequest, " + "failed to redirect to fully qualified host");
            }
            throw new CompleteRequestException();
        }
    }
    validateSSOToken(requestContext);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CompleteRequestException(com.iplanet.jato.CompleteRequestException) IOException(java.io.IOException)

Example 10 with CompleteRequestException

use of com.iplanet.jato.CompleteRequestException in project OpenAM by OpenRock.

the class ConsoleServletBase method onRequestHandlerNotSpecified.

/**
     * Forwards to invalid URL view bean, in case of no handler specified
     *
     * @param requestContext - request context
     * @throws ServletException
     */
protected void onRequestHandlerNotSpecified(RequestContext requestContext) throws ServletException {
    ViewBeanManager viewBeanManager = requestContext.getViewBeanManager();
    ViewBean targetView = viewBeanManager.getViewBean(AMInvalidURLViewBean.class);
    targetView.forwardTo(requestContext);
    throw new CompleteRequestException();
}
Also used : CompleteRequestException(com.iplanet.jato.CompleteRequestException) ViewBeanManager(com.iplanet.jato.ViewBeanManager) ViewBean(com.iplanet.jato.view.ViewBean)

Aggregations

CompleteRequestException (com.iplanet.jato.CompleteRequestException)17 ViewBeanManager (com.iplanet.jato.ViewBeanManager)10 ViewBean (com.iplanet.jato.view.ViewBean)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 SessionID (com.iplanet.dpro.session.SessionID)1 RequestContext (com.iplanet.jato.RequestContext)1 RequestContextImpl (com.iplanet.jato.RequestContextImpl)1 NonSyncStringBuffer (com.iplanet.jato.util.NonSyncStringBuffer)1 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 AuthViewBeanBase (com.sun.identity.authentication.UI.AuthViewBeanBase)1 ISLocaleContext (com.sun.identity.common.ISLocaleContext)1 L10NMessageImpl (com.sun.identity.shared.locale.L10NMessageImpl)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 Cookie (javax.servlet.http.Cookie)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1