May 22, 2020
Estimated Post Reading Time ~

Restricting javax.servlet.Filter to specific URL pattern

I'm trying to implement a Filter for a project in Adobe CQ 5.6.1. Seems nifty to be used for doing some, say, authentication stuff for each page that gets displayed.

I've read up on the documentation on Filters and I've coded my annotations this way:

@SlingFilter(
        label = "Filter implementation",
        metatype = true,
        generateComponent = true,
        generateService = true,
        order = 1,
        scope = SlingFilterScope.REQUEST
        )
@Properties({
    @Property(name="service.description", value="A Filter"),
    @Property(name="sling.filter.pattern", value="/some/path")
})

I've compiled my code and looked up the logs, but somehow, it doesn't seem to get filtered for that specific path indicated in the sling.filter.pattern. I don't seem to find much samples on how to implement this so I'm somewhat in the dark about this feature. What I'm sure of is I don't want this Filter to run on every URL that gets loaded.

Any leads would be appreciated. Thanks!

Best How To:
As mentioned in the question's comments, the sling.filter.pattern service property on Filters is only supported with V2.4.0 and later of the org.apache.sling.engine bundle. I have updated the docs at http://sling.apache.org/documentation/the-sling-engine/filters.html to mention this.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.