2

I am trying to configure CQ5.5 SSO and setting HTTP Header Value using @SlingFilter.

It looks like there is a timming of execution issue where SlingFilter is processing the request after SSO Authentication Handler so it is unable to find the validated user in the Http Header.

Navi
  • 109
  • 1
  • 2
  • 9
  • Filters are sequentially so there shouldn't be a timing issue. Did you find a solution to the question raised yesterday? [CQ5.5 order standard HTTP filters deployed as OSGI components](http://stackoverflow.com/questions/15775044/cq5-5-order-standard-http-filters-deployed-as-osgi-components). Hopefully my answer below will help you confirm this. – diffa Apr 04 '13 at 15:56

2 Answers2

0

You can set a service ranking on your filter to control the order of execution.

@Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Description"),
  @Property(name = Constants.SERVICE_VENDOR, value = "Vendor"),
  @Property(name = Constants.SERVICE_RANKING, intValue = -760, propertyPrivate = true),
  @Property(name = "filter.scope", value = "request", propertyPrivate = true) 
})

You can see the service ranking of your existing filters by looking at the properties of the component e.g.

http://localhost:4502/system/console/components/org.apache.sling.i18n.impl.I18NFilter

It seems that if components have the same service ranking then their service.id will be used to determine their order.

You can see the order that the filers are being processed by looking at the recent requests

http://localhost:4502/system/console/requests

and picking the request you made. You'll see something like:

0 (2013-04-04 15:12:56) LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter
0 (2013-04-04 15:12:56) LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
0 (2013-04-04 15:12:56) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
0 (2013-04-04 15:12:56) LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter
0 (2013-04-04 15:12:56) LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
2 (2013-04-04 15:12:56) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
2 (2013-04-04 15:12:56) LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter

Some older filters will use the filter.order property. This is only used if the service.ranking property is not found. See SLING-1735.

diffa
  • 2,986
  • 1
  • 22
  • 35
  • Thanks diffa for your comments. In standard servlet filters (Apache Http Service Whiteboard support) service.ranking is the right way to order filters. – Navi Apr 05 '13 at 03:34
  • 1
    You should accept the answer that helped solve your problem, whether it was mine or your own. – diffa Apr 05 '13 at 06:52
-1

This was resolved by using a standard HTTP filter Instead of using a Sling Filter using the whiteboard support - Apache Http Service Whiteboard. Sling Filters are invoked after the user is authenticated and for my logic to work I need to intercept the request before it reaches the Sling Authentication Layer. So I need to register them as std Servlet Filter

@Component
@Service
@org.apache.felix.scr.annotations.Properties({
        @Property(name = "pattern", value = "/.*"),
        @Property(name = Constants.SERVICE_RANKING, intValue = 100000, propertyPrivate = false),
        @Property(name = "_usernameHeader", value = "SM_USER")
})
public class TestFilter implements javax.servlet.Filter {
Navi
  • 109
  • 1
  • 2
  • 9