@JsonIgnore public Resource getImageResource() { if (imageResource == null && component != null) { String delegateResourceType = component.getProperties().get(IMAGE_DELEGATE, String.class); if (StringUtils.isEmpty(delegateResourceType)) { LOGGER.error("In order for image rendering delegation to work correctly you need to set up the imageDelegate property on" + " the {} component; its value has to point to the resource type of an image component.", component.getPath()); } else { imageResource = new ImageResourceWrapper(toBeWrapped, delegateResourceType, hiddenProperties); } } return imageResource; }
private Component findUrlFilterDefinitionComponent(Component component) { if (component == null) { return null; } ValueMap properties = component.getProperties(); // Collections.disjoint returns true if the collections // have nothing in common, so when it is false, use the current resource if (!Collections.disjoint(properties.keySet(), PROPERTY_NAMES)) { return component; } else { // otherwise, look at the resource type resource's super type return findUrlFilterDefinitionComponent(component.getSuperComponent()); } }
private Component findUrlFilterDefinitionComponent(Component component) { if (component == null) { return null; } ValueMap properties = component.getProperties(); // Collections.disjoint returns true if the collections // have nothing in common, so when it is false, use the current resource if (!Collections.disjoint(properties.keySet(), PROPERTY_NAMES)) { return component; } else { // otherwise, look at the resource type resource's super type return findUrlFilterDefinitionComponent(component.getSuperComponent()); } }
/** * Get the WCM Views for the component; Looks at both the content resource for the special wcmViews property * and looks up to the resourceType's cq:Component properties for wcmViews. * * @param request the request * @return the WCM Views for the component */ private List<String> getComponentViews(final SlingHttpServletRequest request) { final Set<String> views = new HashSet<String>(); final Resource resource = request.getResource(); if (resource == null) { return new ArrayList<String>(views); } final Component component = WCMUtils.getComponent(resource); final ValueMap properties = resource.adaptTo(ValueMap.class); if (component != null) { views.addAll(Arrays.asList(component.getProperties().get(PN_WCM_VIEWS, new String[]{}))); } if (properties != null) { views.addAll(Arrays.asList(properties.get(PN_WCM_VIEWS, new String[]{}))); } return new ArrayList<String>(views); }
/** * Get the WCM Views for the component; Looks at both the content resource for the special wcmViews property * and looks up to the resourceType's cq:Component properties for wcmViews. * * @param request the request * @return the WCM Views for the component */ private List<String> getComponentViews(final SlingHttpServletRequest request) { final Set<String> views = new HashSet<String>(); final Resource resource = request.getResource(); if (resource == null) { return new ArrayList<String>(views); } final Component component = WCMUtils.getComponent(resource); final ValueMap properties = resource.adaptTo(ValueMap.class); if (component != null) { views.addAll(Arrays.asList(component.getProperties().get(PN_WCM_VIEWS, new String[]{}))); } if (properties != null) { views.addAll(Arrays.asList(properties.get(PN_WCM_VIEWS, new String[]{}))); } return new ArrayList<String>(views); }
/** * Returns the content policy bound to the given component. * @param resourceResolver the request's resource resolver * @param imageResource the resource identifying the accessed image component * @param request the request from which to read specific attributes and parameters. Allows to resolve delegated policy resources. * @return the content policy. May be {@code nulll} in case no content policy can be found. */ private ContentPolicy getContentPolicy(@Nonnull ResourceResolver resourceResolver, @Nonnull Resource imageResource, @Nonnull SlingHttpServletRequest request) { ContentPolicyManager policyManager = resourceResolver.adaptTo(ContentPolicyManager.class); if (policyManager != null) { ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class); if (componentManager != null) { com.day.cq.wcm.api.components.Component component = componentManager.getComponentOfResource(imageResource); if (component != null && component.getProperties() != null) { String delegatingResourceType = component.getProperties().get(AbstractImageDelegatingModel.IMAGE_DELEGATE, String.class); if (StringUtils.isNotEmpty(delegatingResourceType)) { imageResource = new ImageResourceWrapper(imageResource, delegatingResourceType); } } } ContentPolicy contentPolicy = policyManager.getPolicy(imageResource, request); return contentPolicy; } else { LOGGER.warn("Could not get policy manager from resource resolver!"); } return null; }
@Override protected void visit(Resource resource) { final ValueMap properties = resource.adaptTo(ValueMap.class); final String[] resourceViews = properties.get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(resourceViews)) { this.views.addAll(Arrays.asList(resourceViews)); } final Component component = WCMUtils.getComponent(resource); if (component != null) { final String[] componentViews = component.getProperties().get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(componentViews)) { this.views.addAll(Arrays.asList(componentViews)); } } } }
@Override protected void visit(Resource resource) { final ValueMap properties = resource.adaptTo(ValueMap.class); final String[] resourceViews = properties.get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(resourceViews)) { this.views.addAll(Arrays.asList(resourceViews)); } final Component component = WCMUtils.getComponent(resource); if (component != null) { final String[] componentViews = component.getProperties().get(WCMViewsFilter.PN_WCM_VIEWS, String[].class); if (ArrayUtils.isNotEmpty(componentViews)) { this.views.addAll(Arrays.asList(componentViews)); } } } }
@Override protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException { boolean hasImageDelegation = false; ResourceResolver resourceResolver = request.getResourceResolver(); ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class); String suffix = request.getRequestPathInfo().getSuffix(); if (componentManager != null && StringUtils.isNotEmpty(suffix)) { Resource policiesRootPage = getPoliciesRootPage(resourceResolver, suffix); if (policiesRootPage != null) { String resourceType = suffix.substring(policiesRootPage.getPath().length() + 1, suffix.lastIndexOf('/')); com.day.cq.wcm.api.components.Component component = componentManager.getComponent(resourceType); if (component != null && component.isAccessible()) { String imageDelegate = component.getProperties().get(AbstractImageDelegatingModel.IMAGE_DELEGATE, String.class); if (StringUtils.isNotEmpty(imageDelegate)) { hasImageDelegation = true; com.day.cq.wcm.api.components.Component delegate = componentManager.getComponent(imageDelegate); if (delegate != null && delegate.isAccessible()) { ExpressionCustomizer customizer = ExpressionCustomizer.from(request); customizer.setVariable(AbstractImageDelegatingModel.IMAGE_DELEGATE, delegate); } } } } } request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(hasImageDelegation)); }
clientLibraryCategories.addAll(Sets.newHashSet(configurationComponent.getProperties().get(ApplicationRoot.REQUIRED_CLIENT_LIBRARY_CATEGORIES, new String[]{})));
public Set<String> getRequiredAngularModules() { if (applicationModules != null) { return applicationModules; } applicationModules = Sets.newHashSet(); for (ComponentNode currentChildNode : rootPage.adaptTo(ComponentNode.class).getParent().get().findDescendants(COMPONENT_REQUIRES_ANGULAR_MODULES_PREDICATE)) { TypedResource typedResource = currentChildNode.getResource().adaptTo(TypedResource.class); if (typedResource != null) { applicationModules.addAll(typedResource.getResourceType().getAsListInherited(ANGULAR_REQUIRED_MODULES_KEY, String.class)); } } ConfigurationManager configurationManager = rootPage.getContentResource().getResourceResolver().adaptTo(ConfigurationManager.class); for(Iterator<Configuration> configurations = configurationManager.getConfigurations(rootPage.getContentResource()); configurations.hasNext();) { Configuration currentConfiguration = configurations.next(); //TODO: Refactor so this adaptation isn't in the FOR loop //TODO: Determine if we need to make this come from an admin resource resolver ComponentManager componentManager = currentConfiguration.getContentResource().getResourceResolver().adaptTo(ComponentManager.class); applicationModules.addAll(Lists.newArrayList( componentManager.getComponentOfResource(currentConfiguration.getContentResource()).getProperties().get(ApplicationRoot.ANGULAR_REQUIRED_MODULES_KEY, new String[]{}))); } return applicationModules; }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse) { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response; RequestPathInfo pathInfo = slingRequest.getRequestPathInfo(); Component definitionComponent = findUrlFilterDefinitionComponent(slingRequest.getResource(), slingRequest.getResourceResolver().adaptTo(ComponentManager.class)); if (definitionComponent != null) { String definitionPath = definitionComponent.getPath(); log.debug("found url filter definition resource at {}", definitionPath); ValueMap properties = definitionComponent.getProperties(); if (properties != null) { if (checkSelector(pathInfo, properties) && checkSuffix(pathInfo, properties) && checkExtension(pathInfo, properties)) { log.debug("url filter definition resource at {} passed for request {}.", definitionPath, slingRequest.getRequestPathInfo()); } else { log.info("url filter definition resource at {} FAILED for request {}.", definitionPath, slingRequest.getRequestPathInfo()); slingResponse.sendError(403); return; } } } } chain.doFilter(request, response); }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse) { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response; RequestPathInfo pathInfo = slingRequest.getRequestPathInfo(); Component definitionComponent = findUrlFilterDefinitionComponent(slingRequest.getResource(), slingRequest.getResourceResolver().adaptTo(ComponentManager.class)); if (definitionComponent != null) { String definitionPath = definitionComponent.getPath(); log.debug("found url filter definition resource at {}", definitionPath); ValueMap properties = definitionComponent.getProperties(); if (properties != null) { if (checkSelector(pathInfo, properties) && checkSuffix(pathInfo, properties) && checkExtension(pathInfo, properties)) { log.debug("url filter definition resource at {} passed for request {}.", definitionPath, slingRequest.getRequestPathInfo()); } else { log.info("url filter definition resource at {} FAILED for request {}.", definitionPath, slingRequest.getRequestPathInfo()); slingResponse.sendError(403); return; } } } } chain.doFilter(request, response); }