示例#1
0
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     if (empty($this->_request) || empty($this->_response)) {
         throw new Zend_Auth_Adapter_Exception('Request and Response objects must be set before calling authenticate method');
     }
     try {
         $apiId = $this->_getApiId();
         $apiIdMapper = Application\Model\Mapper\APIIdMapper::getInstance();
         $res = $apiIdMapper->findOneByApiId($apiId);
         if (empty($res)) {
             throw new \Application\Exceptions\NotFoundException("Api id '{$apiId}' not found (at Mongo)");
         }
         $orgId = $res->getOrgId();
         if (empty($orgId)) {
             throw new Zend_Auth_Adapter_Exception("Api id '{$apiId}' has no orgId (at Mongo)");
         }
         $apiUserId = $res->id;
         \Application\Model\Mapper\ProtoAbstractMapper::$accountingTransactionPrefix = $this->_prefix;
         \Application\Model\Mapper\ProtoAbstractMapper::$accountingUserId = 'API_' . $apiUserId;
         \Application\Model\Mapper\AbstractMapper::$organizationId = $orgId;
         $orgSrv = \Application\Service\OrgService::getInstance();
         $organization = $orgSrv->load($orgId);
         if (empty($organization)) {
             throw new \Application\Exceptions\NotFoundException("Org '{$orgId}' not found");
         }
         \Application\Model\Mapper\ProtoAbstractMapper::$language = $organization->defaultLanguage;
         $token = md5(uniqid(time(), true));
         $result = array('id' => $apiUserId, 'username' => 'API_' . $organization->getName(), 'token' => $token, 'orgId' => $orgId, 'role' => 'admin', 'authType' => App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL, 'apiId' => $apiId, 'monetaryDataAccess' => $res->getMonetaryDataAccess());
         return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $result);
     } catch (Exception $e) {
         \App::log()->err($e->getMessage());
     }
     if (isset($res)) {
         \App::log()->warn("API authentication failed: CERT-ID => " . $res->id ?: null);
     } else {
         \App::log()->warn("API authentication failed: API-ID => " . @$apiId ?: null);
     }
     return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
 }
示例#2
0
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     if (empty($this->_request) || empty($this->_response)) {
         throw new Zend_Auth_Adapter_Exception('Request and Response objects must be set before calling authenticate method');
     }
     try {
         $token = $this->_getAuthToken();
         $serviceSession = ServiceSessionService::getInstance()->checkToken($token);
         $fakeUserId = $serviceSession->originServiceId;
         $orgId = '';
         if ($serviceSession->contractId) {
             $contract = ContractService::getInstance()->load($serviceSession->contractId);
             if (empty($contract)) {
                 throw new InvalidArgumentException("Invalid contract id '{$serviceSession->contractId}'");
             }
             $orgId = $contract->organizationId;
         }
         \Application\Model\Mapper\ProtoAbstractMapper::$accountingTransactionPrefix = $this->_prefix;
         \Application\Model\Mapper\ProtoAbstractMapper::$accountingUserId = '3rdParty_' . $fakeUserId;
         \Application\Model\Mapper\AbstractMapper::$organizationId = $orgId;
         $orgSrv = \Application\Service\OrgService::getInstance();
         $organization = $orgSrv->load($orgId);
         if (empty($organization)) {
             throw new NotFoundException("Org '{$orgId}' not found");
         }
         \Application\Model\Mapper\ProtoAbstractMapper::$language = $organization->defaultLanguage;
         $result = array('id' => $fakeUserId, 'username' => '3rdParty_' . $serviceSession->originServiceId, 'token' => $token, 'orgId' => $orgId, 'role' => 'admin', 'authType' => App_Controller_Plugin_Auth::AUTH_TYPE_THIRD_PARTY, 'serviceId' => $serviceSession->originServiceId, 'contractId' => $serviceSession->contractId, 'monetaryDataAccess' => false);
         return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $result);
     } catch (Exception $e) {
         \App::log()->err($e->getMessage());
     }
     if (!empty($token)) {
         \App::log()->warn("3rd party token authentication failed: TOKEN => " . $token);
     } else {
         \App::log()->warn("3rd party token authentication failed: NO TOKEN ");
     }
     return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
 }
示例#3
0
 /**
  * User dependencies injection
  */
 public static function initUserAccount()
 {
     $ident = \Zend_Auth::getInstance()->getIdentity();
     // Transaction injection
     \App::get("trackingtoken");
     ProtoAbstractMapper::$accountingTransactionPrefix = 'Testing-';
     // User injection
     ProtoAbstractMapper::$accountingUserId = $ident['id'];
     ProtoAbstractMapper::$language = 'en';
     $user = \App::getUserLogged(null, true);
     $allowed = Zend_Controller_Action_HelperBroker::getStaticHelper('allowed');
     $allowed->setUser($user);
     AbstractMapper::$organizationId = $user->organizationId;
     // Org injection
     if (!empty($ident['orgId'])) {
         $org = OrgService::getInstance()->load($ident['orgId']);
         if (!$org) {
             $org = OrgModelFactory::factory(array('id' => $ident['orgId'], 'type' => OrganizationMapper::getTypeByOrgId($ident['orgId'])));
         }
         \App::getOrgUserLogged($org);
         AbstractMapper::$organizationId = $ident['orgId'];
     }
     WatcherMapper::getInstance()->destroySingleton();
 }
 /**
  * @param $data
  * @return mixed
  */
 protected function _mapData($data)
 {
     return $this->_mapper->mapToModel($data);
 }
示例#5
0
 public function __construct(AdapterInterface $adapter)
 {
     parent::__construct($adapter);
 }