Search in sources :

Example 1 with ContentResolverResult

use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.

the class ComponentHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
    final Content content = resolvedContent.getContentOrElseThrow();
    final Site site = resolvedContent.getNearestSiteOrElseThrow();
    Page page = content.getPage();
    final PageResolverResult resolvedPage = pageResolver.resolve(request.getMode(), content, site);
    Component component = null;
    if (content.getType().isFragment()) {
        // fragment content, try resolving component path in Layout fragment
        final Component fragmentComponent = page.getFragment();
        if (this.componentPath.isEmpty()) {
            component = fragmentComponent;
        } else if (fragmentComponent instanceof LayoutComponent) {
            component = ((LayoutComponent) fragmentComponent).getComponent(this.componentPath);
        }
    }
    final Page effectivePage;
    if (component == null) {
        effectivePage = inlineFragments(resolvedPage.getEffectivePage(), this.componentPath);
        component = effectivePage.getRegions().getComponent(this.componentPath);
    } else {
        effectivePage = resolvedPage.getEffectivePage();
    }
    if (component == null) {
        throw WebException.notFound(String.format("Page component for [%s] not found", this.componentPath));
    }
    final Content effectiveContent = Content.create(content).page(effectivePage).build();
    final DescriptorKey controller = resolvedPage.getController();
    this.request.setSite(site);
    this.request.setContent(effectiveContent);
    this.request.setComponent(component);
    this.request.setApplicationKey(controller != null ? controller.getApplicationKey() : null);
    final Trace trace = Tracer.current();
    if (trace != null) {
        trace.put("componentPath", component.getPath());
        trace.put("type", component.getType().toString());
    }
    final PortalResponse response = rendererDelegate.render(component, this.request);
    return this.postProcessor.processResponseInstructions(this.request, response);
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) Site(com.enonic.xp.site.Site) Trace(com.enonic.xp.trace.Trace) PortalResponse(com.enonic.xp.portal.PortalResponse) Content(com.enonic.xp.content.Content) DescriptorKey(com.enonic.xp.page.DescriptorKey) Page(com.enonic.xp.page.Page) FragmentComponent(com.enonic.xp.region.FragmentComponent) Component(com.enonic.xp.region.Component) LayoutComponent(com.enonic.xp.region.LayoutComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 2 with ContentResolverResult

use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.

the class ServiceHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    // Retrieves the ServiceDescriptor
    final DescriptorKey descriptorKey = DescriptorKey.from(applicationKey, name);
    final ServiceDescriptor serviceDescriptor = serviceDescriptorService.getByKey(descriptorKey);
    if (serviceDescriptor == null) {
        throw WebException.notFound(String.format("Service [%s] not found", descriptorKey));
    }
    // Checks if the access to ServiceDescriptor is allowed
    final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
    if (!serviceDescriptor.isAccessAllowed(principals)) {
        throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
    }
    final ContentResolverResult resolvedContent = contentResolver.resolve(request);
    final Site site = resolvedContent.getNearestSite();
    // Checks if the application is set on the current site
    if (site != null) {
        final PropertyTree siteConfig = site.getSiteConfig(applicationKey);
        if (siteConfig == null) {
            throw WebException.forbidden(String.format("Service [%s] forbidden for this site", descriptorKey));
        }
    }
    // Checks if the application is set on the current application
    final ApplicationKey baseApplicationKey = getBaseApplicationKey();
    if (baseApplicationKey != null && !baseApplicationKey.equals(applicationKey)) {
        throw WebException.forbidden(String.format("Service [%s] forbidden for this application", descriptorKey));
    }
    // Prepares the request
    this.request.setApplicationKey(applicationKey);
    this.request.setContent(resolvedContent.getContent());
    this.request.setSite(site);
    // Executes the service
    final ControllerScript controllerScript = getScript();
    final PortalResponse portalResponse = controllerScript.execute(this.request);
    final WebSocketConfig webSocketConfig = portalResponse.getWebSocket();
    final WebSocketContext webSocketContext = this.request.getWebSocketContext();
    if ((webSocketContext != null) && (webSocketConfig != null)) {
        final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig);
        webSocketContext.apply(webSocketEndpoint);
    }
    return portalResponse;
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) Site(com.enonic.xp.site.Site) ApplicationKey(com.enonic.xp.app.ApplicationKey) PortalResponse(com.enonic.xp.portal.PortalResponse) WebSocketConfig(com.enonic.xp.web.websocket.WebSocketConfig) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) ServiceDescriptor(com.enonic.xp.service.ServiceDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) WebSocketEndpoint(com.enonic.xp.web.websocket.WebSocketEndpoint) DescriptorKey(com.enonic.xp.page.DescriptorKey) WebSocketContext(com.enonic.xp.web.websocket.WebSocketContext)

Example 3 with ContentResolverResult

use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.

the class PageHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
    final Content content = resolvedContent.getContentOrElseThrow();
    if (content.getType().isShortcut()) {
        return renderShortcut(content);
    }
    final Site site = resolvedContent.getNearestSiteOrElseThrow();
    final PageResolverResult resolvedPage = pageResolver.resolve(request.getMode(), content, site);
    final Content effectiveContent = Content.create(content).page(resolvedPage.getEffectivePage()).build();
    final DescriptorKey pageDescriptorKey = resolvedPage.getController();
    this.request.setSite(site);
    this.request.setContent(effectiveContent);
    this.request.setApplicationKey(pageDescriptorKey != null ? pageDescriptorKey.getApplicationKey() : null);
    this.request.setPageDescriptor(pageDescriptorKey != null ? this.pageDescriptorService.getByKey(pageDescriptorKey) : null);
    final Trace trace = Tracer.current();
    if (trace != null) {
        trace.put("contentPath", effectiveContent.getPath().toString());
        trace.put("type", "page");
    }
    return rendererDelegate.render(effectiveContent, this.request);
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) Site(com.enonic.xp.site.Site) Trace(com.enonic.xp.trace.Trace) Content(com.enonic.xp.content.Content) DescriptorKey(com.enonic.xp.page.DescriptorKey)

Example 4 with ContentResolverResult

use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.

the class IdentityHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
    this.request.setContent(resolvedContent.getContent());
    this.request.setSite(resolvedContent.getNearestSite());
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().idProviderKey(idProviderKey).functionName(idProviderFunction).portalRequest(this.request).build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    if (portalResponse == null) {
        throw WebException.notFound(String.format("ID Provider function [%s] not found for id provider [%s]", idProviderFunction, idProviderKey));
    } else {
        return portalResponse;
    }
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)

Example 5 with ContentResolverResult

use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.

the class MappingHandler method handle.

@Override
public WebResponse handle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
    if (!(webRequest instanceof PortalRequest) || webRequest.getEndpointPath() != null) {
        return webHandlerChain.handle(webRequest, webResponse);
    }
    final PortalRequest request = (PortalRequest) webRequest;
    if (request.getMode() == RenderMode.ADMIN || !request.isSiteBase()) {
        return webHandlerChain.handle(webRequest, webResponse);
    }
    WebHandlerHelper.checkAdminAccess(request);
    final HttpMethod method = webRequest.getMethod();
    if (!HttpMethod.standard().contains(method)) {
        throw new WebException(HttpStatus.METHOD_NOT_ALLOWED, String.format("Method %s not allowed", method));
    }
    final ContentResolverResult resolvedContent = contentResolver.resolve(request);
    final Site site = resolvedContent.getNearestSite();
    if (site == null) {
        return webHandlerChain.handle(request, webResponse);
    }
    final Content content = resolvedContent.getContent();
    final Optional<ControllerMappingDescriptor> resolve = controllerMappingsResolver.resolve(resolvedContent.getSiteRelativePath(), request.getParams(), content, site.getSiteConfigs());
    if (resolve.isPresent()) {
        final ControllerMappingDescriptor mapping = resolve.get();
        request.setContent(content);
        request.setSite(site);
        request.setContextPath(request.getBaseUri() + "/" + request.getBranch() + site.getPath());
        request.setApplicationKey(mapping.getApplication());
        if (mapping.isController()) {
            return handleController(request, mapping);
        } else {
            return handleFilter(request, webResponse, webHandlerChain, mapping);
        }
    } else {
        return webHandlerChain.handle(request, webResponse);
    }
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) Content(com.enonic.xp.content.Content) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) HttpMethod(com.enonic.xp.web.HttpMethod) PortalRequest(com.enonic.xp.portal.PortalRequest)

Aggregations

ContentResolverResult (com.enonic.xp.portal.impl.ContentResolverResult)5 Site (com.enonic.xp.site.Site)4 Content (com.enonic.xp.content.Content)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 Trace (com.enonic.xp.trace.Trace)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 Page (com.enonic.xp.page.Page)1 PortalRequest (com.enonic.xp.portal.PortalRequest)1 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)1 IdProviderControllerExecutionParams (com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)1 Component (com.enonic.xp.region.Component)1 FragmentComponent (com.enonic.xp.region.FragmentComponent)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)1 ServiceDescriptor (com.enonic.xp.service.ServiceDescriptor)1 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)1 HttpMethod (com.enonic.xp.web.HttpMethod)1 WebException (com.enonic.xp.web.WebException)1