简体   繁体   中英

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!

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM