I am working on a special form handler in cq5.5 and everything is going fine. Now I am working on blocking some security, and one of my tasks is to implement a request throttling filter on the path of the form handlers.
I currently have something like
@Component(immediate = true, metatype = true) @Service(javax.servlet.Filter.class) @Properties({ @Property(name="service.pid", value="com.xxxxxx.cq.core.filter.FormFilter",propertyPrivate=false), @Property(name="service.description",value="FormFilter", propertyPrivate=false), @Property(name="service.vendor",value="xxxxxx - Microsites", propertyPrivate=false), @Property(name = "filter.scope", value = "request"), @Property(name = "sling.filter.scope", value = "request"), @Property(name = "service.ranking", intValue = 100001) }) public class FormFilter implements javax.servlet.Filter { private Logger LOGGER = LoggerFactory.getLogger(TrackingFilter.class.getName()); private static final Object lock = new Object(); @Override public void doFilter(ServletRequest pRequest, ServletResponse pResponse, FilterChain pChain) throws IOException, ServletException {
This works fine, but I would like to block it so that it only works on a specific path.
Thanks for any ideas.
---- EDIT ----- After further research, I found several messages stating that it was not possible to register a filter for the specified path for the default ServletFilter handler. Basically, two solutions to this problem that I found either created a new OSGI kit for the filter and registered it using ExtHTTPService or the board:
http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html
OR
Filter the URL inside the filter itself. So basically add a check for the specified path in my filter.
i.e:
@Override public void doFilter(ServletRequest pRequest, ServletResponse pResponse, FilterChain pChain) throws IOException, ServletException { String path = pRequest.getContextPath(); if (path.contains("my/matching/path") {
I would like to see if there are additional solutions to this problem, but I wanted to share what I managed to find so far, in the hope that this will help either increase the number of ideas, or even help someone with the same problem save some time on google search.
Thank you brody