/**
  * Performs user authorization
  *
  * @see http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-4.3
  *
  * @param string username
  * @param string password
  * @throws Nette\Application\AbortException on failed authorization
  */
 protected function processPasswordAuth($username, $password)
 {
     // Set NULL storage for user (no session storing)
     $this->user->setStorage();
     try {
         // Automatically logs attempts
         $this->user->login(User::AUTHN_METHOD_PASSWORD, User::AUTHN_SOURCE_ALL, $username, $password);
         // Set up token parameters
         if (!isset($this->tokenParameters)) {
             $this->tokenParameters = new \StdClass();
         }
         $this->tokenParameters->userIdentity = $this->user->identity;
     } catch (AuthenticationException $e) {
         if ($e->getCode() == BaseAuthenticator::MAXIMUM_ATTEMPTS_EXCEEDED) {
             $this->presenter->terminateWithError(self::ERROR_MAXIMUM_ATTEMPTS_EXCEEDED, 'Maximum number of authorization attempts exceeded.', 403);
         } else {
             $this->presenter->terminateWithError(self::ERROR_INVALID_GRANT, 'The provided credentials are invalid.', 401);
         }
     }
 }