@Override protected PortofinoRoot getRoot(FileObject actionsDirectory, ResourceResolvers resourceResolver) throws Exception { return PortofinoRoot.get(actionsDirectory, resourceResolver); }
protected PortofinoRoot(FileObject location, ResourceResolver resourceResolver) { setLocation(location); this.resourceResolver = resourceResolver; }
public static boolean unmount(FileObject object) { return children.remove(getDefaultMountPointName(object), object); }
protected void checkAuthorizations(ContainerRequestContext requestContext, Object resource) { try { Method handler = resourceInfo.getResourceMethod(); AUTH_CHECKER.assertAuthorized(resource, handler); logger.debug("Standard Shiro security check passed."); if(resource instanceof PageAction) { checkPageActionInvocation(requestContext, (PageAction) resource); } } catch (UnauthenticatedException e) { logger.debug("Method required authentication", e); requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); } catch (AuthorizationException e) { logger.warn("Method invocation not authorized", e); requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).build()); } }
/** * Returns a description of the root. * @since 5.0 * @return the page's description as JSON. */ @Path(":description") @Produces(MediaType.APPLICATION_JSON) @GET @RequiresPermissions(level = AccessLevel.NONE) public Map<String, Object> getJSONDescription() { Map<String, Object> description = new HashMap<String, Object>(); description.put("superclass", getClass().getSuperclass().getName()); description.put("class", getClass().getName()); description.put("page", pageInstance.getPage()); description.put("path", getPath()); description.put("children", getSubResources()); description.put("loginPath", portofinoConfiguration.getString("login.path")); return description; }
@Override public PortofinoRoot init() { super.init(); Page rootPage = PageLogic.getPage(location); PageInstance pageInstance = new PageInstance(null, location, rootPage, getClass()); setPageInstance(pageInstance); HttpServletRequest request = ElementsThreadLocals.getHttpServletRequest(); ActionContext context = new ActionContext(); context.setServletContext(servletContext); context.setRequest(request); context.setResponse(response); context.setActionPath("/"); setContext(context); return this; }
@Override public void filter(ContainerRequestContext requestContext) { UriInfo uriInfo = requestContext.getUriInfo(); if(uriInfo.getMatchedResources().isEmpty()) { return; } Object resource = uriInfo.getMatchedResources().get(0); if(resourceInfo == null || resourceInfo.getResourceClass() == null) { return; } if(resource.getClass() != resourceInfo.getResourceClass()) { throw new RuntimeException("Inconsistency: matched resource is not of the right type, " + resourceInfo.getResourceClass()); } fillMDC(); logger.debug("Publishing securityUtils in OGNL context"); OgnlContext ognlContext = ElementsThreadLocals.getOgnlContext(); ognlContext.put("securityUtils", new SecurityUtilsBean()); if(resource instanceof PageAction) { PageAction pageAction = (PageAction) resource; pageAction.prepareForExecution(); } checkAuthorizations(requestContext, resource); accessLogger.info(requestContext.getMethod()); }
public static PortofinoRoot get(FileObject location, ResourceResolver resourceResolver) throws Exception { Resource root = Root.get(location, resourceResolver); if (!(root instanceof PortofinoRoot)) { if(!root.getClass().equals(Root.class)) { logger.warn(root + " defined in " + location + " does not extend PortofinoRoot, ignoring"); } root = new PortofinoRoot(location, resourceResolver); } return (PortofinoRoot) root; }
@PostConstruct public void init() { FileObject fileObject; try { fileObject = VFS.getManager().resolveFile("res:com/manydesigns/portofino/upstairs/actions"); } catch (FileSystemException e) { throw new RuntimeException(e); } PortofinoRoot.mount(fileObject, "portofino-upstairs"); status = ModuleStatus.STARTED; }
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { addCacheHeaders(responseContext); for(String message : RequestMessages.consumeErrorMessages()) { responseContext.getHeaders().add(MESSAGE_HEADER, "error: " + message); } for(String message : RequestMessages.consumeWarningMessages()) { responseContext.getHeaders().add(MESSAGE_HEADER, "warning: " + message); } for(String message : RequestMessages.consumeInfoMessages()) { responseContext.getHeaders().add(MESSAGE_HEADER, "info: " + message); } }
@Override public void beforeScan(Reader reader, Swagger swagger) { super.beforeScan(reader, swagger); ModelConverters.getInstance().addConverter(new PortofinoModelResolver(Json.mapper())); }
@Override @Path("{pathSegment}") public Object consumePathSegment(@PathParam("pathSegment") String pathSegment) { logger.debug("Publishing securityUtils in OGNL context"); OgnlContext ognlContext = ElementsThreadLocals.getOgnlContext(); ognlContext.put("securityUtils", new SecurityUtilsBean()); logger.debug("Publishing textProvider in OGNL context"); ognlContext.put("textProvider", new TextProviderBean(ElementsThreadLocals.getTextProvider())); FileObject child = children.get(pathSegment); if(child != null) { return consumePathSegment(pathSegment, child, resourceResolver); } return super.consumePathSegment(pathSegment); }
public static void mount(FileObject fileObject) { FileObject previous = children.putIfAbsent(getDefaultMountPointName(fileObject), fileObject); if(previous != null) { throw new RuntimeException("Already mounted: " + previous); } }