code: SessionImpl createSession(ConversationState user) throws RepositoryException, LoginException
     {
        if (IdentityConstants.SYSTEM.equals(user.getIdentity().getUserId()))
        {
           // Need privileges to get system session.
           SecurityManager security = System.getSecurityManager();
           if (security != null)
           {
              security.checkPermission(JCRRuntimePermissions.CREATE_SYSTEM_SESSION_PERMISSION);
           }
        }
        else if (DynamicIdentity.DYNAMIC.equals(user.getIdentity().getUserId()))
        {
           // Need privileges to get Dynamic session.
           SecurityManager security = System.getSecurityManager();
           if (security != null)
           {
              security.checkPermission(JCRRuntimePermissions.CREATE_DYNAMIC_SESSION_PERMISSION);
           }
        }
        if (SessionReference.isStarted())
        {
           return new TrackedSession(workspaceName, user, container);
        }
        else
        {
           return new SessionImpl(workspaceName, user, container);
        }
     }
docs: Creates Session object by given Credentials
  
  @param credentials
  @return the SessionImpl corresponding to the given {@link ConversationState}
  @throws RepositoryException