Search in sources :

Example 1 with CompleteRequestException

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

the class PWResetServlet 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(PWResetInvalidURLViewBean.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)

Example 2 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 3 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 4 with CompleteRequestException

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

the class ConsoleServletBase method validateSSOToken.

private void validateSSOToken(RequestContext requestContext) throws ServletException {
    try {
        /*
             * Since all supported web containers now support
             * servlet 2.3 and above, we use setCharacterEncoding
             * to set request charset.
             */
        HttpServletRequest req = requestContext.getRequest();
        SSOToken token = checkAuthentication(req);
        String enc = token.getProperty("CharSet");
        try {
            String jCharset = BrowserEncoding.mapHttp2JavaCharset(enc);
            req.setCharacterEncoding(jCharset);
        } catch (UnsupportedEncodingException ex) {
            getDebug().error("ConsoleServletBase.validateSSOToken " + "Unsupported encoding", ex);
        }
    } catch (SSOException soe) {
        browserRedirect(requestContext, formGotoUrl(requestContext.getRequest()));
        throw new CompleteRequestException();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) CompleteRequestException(com.iplanet.jato.CompleteRequestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SSOException(com.iplanet.sso.SSOException)

Example 5 with CompleteRequestException

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

the class ConsoleServletBase method onRequestHandlerNotFound.

/**
     * Forwards to invalid URL 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();
    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