|
Page Edited :
SLINGxSITE :
Authentication
Authentication has been edited by Felix Meschberger (Apr 26, 2009). Content:AuthenticationThis page is about how requests are authenticated in Sling. The process of authenticating client requests takes two steps: The first step extracts the credentials from the request and the second step tries to login to the JCR repository 1 . The former of these steps is extensible by providing AuthenticationHandler services, while the latter is coded into the SlingAuthenticator class. But before getting to much into the details, lets step back and look at the various actors in the authentication game. The SlingMaingServlet which is the main entry point into the Sling system for all request processing is registered with the OSGi HTTP Service. The servlet is registered together with a customized implementation of the OSGi HttpContext class. The HttpContext interface defines a handleSecurity method which is intended to authenticate the request. This method is implemented in Sling to use the SlingAuthenticator class which in turn uses AuthenticationHandler services to extract credentials from the request and login to the repository. This sounds all very nice, but how is this linked together ? Lets look at the processing steps from the point a request is sent to a Sling system to the moment the request is finally entering the SlingMainServlet.service method:
The important thing to note here is, that at the time the handleSecurity method is called, the SlingMainServlet is not yet in control of the request. So any functionality added by the SlingMainServlet, notably the SlingHttpServletRequest and SlingHttpServletResponse objects are not available to the implementation of the handleSecurity method. HttpContext.handleSecurityThe HttpContext.handleSecurity method is implemented by the SlingMainServlet because this servlet implements the HttpContext interface itself. The handleSecurity method simply calls SlingAuthenticator.authenticate method and returns the result of this call. If the call fails, an error is logged and false is returned to not handle the request. SlingAuthenticatorThe SlingAuthenticator class is an internal class of the org.apache.sling.engine bundle, which also has the SlingMainServlet. In fact the single instance of this class is managed by the SlingMainServlet. The SlingAuthenticator class has the following basic features:
The authenticate method gets credentials from the AuthenticationHandler and logs into the JCR repository using those credentials. If the login is successful, the SlingAuthenticator sets the following request attributes:
NOTE: Do NOT use the javax.jcr.Session request attribute in your Sling applications. This attribute must be considered an implementation specific to convey the JCR Session to the SlingMainServlet. In future versions of the Sling Engine bundle, this request attribute may not be present anymore. To get the JCR Session for the current request adapt the request's resource resolver to a JCR Session: Session session = request.getResourceResolver().adaptTo(Session.class);
|
Unsubscribe or edit your notifications preferences
