title: How SlingAuthenticationHandler talks to CRXLogin module
body: <p>I read about this point <a href="http://www.connectcon.ch/content/dam/connectWE/Pr%C3%A4sentation_Antonio_Sanso.pdf" rel="nofollow">here</a>. But after I could not figure out how the AuthenticationInfo object is passed to CRXLoginModule . What I have understood the flow of SlingAuthenticationHandler is as follows -</p>
  
  <ol>
  <li><p>SlingAuthenticator calls the AuthenticationHandler (the CQ default is TokenAuthenticationHandler)</p></li>
  <li><p>The AuthenticationHandler returns AuthenticationInfo with username and password. In the  code of SlingAuthenticationHandler and it just sends the AuthenticationInfo object from TokenUtil.createCredentials(request, response, this.repository, username, true); The code of TokenUtil class says - 
  </p>
  
  <pre><code>adminSession = repository.loginAdministrative(null);
  
  SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
  sc.setAttribute(".token", "");
  userSession = adminSession.impersonate(sc);
  
  TokenCredentials tc = new TokenCredentials((String)sc.getAttribute(".token"));
  AuthenticationInfo authInfo = new AuthenticationInfo("TOKEN", userId);
  authInfo.put("user.jcr.credentials", tc);
  </code></pre></li>
  <li><p>adminSession.impersonate(sc) calls org.apache.jackrabbit.core.SessionImpl.impersonate(Credential crd) which again calls org.apache.jackrabbit.core.RepositoryImpl.login and it allows to login and creates token in commit() method of org.apache.jackrabbit.core.security.authentication.DefaultLoginModule . </p></li>
  </ol>
  
  <p>Questions:</p>
  
  <p>Q1) How is the CRXLoginModule invoked when adminSession.impersonate(sc)  is executed? Which class file is responsible for this? </p>
  
  <p>Q2) I saw the code of SlingAuthenticator but it does not call javax.jcr.RepositoryFactory or com.day.crx.core.CRXRepositoryFactory. How does sling pass the AuthenticationInfo object to CRXLoginModule? </p>
  
  <p>Kindly help me to understand the flow. Appreciate your help!</p>