@Path(":pages") @GET @Produces(MimeTypes.APPLICATION_JSON_UTF8) public NavigationItem getPages() { List<PageInstance> pageInstancePath = new ArrayList<PageInstance>(); PageInstance current = pageInstance; while (current != null) { pageInstancePath.add(0, current); current = current.getParent(); } //TODO |dispatch is not cached in REST calls, so we have to build it from actual page instances //TODO |to avoid building it from scratch and losing potential modifications to page instances title and //TODO |description done by pages in the path. Dispatch dispatch = new Dispatch(pageInstancePath.toArray(new PageInstance[pageInstancePath.size()])); return new Navigation( portofinoConfiguration, dispatch, SecurityUtils.getSubject(), false). getRootNavigationItem(); }
public PageInstance getPageInstance() { return dispatch.getLastPageInstance(); }
public PageInstance getPageInstance(int index) { if(index >= 0) { return getPageInstancePath()[index]; } else { return getPageInstancePath()[getPageInstancePath().length + index]; } }
pagePath = new ArrayList<PageInstance>(Arrays.asList(dispatch.getPageInstancePath())); String[] fragments = StringUtils.split(path.substring(subPath.length()), '/'); currentElement = dispatch.getLastPageInstance().getActionBean(); dispatch = new Dispatch(pagePath.toArray(new PageInstance[pagePath.size()])); cache.put(path, dispatch); return dispatch;
int start = dispatch.getClosestSubtreeRootIndex(); PageInstance pageInstance = dispatch.getPageInstance(start); PageInstance parentPageInstance = pageInstance.getParent(); if(parentPageInstance == null) { PageInstance current = dispatch.getPageInstancePath()[i]; sb.append("/"); Page page = current.getPage();
HttpServletRequest request = actionContext.getRequest(); logger.debug("Preparing PageActions"); for(PageInstance page : dispatch.getPageInstancePath()) { if(page.getParent() == null) { logger.debug("Not preparing root"); PageInstance pageInstance = dispatch.getLastPageInstance(); request.setAttribute(RequestAttributes.PAGE_INSTANCE, pageInstance);
dispatch.getPageInstancePath().length > 2 && SecurityLogic.hasPermissions( portofinoConfiguration, dispatch.getPageInstance(-2), subject, AccessLevel.EDIT); List<String[]> insertPositions = new ArrayList<String[]>();
private void buildTree() { int rootPageIndex = dispatch.getClosestSubtreeRootIndex(); PageInstance[] pageInstances = dispatch.getPageInstancePath(rootPageIndex); if (pageInstances == null || pageInstances.length == 0) { return; null, true, rootSelected, rootGhost); LinkedList<Page> pages = new LinkedList<Page>(); PageInstance[] allInstances = dispatch.getPageInstancePath(); for(int i = 0; i <= rootPageIndex; i++) { pages.add(allInstances[i].getPage());
break; case SIBLING: parentPageInstance = dispatch.getPageInstance(-2); parentPage = parentPageInstance.getPage(); parentLayout = parentPageInstance.getLayout();
@Override public Class<? extends ActionBean> getActionBeanType(String path) { if(path.startsWith(APIRoot.PATH_PREFIX)) { return null; //Not an ActionBean (as far as Stripes is concerned) } Dispatch dispatch = getDispatch(path); if(dispatch != null) { Class<? extends ActionBean> actionBeanClass = dispatch.getActionBeanClass(); if(GroovyObject.class.isAssignableFrom(actionBeanClass) && !eventMappings.containsKey(actionBeanClass)) { synchronized (this) { addActionBean(actionBeanClass); } } return actionBeanClass; } else { return super.getActionBeanType(path); } }
protected boolean isSelected(PageInstance pageInstance) { return pageInstance == dispatch.getLastPageInstance(); }
public Breadcrumbs(Dispatch dispatch) { this(dispatch, dispatch.getPageInstancePath().length); }
@Override @Before public Resolution prepare() { originalPath = "/"; File rootDir = pagesDir; Page rootPage; try { rootPage = DispatcherLogic.getPage(rootDir); } catch (Exception e) { throw new Error("Couldn't load root page", e); } pageInstance = new PageInstance(null, rootDir, rootPage, SafeModeAction.class); dispatch = new Dispatch(pageInstance); return null; }
public Class<? extends ActionBean> getActionBeanClass() { return getLastPageInstance().getActionClass(); }
public int getClosestSubtreeRootIndex() { PageInstance[] path = getPageInstancePath(); for(int i = path.length - 1; i > 0; i--) { if(path[i].getPage().getActualNavigationRoot() != NavigationRoot.INHERIT) { return i; } } return 0; }
protected void checkActionBeanInvocation(ContainerRequestContext requestContext, PageAction pageAction) { Method handler = resourceInfo.getResourceMethod(); List<PageInstance> pageInstancePath = new ArrayList<PageInstance>(); PageInstance last = pageAction.getPageInstance(); while(last != null) { pageInstancePath.add(0, last); last = last.getParent(); } Dispatch dispatch = new Dispatch(pageInstancePath.toArray(new PageInstance[pageInstancePath.size()])); HttpServletRequest request = ElementsThreadLocals.getHttpServletRequest(); if(!SecurityLogic.isAllowed(request, dispatch, pageAction, handler)) { Response.Status status = SecurityUtils.getSubject().isAuthenticated() ? Response.Status.FORBIDDEN : Response.Status.UNAUTHORIZED; requestContext.abortWith(Response.status(status).build()); } else if(!ButtonsLogic.doGuardsPass(pageAction, handler)) { requestContext.abortWith( Response.status(Response.Status.CONFLICT) .entity("The action couldn't be invoked, a guard did not pass") .build()); } else { logger.debug("Portofino-specific security check passed"); } }
public static boolean hasPermissions(Configuration conf, Dispatch dispatch, Subject subject, Method handler) { logger.debug("Checking action permissions"); return hasPermissions(conf, dispatch.getLastPageInstance(), subject, handler); }
if(dispatch != null) { logger.debug("The protected resource is a page action"); resource = dispatch.getLastPageInstance().getPath(); allowed = hasPermissions(configuration, dispatch, subject, handler); } else {
@Before public Resolution prepare() { Dispatcher dispatcher = DispatcherUtil.get(context.getRequest()); dispatch = dispatcher.getDispatch(originalPath); try{ pageInstance = dispatch.getLastPageInstance(); }catch (Exception e){ logger.warn(e.getMessage()); return new ForbiddenAccessResolution(); } if(pageInstance==null || !SecurityLogic.hasPermissions( portofinoConfiguration, pageInstance, SecurityUtils.getSubject(), AccessLevel.EDIT)) { return new ForbiddenAccessResolution(); } else { return null; } }
protected void buildCopyPageForm() { PageInstance pageInstance = dispatch.getLastPageInstance(); SelectionProvider pagesSelectionProvider = DispatcherLogic.createPagesSelectionProvider (pagesDir, true, true, pageInstance.getDirectory()); copyForm = new FormBuilder(CopyPage.class) .configReflectiveFields() .configSelectionProvider(pagesSelectionProvider, "destinationPagePath") .build(); }