protected function _mapData($data) { if ($data instanceof \DrSlump\Protobuf\Message) { $data = $data->serialize(new \DrSlump\Protobuf\Codec\PhpArray()); $data = Mapper\ProtoAbstractMapper::filterFieldNames(new \App_Filter_UnderscoreToCamelCase(), $data); } return $data; }
/** * Maps Ericsson proto message fields to application model fields * @param array $data * @return array */ protected function _mapEricssonModelToModel(array $data) { if (isset($data['customer_id'])) { $data['customerCrmId1'] = $data['customer_id']; unset($data['customer_id']); } if (isset($data['is_legacy'])) { $data['legacy'] = $data['is_legacy']; unset($data['is_legacy']); } if (isset($data['logistics_profile'])) { $data['logistics'] = $data['logistics_profile']; unset($data['logistics_profile']); } if (isset($data['initial_life_cycle_state'])) { $data['life_cycle_status'] = $this->mapEricssonToInitialLifeCycleStatus($data['initial_life_cycle_state']); unset($data['initial_life_cycle_state']); } if (isset($data['hlr_id'])) { $data['hlr'] = $data['hlr_id']; unset($data['hlr_id']); } if (isset($data['commercial_group_name'])) { $data['commercial_group'] = array('name' => $data['commercial_group_name']); unset($data['commercial_group_name']); } $data = parent::_mapEricssonModelToModel($data); if (isset($data['simType']) && isset($this->_simTypeMap[$data['simType']])) { $data['simType'] = $this->_simTypeMap[$data['simType']]; } if (isset($data['apns'])) { $data['apns'] = array_values($data['apns']); } //Invalid 0 as index... strange ericsson behaivor if (isset($data['staticIpApnIndex']) && !$data['staticIpApnIndex']) { unset($data['staticIpApnIndex']); } return $data; }
/** * 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(); }
/** * 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); }
/** * 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); }
protected function _mapEricssonModelToModel(array $data) { $target = $data['target']; unset($data['target']); $data += $this->_mapTarget($target); $data = parent::_mapEricssonModelToModel($data); if (isset($data['reportType'])) { $data['type'] = $this->mapReportType($data['reportType']); } if (isset($data['customerId'])) { $data['organization'] = $data['customerId']; unset($data['customerId']); } if (isset($data['serviceProviderId'])) { $data['organization'] = $data['serviceProviderId']; unset($data['serviceProviderId']); } return $data; }
public function setUp() { $mapper = ProtoAbstractMapper::getInstance(); $this->_sut = $mapper; }