Package org.jboss.dashboard.ui.controller

Examples of org.jboss.dashboard.ui.controller.RequestContext


    /**
     * Returns the section status object for a given region. If it doesn't exist,
     * creates and stores it in the session.
     */
    public static LayoutRegionStatus getRegionStatus(Section section, LayoutRegion region) {
        RequestContext reqCtx = RequestContext.lookup();
        HttpSession session = reqCtx.getRequest().getSessionObject();
        if (section == null || region == null) return null;

        String key = "_region_status_" + section.getKey() + "_" + region.getId();
        LayoutRegionStatus sectionStatus = (LayoutRegionStatus) session.getAttribute(key);
        if (sectionStatus == null) {
View Full Code Here


        PreferredLocale preferredLocale =  getPreferredLocale(request);
        localeManager.setCurrentLocale(preferredLocale.asLocale());
    }

    public boolean processRequest() throws Exception {
        RequestContext requestContext= getRequestContext();
        HttpServletRequest request = getHttpRequest();
        HttpServletResponse response = getHttpResponse();
        HttpSession session = request.getSession(true);

        // Catch new sessions
        if (isNewSession(request)) {
            initSession(request, response);
            return true;
        }

        // Check session expiration
        if (request.getRequestedSessionId() != null && !request.getRequestedSessionId().equals(session.getId())) {
            log.debug("Session expiration detected.");
            requestContext.setResponse(new RedirectToURLResponse(getExpirationRecoveryURL(request)));
            requestContext.consumeURIPart(requestContext.getURIToBeConsumed());
            return false;
        }
        return true;
    }
View Full Code Here

    public boolean processRequest() throws Exception {
        HttpServletRequest request = getHttpRequest();
        String servletPath = request.getServletPath();
        NavigationManager navigationManager = NavigationManager.lookup();
        UserStatus userStatus = UserStatus.lookup();
        RequestContext requestContext = RequestContext.lookup();

        // ---- Apply locale information, --------------
        LocaleManager localeManager = LocaleManager.lookup();
        // First check if a locale parameter is present in the URI query string.
        Locale localeToSet = null;
        String localeParam = request.getParameter(LOCALE_PARAMETER);
        if (localeParam != null && localeParam.trim().length() > 0)  {
            localeToSet = localeManager.getLocaleById(localeParam);
            if (localeToSet != null) {
                localeManager.setCurrentLocale(localeToSet);
            }
        }

        // No friendly -> nothing to do.
        if (!servletPath.startsWith(FRIENDLY_MAPPING)) return true;

        String contextPath = request.getContextPath();
        requestContext.consumeURIPart(FRIENDLY_MAPPING);
        navigationManager.setShowingConfig(false);
        String requestUri = request.getRequestURI();
        String relativeUri = requestUri.substring(contextPath == null ? 0 : (contextPath.length()));
        relativeUri = relativeUri.substring(servletPath == null ? 0 : (servletPath.length()));

        // Empty URI -> nothing to do.
        if (StringUtils.isBlank(relativeUri)) return true;

        /*
        * Check if the locale information is in the URI value in order to consume it.
        * Locale information is expected in the URI after "/workspace".
        * Examples:
        * - /workspace/en/....
        * - /workspace/es/....
        * - /workspace/en_ES/....
        * NOTES:
        * - Available locales matched in the URI parameter are obtained from JVM available locales.
        * - If the locale is found as platform available, the locale is set.
        * - Otherwise, do nothing, the locale used will be the last one set or default.
        * - In both cases URI locale parameter will be consumed.
        */
        int startLocaleUri = relativeUri.indexOf("/");
        int endLocaleUri = relativeUri.indexOf("/", startLocaleUri + 1);
        endLocaleUri = endLocaleUri > 0 ? endLocaleUri : relativeUri.length();
        String localeUri = relativeUri.substring(startLocaleUri + 1, endLocaleUri);
        Locale uriLocale = localeManager.getLocaleById(localeUri);
        if (uriLocale != null) {
            requestContext.consumeURIPart("/" + localeUri);
            relativeUri = relativeUri.substring(localeUri.length() + 1);
            // Use the locale specified in the URI value only if no locale specified in the qeury string.
            if (localeToSet == null) localeManager.setCurrentLocale(uriLocale);
        }

        // Tokenize the friendly URI.
        StringTokenizer tokenizer = new StringTokenizer(relativeUri, "/", false);
        List tokens = new ArrayList();
        int i = 0;
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            if (i < 2) {
                tokens.add(token);
                i++;
            } else if (tokens.size() == 2) {
                tokens.add("/" + token);
            } else {
                tokens.set(2, tokens.get(2) + "/" + token);
            }
        }
        try {
            // Get the target workspace/section spècified.
            log.debug("Tokens=" + tokens);
            String workspaceCandidate = null;
            String sectionCandidate = null;
            if (tokens.size() > 0) workspaceCandidate = (String) tokens.get(0);
            if (tokens.size() > 1) sectionCandidate = (String) tokens.get(1);
            if (log.isDebugEnabled()) {
                log.debug("workspaceCandidate=" + workspaceCandidate);
                log.debug("sectionCandidate=" + sectionCandidate);
            }
            WorkspaceImpl workspace = null;
            Section section = null;
            if (workspaceCandidate != null) {
                boolean canbeWorkspaceId = canBeWorkspaceId(workspaceCandidate);
                if (canbeWorkspaceId) workspace = (WorkspaceImpl) UIServices.lookup().getWorkspacesManager().getWorkspace(workspaceCandidate);
                if (workspace == null) workspace = (WorkspaceImpl) UIServices.lookup().getWorkspacesManager().getWorkspaceByUrl(workspaceCandidate);
            }
            if (workspace != null && sectionCandidate != null) {
                try {
                    section = workspace.getSection(Long.decode(sectionCandidate));
                } catch (NumberFormatException nfe) {
                    section = workspace.getSectionByUrl(sectionCandidate);
                }
            }
            // Check the user has access permissions to the target workspace.
            if (workspace != null && section == null) {
                try {
                    Workspace currentWorkspace = navigationManager.getCurrentWorkspace();
                    log.debug("currentWorkspace = " + (currentWorkspace == null ? "null" : currentWorkspace.getId()) + " workspaceCandidate = " + workspaceCandidate);
                    if (!workspace.equals(currentWorkspace)) {

                        WorkspacePermission workspacePerm = WorkspacePermission.newInstance(workspace, WorkspacePermission.ACTION_LOGIN);
                        if (userStatus.hasPermission(workspacePerm)) {
                            navigationManager.setCurrentWorkspace(workspace);
                            log.debug("SessionManager.setWorkspace(" + workspace.getId() + ")");
                        } else {
                            if (log.isDebugEnabled()) log.debug("User has no " + WorkspacePermission.ACTION_LOGIN + " permission in workspace " + workspaceCandidate);
                            if (isShowLoginBackDoorOnPermissionDenied()) {
                                navigationManager.setUserRequiresLoginBackdoor(true);
                                navigationManager.setCurrentWorkspace(workspace);
                            }
                        }
                    }
                    requestContext.consumeURIPart("/" + workspaceCandidate);
                } catch (Exception e) {
                    log.error("Cannot set current workspace.", e);
                }
            }
            // Check the user has access permissions to the target section.
            else if (section != null) {
                try {
                    if (!section.equals(navigationManager.getCurrentSection())) {

                        WorkspacePermission workspacePerm = WorkspacePermission.newInstance(section.getWorkspace(), WorkspacePermission.ACTION_LOGIN);
                        SectionPermission sectionPerm = SectionPermission.newInstance(section, SectionPermission.ACTION_VIEW);
                        if (userStatus.hasPermission(workspacePerm) && userStatus.hasPermission(sectionPerm)) {
                            if (log.isDebugEnabled()) log.debug("SessionManager.setSection(" + section.getId() + ")");
                            navigationManager.setCurrentSection(section);
                        }
                        else {
                            if (log.isDebugEnabled()) log.debug("User has no " + WorkspacePermission.ACTION_LOGIN + " permission in workspace " + workspaceCandidate);
                            if (isShowLoginBackDoorOnPermissionDenied()) {
                                navigationManager.setUserRequiresLoginBackdoor(true);
                                navigationManager.setCurrentSection(section);
                            }
                        }
                    }
                    requestContext.consumeURIPart("/" + workspaceCandidate);
                    requestContext.consumeURIPart("/" + sectionCandidate);
                } catch (Exception e) {
                    log.error("Cannot set current section.", e);
                }
            }
        } catch (Exception e) {
View Full Code Here

        return l;
    }

    public int getDepthLevel() {
        // Section path number cache, to avoid lots of getParent() in the same request...
        RequestContext ctx = RequestContext.lookup();
        if (ctx == null || ctx.getRequest() == null) {
            return getPathNumber().size() - 1;
        }
        Map<Long, List<Integer>> sectionsCache = (Map) ctx.getRequest().getRequestObject().getAttribute("sectionsPathNumberCache");
        if (sectionsCache == null)
            ctx.getRequest().getRequestObject().setAttribute("sectionsPathNumberCache", sectionsCache = new HashMap<Long, List<Integer>>());

        List<Integer> myPathNumber = sectionsCache.get(this.getDbid());
        if (myPathNumber == null) {
            myPathNumber = getPathNumber();
            sectionsCache.put(this.getDbid(), myPathNumber);
View Full Code Here

        }
        return 0;
    }

    private void clearSectionsCache() {
        RequestContext ctx = RequestContext.lookup();
        if (ctx != null && ctx.getRequest() != null) {
            ctx.getRequest().getRequestObject().removeAttribute("sectionsPathNumberCache");
        }
    }
View Full Code Here

    }

    public int compareTo(Section other) {
        if (this == other) return 0;
        // Section path number cache, to avoid lots of getParent() in the same request...
        RequestContext ctx = RequestContext.lookup();
        if (ctx == null || ctx.getRequest() == null) {
            return comparePathNumbers(getPathNumber(), other.getPathNumber());
        }
        Map<Long, List<Integer>> sectionsCache = (Map) ctx.getRequest().getRequestObject().getAttribute("sectionsPathNumberCache");
        if (sectionsCache == null)
            ctx.getRequest().getRequestObject().setAttribute("sectionsPathNumberCache", sectionsCache = new HashMap<Long, List<Integer>>());

        List<Integer> myPathNumber = sectionsCache.get(this.getDbid());
        if (myPathNumber == null) {
            myPathNumber = getPathNumber();
            sectionsCache.put(this.getDbid(), myPathNumber);
View Full Code Here

     * Apply a final post-processing on generated URLs in order to add some extra information such as CSRF tokens or
     * propagate some behavioural parameters via URL-rewriting.
     */
    protected StringBuffer postProcessURL(StringBuffer url) {
        // Keep the embedded mode using URL rewriting.
        RequestContext reqCtx = RequestContext.lookup();
        if (reqCtx != null) {
            HttpServletRequest request = reqCtx.getRequest().getRequestObject();
            boolean embeddedMode = Boolean.parseBoolean(request.getParameter(Parameters.PARAM_EMBEDDED));
            String embeddedParam = Parameters.PARAM_EMBEDDED + "=true";
            if (embeddedMode && url.indexOf(embeddedParam) == -1) {
                url.append(url.indexOf("?") != -1 ? PARAM_SEPARATOR : "?");
                url.append(embeddedParam);
View Full Code Here

                res = resMap.get(null);//Try with no-language resource.
            if (res == null)
                res = resMap.get(getLocaleManager().getDefaultLang());//Try with default lang

            res = getBaseDir() + "/" + res;
            RequestContext reqCtx = RequestContext.lookup();
            if (reqCtx != null) {
                //Resources are best retrieved through URL (the fastest way)
                log.debug("Resource relative name = " + res);
                String categoryMapping = getMappingDir();
                log.debug("Category where the resource belongs to is mapped to uri " + categoryMapping);
                String url = categoryMapping + "/" + res;
                log.debug("Returning UrlResource to " + url);
                return UrlResource.getInstance(resourceName, reqCtx.getRequest().getRequestObject().getContextPath(), url);
            } else {
                //Create a FileResource...
                try {
                    checkDeployment();
                    return FileResource.getInstance(resourceName, new File(Application.lookup().getBaseAppDirectory() + getMappingDir() + "/" + res));
View Full Code Here

        }

        // Set locale if needed
        processSetLocale(request);

        RequestContext requestContext = getRequestContext();
        String contextPath = request.getContextPath();
        requestContext.consumeURIPart(KPI_MAPPING);
        navigationManager.setShowingConfig(false);
        String requestUri = request.getRequestURI();
        String relativeUri = requestUri.substring(contextPath == null ? 0 : (contextPath.length()));
        relativeUri = relativeUri.substring(servletPath == null ? 0 : (servletPath.length()));

        // Empty URI -> nothing to do.
        if (StringUtils.isBlank(relativeUri)) {
            return true;
        }

        // Tokenize the friendly URI.
        StringTokenizer tokenizer = new StringTokenizer(relativeUri, "/", false);
        String action = null;
        if (tokenizer.hasMoreTokens()) action = tokenizer.nextToken();

        try {
            // Invoke the right action
            CommandResponse cmdResponse = null;
            if ("show".equalsIgnoreCase(action)) {
                cmdResponse = processShowKPI(request, response);
                requestContext.consumeURIPart("/" + action);
            }
            else {
                log.error("Invalid KPI URL: " + relativeUri);
            }

            // Set response if needed
            if (cmdResponse != null) {
                // Set successful response
                requestContext.setResponse(cmdResponse);
            } else {
                // Response parameters missing or wrong action
                requestContext.setResponse(new SendErrorResponse(HttpServletResponse.SC_NOT_FOUND));
            }
        } catch (Exception e) {
            // Handler response error
            ErrorManager.lookup().notifyError(e, true);
            requestContext.setResponse(new SendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
        }
        return true;
    }
View Full Code Here

    @Inject
    private BeanDispatcher beanDispatcher;

    public boolean processRequest() throws Exception {
        RequestContext requestContext = getRequestContext();
        HttpServletRequest request = getHttpRequest();
        String pAction = request.getParameter(Parameters.DISPATCH_ACTION);
        String idPanel = request.getParameter(Parameters.DISPATCH_IDPANEL);
        if (StringUtils.isEmpty(pAction) || StringUtils.isEmpty(idPanel)) {
            log.debug("Running bean action.");
            CommandResponse res = beanDispatcher.handleRequest(getRequest());
            if (request.getServletPath().indexOf("/" + URLMarkupGenerator.COMMAND_RUNNER) != -1) {
                requestContext.consumeURIPart(requestContext.getURIToBeConsumed());
            }
            if (res != null) {
                requestContext.setResponse(res);
            }
            return true;
        }

        // Get the specified panel from the current page.
        Section currentPage = NavigationManager.lookup().getCurrentSection();
        Panel panel = currentPage.getPanel(idPanel);
        if (panel == null) {
            // If not found then try to get the panel from wherever the request comes from.
            panel = UIServices.lookup().getPanelsManager().getPaneltById(new Long(idPanel));
            if (panel == null) {
                log.error("Cannot dispatch to panel " + idPanel + ". Panel not found.");
                return true;
            }
            // Ensure the panel's section is set as current.
            // This is needed to support requests coming from pages reached after clicking the browser's back button.
            NavigationManager.lookup().setCurrentSection(panel.getSection());
        }

        CodeBlockTrace trace = new PanelActionTrace(panel, pAction).begin();
        try {
            WorkspacePermission workspacePerm = WorkspacePermission.newInstance(panel.getWorkspace(), WorkspacePermission.ACTION_LOGIN);
            if (UserStatus.lookup().hasPermission(workspacePerm)) {
                SectionPermission sectionPerm = SectionPermission.newInstance(panel.getSection(), SectionPermission.ACTION_VIEW);
                if (UserStatus.lookup().hasPermission(sectionPerm)) {
                    PanelProvider provider = panel.getInstance().getProvider();
                    if (provider.isEnabled()) {
                        PanelDriver handler = provider.getDriver();
                        CommandResponse response = handler.execute(panel, getRequest());
                        if (response != null)
                            requestContext.setResponse(response);
                        if (request.getServletPath().indexOf("/" + URLMarkupGenerator.COMMAND_RUNNER) != -1) {
                            requestContext.consumeURIPart(requestContext.getURIToBeConsumed());
                        }
                    }
                }
            }
        } finally {
View Full Code Here

TOP

Related Classes of org.jboss.dashboard.ui.controller.RequestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.