Search in sources :

Example 1 with ServletException

use of com.genexus.servlet.ServletException in project JavaClasses by genexuslabs.

the class GXWebObjectStub method callExecute.

protected void callExecute(String method, IHttpServletRequest req, IHttpServletResponse res) throws ServletException {
    initialize(req, res);
    HttpContext httpContext = null;
    try {
        String gxcfg = getWrappedServletContext().getInitParameter("gxcfg");
        if (gxcfg != null) {
            Class gxcfgClass = Class.forName(gxcfg);
            ModelContext.gxcfgPackageClass = gxcfgClass;
            ApplicationContext appContext = ApplicationContext.getInstance();
            appContext.setServletEngine(true);
            Application.init(gxcfgClass);
        }
        httpContext = new HttpContextWeb(method, req, res, getWrappedServletContext());
        if (logger.isDebugEnabled())
            dumpRequestInfo(httpContext);
        boolean useAuthentication = IntegratedSecurityEnabled();
        if (!useAuthentication) {
            callDoExecute(httpContext);
        } else {
            init(httpContext);
            if (IntegratedSecurityLevel() == SECURITY_GXOBJECT) {
                httpContext.doNotCompress(true);
            }
            new WebApplicationStartup().init(getClass(), httpContext);
            boolean[] flag = new boolean[] { false };
            boolean[] permissionFlag = new boolean[] { false };
            String reqUrl = req.getRequestURL().toString();
            if (req.getMethod().equals("POST")) {
                if (EncryptURLParameters().equals("SESSION"))
                    reqUrl = "";
                else
                    reqUrl = req.getHeader("Referer");
            } else {
                String queryString = req.getQueryString();
                if (queryString != null) {
                    reqUrl += "?" + queryString;
                }
            }
            ModelContext modelContext = ModelContext.getModelContext(getClass());
            modelContext.setHttpContext(httpContext);
            ApplicationContext.getInstance().setPoolConnections(!Namespace.createNamespace(modelContext).isRemoteGXDB());
            String loginObject = Application.getClientContext().getClientPreferences().getProperty("IntegratedSecurityLoginWeb", "");
            loginObject = GXutil.getClassName(loginObject);
            String loginObjectURL = URLRouter.getURLRoute(loginObject.toLowerCase(), new String[] {}, new String[] {}, httpContext.getRequest().getContextPath(), modelContext.getPackageName());
            String permissionPrefix = IntegratedSecurityPermissionPrefix();
            if (IntegratedSecurityLevel() == SECURITY_GXOBJECT) {
                String token = req.getHeader("Authorization");
                if (token != null && token.length() > 0) {
                    token = token.replace("OAuth ", "");
                    GXResult result = GXSecurityProvider.getInstance().checkaccesstoken(-2, modelContext, token, flag);
                } else {
                    token = "";
                    GXSecurityProvider.getInstance().checksession(-2, modelContext, reqUrl, flag);
                }
                if (!flag[0]) {
                    String OauthRealm = "OAuth realm=\"" + httpContext.getRequest().getServerName() + "\"";
                    httpContext.getResponse().addHeader("WWW-Authenticate", OauthRealm);
                    httpContext.sendResponseStatus(401, "Not Authorized");
                } else {
                    callDoExecute(httpContext);
                }
            } else if (IntegratedSecurityLevel() == SECURITY_LOW) {
                GXSecurityProvider.getInstance().checksession(-2, modelContext, reqUrl, flag);
                if (!flag[0]) {
                    httpContext.redirect(loginObjectURL, true);
                } else {
                    callDoExecute(httpContext);
                }
            } else {
                GXSecurityProvider.getInstance().checksessionprm(-2, modelContext, reqUrl, permissionPrefix, flag, permissionFlag);
                if (permissionFlag[0]) {
                    callDoExecute(httpContext);
                } else {
                    String notAuthorizedObject = Application.getClientContext().getClientPreferences().getProperty("IntegratedSecurityNotAuthorizedWeb", "");
                    notAuthorizedObject = GXutil.getClassName(notAuthorizedObject);
                    String notAuthorizedObjectURL = URLRouter.getURLRoute(notAuthorizedObject.toLowerCase(), new String[] {}, new String[] {}, httpContext.getRequest().getContextPath(), modelContext.getPackageName());
                    if (flag[0]) {
                        httpContext.redirect(notAuthorizedObjectURL, true);
                    } else {
                        httpContext.redirect(loginObjectURL, true);
                    }
                }
            }
        }
        httpContext.setResponseCommited();
        httpContext.flushStream();
    } catch (Throwable e) {
        if (!res.isCommitted())
            res.reset();
        logger.error("Web Execution Error", e);
        if (logger.isDebugEnabled() && httpContext != null)
            dumpRequestInfo(httpContext);
        throw new ServletException(com.genexus.PrivateUtilities.getStackTraceAsString(e));
    }
}
Also used : ServletException(com.genexus.servlet.ServletException) GXResult(com.genexus.security.GXResult) HttpContext(com.genexus.internet.HttpContext)

Aggregations

HttpContext (com.genexus.internet.HttpContext)1 GXResult (com.genexus.security.GXResult)1 ServletException (com.genexus.servlet.ServletException)1