Gated Content for assets | Community
Skip to main content
New Participant
December 1, 2020
Solved

Gated Content for assets

  • December 1, 2020
  • 1 reply
  • 1365 views

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() {
}

}

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by shelly-goel

@larry19  Your issue looks similar to one mentioned here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sling-filter-access-an-asset-url-with-the-requestdispatcher/qaq-p/231148

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/adobe/acs/samples/filters/impl/SampleServletFilter.java

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

1 reply

shelly-goel
shelly-goelAccepted solution
Employee
December 1, 2020

@larry19  Your issue looks similar to one mentioned here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sling-filter-access-an-asset-url-with-the-requestdispatcher/qaq-p/231148

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/adobe/acs/samples/filters/impl/SampleServletFilter.java

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