public function login(&$subject, $token)
    {
        global $logger;
        global $app;
        try {
            if($app->getConfiguration()->isPreventMultipleLogins()) {
                list($authInfo, $roles, $tokens,$hashedSessionId) = $this->authenticate($token, true);
                $app->getSessionManager()->getActiveSession()->setAttribute('sessionHash', $hashedSessionId); 
            } else
                list($authInfo, $roles, $tokens) = $this->authenticate($token);
        } catch (AuthenticationException $aex) {
            $logger->error($aex->getMessage(), array($aex->getMessage()));
            throw $aex;
        }
        $loggedInSubj = $this->_createSubject($token, $authInfo, $subject, $roles);
        $this->_logAnalytics($app, $loggedInSubj);

        // Generate unique token to prevent XSRF.
        $app->getSessionManager()->getActiveSession()->setAttribute('nonce', $this->_generateCSRFToken(32)); 
            //sha1(uniqid(mt_rand(), true))); 
        $app->getSessionManager()->getActiveSession()->setAttribute(DefaultSubjectContext::AUTHENTICATED_SESSION_KEY, true);
        if(!empty($tokens)) {
            // FIXME: No token swapping done here - left to the application
            //$app->getSessionManager()->getActiveSession()->setAttribute('sharedKey', $tokens['token']); 
            //$app->getSessionManager()->getActiveSession()->setAttribute('secretKey', $tokens['secret']); 
            // FIXME: No token swapping done here - left to the application
            //// TODO : Fix Hack for storing account level tokens when logging in.
            //$session = $app->getSessionManager()->getActiveSession();
            //$session->setAttribute('accountSharedKey', $tokens['token']);
            //$session->setAttribute('accountSecretKey', $tokens['secret']);
        }
        return $loggedInSubj;

    }