public function loadApiCredentials($apiOrId) { if (!$apiOrId instanceof \Application\Model\APIIdModel) { $apiOrId = \Application\Service\APIIdService::getInstance()->findOneByApiId($apiOrId); } return $this->setCredentials('api_' . $apiOrId->apiId, 'API_' . $apiOrId->apiId, $apiOrId->orgId, $apiOrId->apiId); }
public function generateCurrentUser(UserModel $user = null) { if (!\Zend_Auth::getInstance()->hasIdentity()) { throw new InvalidArgumentException("No logged user"); } $ident = \Zend_Auth::getInstance()->getIdentity(); if ($user instanceof CurrentUserModel) { $currentUser = $user; } else { if ($user != null) { $currentUser = new CurrentUserModel($user->exportData()); } else { $currentUser = new CurrentUserModel(); $authType = $ident['authType']; if ($authType == \App_Controller_Plugin_Auth::AUTH_TYPE_DOWNLOAD_TOKEN) { $authType = $ident['downloadToken']->authType; $currentUser->downloadToken = $ident['downloadToken']; } switch ($authType) { case \App_Controller_Plugin_Auth::AUTH_TYPE_AUTH_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_REGULAR: case \App_Controller_Plugin_Auth::AUTH_TYPE_CORE: case \App_Controller_Plugin_Auth::AUTH_TYPE_ACTIVATION_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_PASSWORD_EXPIRED_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD: $user = $this->loadByUsername($ident['username']); $currentUser->importData($user->exportData()); break; case \App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL: if (!isset($ident['apiId'])) { throw new InvalidArgumentException("No apiId defined"); } $apiId = APIIdService::getInstance()->findOneByApiId($ident['apiId']); $currentUser->id = $apiId->id; $currentUser->apiId = $apiId->apiId; $currentUser->userName = '******' . $apiId->apiId; $currentUser->organizationId = $apiId->orgId; $currentUser->appId = $apiId->appId; $currentUser->monetaryDataAccess = $apiId->monetaryDataAccess; $currentUser->role = 'admin'; break; case \App_Controller_Plugin_Auth::AUTH_TYPE_THIRD_PARTY: if (!isset($ident['serviceId'])) { throw new InvalidArgumentException("No serviceId defined"); } $currentUser->id = $ident['serviceId']; $currentUser->userName = $ident['username']; $currentUser->organizationId = $ident['orgId']; $currentUser->monetaryDataAccess = $ident['monetaryDataAccess']; $currentUser->role = $ident['role']; break; case \App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC: $currentUser->id = 'ASYNC-REQUEST'; $currentUser->userName = '******'; $currentUser->organizationId = 'ASYNC-REQUEST'; break; } } } if (!empty($ident['authType'])) { $currentUser->authType = $ident['authType']; } if (!empty($ident['token'])) { $currentUser->authToken = $ident['token']; } if (!empty($ident['impersonation'])) { $this->generateImpersonatedUser($currentUser, $ident['impersonation']); } return $currentUser; }
public function delete($orgOrId) { if (!isset($orgOrId) && !strlen($orgOrId)) { throw new InvalidArgumentException('function param cannot be null'); } if (!$orgOrId instanceof \Application\Model\OrgModelAbstract) { $org = $this->load($orgOrId); } else { $org = $orgOrId; } $validator = new \Application\Model\Validate\Organization\CustomerIsErasable(); if (!$validator->isValid($org)) { throw new ValidateException("customer {$orgOrId} is not erasable", array('validationErrors' => $validator->getMessages())); } $type = $this->getChildrenTypeByOrg($org); $filterListOrgService = $this->buildFilterList(array('type' => $type, \Application\Model\Filter\OrgFilterFields::PARENT_ID => $org->getId())); if ($org->getType() != OrgAggregatorModel::ORG_TYPE) { $list = $this->listAll($type, array('filterList' => $filterListOrgService)); $items = $list->getItems(); if (count($items) > 0) { throw new InvalidArgumentException('The organization has ChildOrgs and can not be deleted'); } } $templateService = TemplateService::getInstance(); $userService = UserService::getInstance(); $APPIdService = APIIdService::getInstance(); $this->deleteOrgElements($org, $templateService); $this->deleteOrgElements($org, $userService); $this->deleteOrgElements($org, $APPIdService); $mapper = $this->getMapperByType($this->getTypeById($org->getId())); $result = $mapper->delete($org->getId()); WatcherService::getInstance()->removeByScope('organization', $org->id); \App::audit('The organization with Id ' . $org->getId() . "has been deleted", $org); $this->_sendEvent('delete', $org); return $result; }