Gated Content for assets

Avatar

Avatar
Level 1
larry19
Level 1

Likes

0 likes

Total Posts

4 posts

Correct reply

0 solutions
View profile

Avatar
Level 1
larry19
Level 1

Likes

0 likes

Total Posts

4 posts

Correct reply

0 solutions
View profile
larry19
Level 1

01-12-2020

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

}

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 100
MVP
shelly-goel
MVP

Likes

246 likes

Total Posts

410 posts

Correct reply

105 solutions
Top badges earned
Affirm 100
Give Back 25
Ignite 3
Give Back 10
Validate 1
View profile

Avatar
Affirm 100
MVP
shelly-goel
MVP

Likes

246 likes

Total Posts

410 posts

Correct reply

105 solutions
Top badges earned
Affirm 100
Give Back 25
Ignite 3
Give Back 10
Validate 1
View profile
shelly-goel
MVP

01-12-2020

@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

Answers (0)