Is there a way to associate a DAM location to a site (for ACS custom error handling)?

jayv25585659

20-08-2019

Hello.

Can someone please help me debug a custom error handler that was developed by someone else? Thank you.

----------------

setup:

1. 4 sites in 1 AEM instance (/content/site1/en, /content/site2/en, /content/site3/en, /content/site4/en)

2. the 4 sites listed in no.1 each have an associated DAM location (/content/dam/site1, /content/dam/site2, /content/dam/site3, /content/dam/site4)

3. content of com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.xml

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

          jcr:primaryType="sling:OsgiConfig"

          enabled="{Boolean}true"

          cache.serve-authenticated="{Boolean}true"

          cache.ttl="{Long}300"

          error-page.system-path="/content/site1/en/errors/default"

          error-page.fallback-name="500"

          error-page.extension="html"

          paths="[/content/site1/en:errors, /content/site2/en:errors, /content/site3/en:errors, /content/site4/en:errors]"/>

4. snippet of my custom 404.jsp

<%

    if (!isAnonymousUser(slingRequest)) {

        final ResourceService resourceService = sling.getService(ResourceService.class);

        final String resourcePath = resource.getPath();

        if (resourceService.getResource(resourcePath) != null) {

            ErrorPageHandlerService acsErrorPageHandlerService = sling.getService(ErrorPageHandlerService.class);

            if (acsErrorPageHandlerService != null && acsErrorPageHandlerService.isEnabled()) {

                slingRequest = new ForbiddenRequest(slingRequest);

                slingResponse.setStatus(403);

                final String errorPagePath = acsErrorPageHandlerService.findErrorPage(slingRequest, resource);

                if (errorPagePath != null) {

                    acsErrorPageHandlerService.resetRequestAndResponse(slingRequest, slingResponse, 403);

                    acsErrorPageHandlerService.includeUsingGET(slingRequest, slingResponse, errorPagePath);

                    return;

                }

            }

        }

    }

%><%@include file="/apps/acs-commons/components/utilities/errorpagehandler/404.jsp" %>

----------------

situation/problem:

When unauthorized user request for a protected page, I get a 403 page for that site.

example: visiting the protected page site2.myhost.com/about when the user is not authorized displays the 403 page located in /content/site2/en/errors/403.html

When unauthorized user request for a protected asset, I get the default error page which is located in /content/site1/en/errors/default

example: visiting site2.myhost.com/content/dam/site2/protected/my-pdf-here.pdf when the user is not authorized displays the default error page located in /content/site1/en/errors/default

It seems to me that AEM doesn't know that the path /content/dam/site2 is associated with /content/site2/en/errors.

--------------

fixes/workaround:

1. Is there a way to associate this? Or maybe there's a configuration option I missed?

2. The workaround I'm thinking of is to replace findErrorPage call above with some custom code where I will use if-else/switch to determine the error page that will be loaded based on the value of resourcePath.

something like:

if (resourcePath.Contains("/content/site2") || resourcePath.Contains("/content/dam/site2")) {

    errorPagePath = "/content/site2/en/errors/403.html";

}

Answers (0)