Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Gated Content for assets

Avatar

Level 1

I have a client requirement for creating some gated content. So basically, the page ( which contains some assets) should only be reachable after the user has submitted a form. And the assets should also be not accessible directly without submitting the form. So i have created a servlet filter to achieve this, the page logic works fine but when i access a assets directly the request is not reaching the servlet filters. The below is my code please let me know if there is some mistake or there is any other prefered method, i have also tried setting this ServiceRanking(1)

@Component(service = Filter.class,
property = {
EngineConstants.SLING_FILTER_SCOPE + "=" + EngineConstants.FILTER_SCOPE_REQUEST,
})
@@ServiceRankin(-700)
public class GatedContentFilter implements Filter {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
final FilterChain filterChain) throws IOException, ServletException {


final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;

final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
final Resource resource = slingRequest.getResource();

if(resource.getPath().startsWith("/content/abc")) {
//page logic
}
else if (resource.getPath().startsWith("/content/dam/abc/gated-assets")) {
//assets logic
}

filterChain.doFilter(request, response);
}

@Override
public void init(FilterConfig filterConfig) {
}

@Override
public void destroy() {
}

}

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

@larry19  Your issue looks similar to one mentioned here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sling-filter-access-an-ass...

There's probably a DAM Asset filter that is taking precedence.Try using Felix Servlet Filter (they are executed by Apache Felix before the Sling Engine is engaged), example below:

https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/core/src/main/java/com/adob...

You can also look at <aem-instance>/system/console/status-slingfilter to see all the filters with ranking in your instance

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

@larry19  Your issue looks similar to one mentioned here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sling-filter-access-an-ass...

There's probably a DAM Asset filter that is taking precedence.Try using Felix Servlet Filter (they are executed by Apache Felix before the Sling Engine is engaged), example below:

https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/core/src/main/java/com/adob...

You can also look at <aem-instance>/system/console/status-slingfilter to see all the filters with ranking in your instance