AEM 6.2 Filters
We are currently working with an AEM 6.2 (SP1 is not installed) project, and I'm trying to understand and use filters for when an author is in Edit mode in order to restrict the amount of nesting N levels deep for a specific component. Is there any good documentation on Filters? I've seen ACS commons examples, but it doesn't help a whole lot as I'm trying to only trigger the filter on specific URL patterns (such as editor.html/content/{appDir}/*) using the following above my filter:
@Properties({
@Property(name="service.description", value="A Filter"),
@Property(name="sling.filter.pattern", value="editor.html/content/informa*")
})
Unable to get the filter to trigger with the above annotations, I decided to try another route by removing the @Properties and check the current WCMMode, only running the validation if it's in EDIT mode. I would prefer the above method work as to not constantly trigger the filter, but if that's not possible, I would expect the below to still work. The below filter will trigger on all requests, and I have logging in my "if" statement that checks for EDIT mode. Now when I make a request to any part of the AEM backend, the log will spit out entries such as:
07.09.2018 15:46:18.468 *DEBUG* [0:0:0:0:0:0:0:1 [1536356778468] GET /libs/granite/csrf/token.json HTTP/1.1] com.informa.filters.ColumnControlLimitFilter ***modeEDIT
07.09.2018 15:46:40.399 *DEBUG* [0:0:0:0:0:0:0:1 [1536356800399] GET /mnt/overlay/granite/ui/content/shell/header/actions/pulse.data.json HTTP/1.1] com.informa.filters.ColumnControlLimitFilter ***modeEDIT
07.09.2018 15:47:25.386 *DEBUG* [0:0:0:0:0:0:0:1 [1536356845386] GET /libs/granite/csrf/token.json HTTP/1.1] com.informa.filters.ColumnControlLimitFilter ***modeEDIT
07.09.2018 15:47:26.335 *DEBUG* [0:0:0:0:0:0:0:1 [1536356846335] GET /libs/granite/csrf/token.json HTTP/1.1] com.informa.filters.ColumnControlLimitFilter ***modeEDIT
07.09.2018 15:47:42.360 *DEBUG* [0:0:0:0:0:0:0:1 [1536356862360] GET /mnt/overlay/granite/ui/content/shell/header/actions/pulse.data.json HTTP/1.1] com.informa.filters.ColumnControlLimitFilter ***modeEDIT
07.09.2018 15:48:44.349 *DEBUG* [0:0:0:0:0:0:0:1 [1536356924349] GET /mnt/overlay/granite/ui/content/shell/header/actions/pulse.data.json HTTP/1.1] com.informa.filters.ColumnControlLimitFilter ***modeEDIT
************* Current Code **************
@SlingFilter(
label = "Filter implementation",
metatype = true,
generateComponent = true,
generateService = true,
order = 1,
scope = SlingFilterScope.REQUEST
)
public class ColumnControlLimitFilter implements Filter {
private Logger log = LoggerFactory.getLogger(ColumnControlLimitFilter.class);
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
WCMMode mode = WCMMode.fromRequest(request);
if (mode == WCMMode.EDIT) { //Tried mode.equals(WCMMode.EDIT) and same results
log.debug("***mode" + mode);
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
Does anybody have any suggestions on how to solve the above problem(s)? Much appreciated in advanced.
Thanks,
Danny