Exemple #1
0
 /**
  * keep backward compatibility with changed error codes
  * @param KalturaAPIException $e
  * @throws KalturaAPIException
  */
 private function throwTranslatedException(KalturaAPIException $e)
 {
     $code = $e->getCode();
     if ($code == KalturaErrors::USER_NOT_FOUND) {
         throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_NOT_FOUND);
     } else {
         if ($code == KalturaErrors::WRONG_OLD_PASSWORD) {
             throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_WRONG_OLD_PASSWORD, "wrong password");
         } else {
             if ($code == KalturaErrors::USER_WRONG_PASSWORD) {
                 throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_NOT_FOUND);
             } else {
                 if ($code == KalturaErrors::LOGIN_DATA_NOT_FOUND) {
                     throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_NOT_FOUND);
                 }
             }
         }
     }
     throw $e;
 }
Exemple #2
0
<table>
<tr>
	<th>Error Code</th>
	<th>Error message</th>
</tr>
<?php 
$odd = true;
foreach ($generalError as $error => $errorParams) {
    ?>
<tr class="<?php 
    echo $odd ? "odd" : "";
    ?>
">
<?php 
    $ex = new KalturaAPIException(null);
    call_user_func_array(array($ex, 'KalturaAPIException'), array_merge(array($error), $errorParams));
    ?>
	<td><?php 
    echo $ex->getCode();
    ?>
</td>
	<td><?php 
    echo $ex->getMessage();
    ?>
</td>
</tr>
<?php 
    $odd = !$odd;
}
?>
 protected function handleErrorMapping(KalturaAPIException $apiException, $service, $action)
 {
     if (!kConf::hasParam('api_strict_error_map')) {
         KalturaLog::err('api_strict_error_map was not found in kConf and is mandatory!');
         return new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR);
     }
     $map = kConf::get('api_strict_error_map');
     if (!is_array($map)) {
         return $apiException;
     }
     $mapKey = strtolower($service) . '_' . strtolower($action);
     if (!isset($map[$mapKey])) {
         return $apiException;
     }
     $mapParams = $map[$mapKey];
     $defaultError = isset($mapParams['defaultError']) ? $mapParams['defaultError'] : null;
     $defaultNull = isset($mapParams['defaultNull']) ? $mapParams['defaultNull'] : null;
     $whiteListedErrors = isset($mapParams['whitelisted']) ? $mapParams['whitelisted'] : array();
     if (!is_array($whiteListedErrors)) {
         $whiteListedErrors = array();
     }
     if (array_search($apiException->getCode(), $whiteListedErrors, true) !== false) {
         KalturaLog::debug('Returning white-listed error: ' . $apiException->getCode());
         return $apiException;
     }
     // finally, replace the error or return null as default
     if ($defaultNull) {
         KalturaLog::debug('Replacing error code "' . $apiException->getCode() . '" with null result');
         return null;
     } else {
         $reflectionException = new ReflectionClass("KalturaAPIException");
         $errorStr = constant($defaultError);
         $args = array_merge(array($errorStr), $apiException->getArgs());
         /** @var KalturaAPIException $replacedException */
         $replacedException = $reflectionException->newInstanceArgs($args);
         KalturaLog::debug('Replacing error code "' . $apiException->getCode() . '" with error code "' . $replacedException->getCode() . '"');
         return $replacedException;
     }
 }
 public function initService($serviceId, $serviceName, $actionName)
 {
     // init service and action name
     $this->serviceId = $serviceId;
     $this->serviceName = $serviceName;
     $this->actionName = $actionName;
     // impersonated partner = partner parameter from the request
     $this->impersonatedPartnerId = kCurrentContext::$partner_id;
     $this->ks = kCurrentContext::$ks_object ? kCurrentContext::$ks_object : null;
     // operating partner = partner from the request or the ks partner
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     // if there is no session, assume it's partner 0 using actions that doesn't require ks
     if (is_null($partnerId)) {
         $partnerId = 0;
     }
     $this->partner = PartnerPeer::retrieveByPK($partnerId);
     if (!$this->partner) {
         $this->partner = null;
     }
     // check if current aciton is allowed and if private partner data access is allowed
     $allowPrivatePartnerData = false;
     $actionPermitted = $this->isPermitted($allowPrivatePartnerData);
     // action not permitted at all, not even kaltura network
     if (!$actionPermitted) {
         $e = new KalturaAPIException(APIErrors::SERVICE_FORBIDDEN, $this->serviceId . '->' . $this->actionName);
         //TODO: should sometimes thorow MISSING_KS instead
         header("X-Kaltura:error-" . $e->getCode());
         header("X-Kaltura-App: exiting on error " . $e->getCode() . " - " . $e->getMessage());
         throw $e;
     }
     // init partner filter parameters
     $this->private_partner_data = $allowPrivatePartnerData;
     $this->partnerGroup = kPermissionManager::getPartnerGroup($this->serviceId, $this->actionName);
     if ($this->globalPartnerAllowed($this->actionName)) {
         $this->partnerGroup = PartnerPeer::GLOBAL_PARTNER . ',' . trim($this->partnerGroup, ',');
     }
     // apply partner filters according to current context and permissions
     myPartnerUtils::resetAllFilters();
     myPartnerUtils::applyPartnerFilters($partnerId, $this->private_partner_data, $this->partnerGroup, $this->kalturaNetworkAllowed($this->actionName));
 }
Exemple #5
0
 public function validateForUsage($sourceObject, $propertiesToSkip = array())
 {
     $useableProperties = array();
     $reflector = KalturaTypeReflectorCacher::get(get_class($this));
     if (!$reflector) {
         KalturaLog::err("Unable to validate usage for attribute object type [" . get_class($this) . "], type reflector not found");
         throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_USAGE_PERMISSION, get_class($this));
     }
     $properties = $reflector->getProperties();
     if ($reflector->requiresUsagePermission() && !kPermissionManager::getUsagePermitted(get_class($this), kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER)) {
         throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_USAGE_PERMISSION, get_class($this));
     }
     foreach ($properties as $property) {
         /* @var $property KalturaPropertyInfo */
         $propertyName = $property->getName();
         if ($propertiesToSkip && is_array($propertiesToSkip) && in_array($propertyName, $propertiesToSkip)) {
             continue;
         }
         if ($this->{$propertyName} !== null) {
             // check if property value is being changed - if not, just continue to the next
             $objectPropertyName = $this->getObjectPropertyName($propertyName);
             $getter_callback = array($sourceObject, "get{$objectPropertyName}");
             if (is_callable($getter_callback)) {
                 $value = call_user_func($getter_callback);
                 if ($value === $this->{$propertyName} || is_bool($this->{$propertyName}) && $value === (int) $this->{$propertyName}) {
                     continue;
                 }
             }
             // property requires update permissions, verify that the current user has it
             if ($property->requiresUsagePermission()) {
                 if (!kPermissionManager::getUsagePermitted($this->getDeclaringClassName($propertyName), $propertyName)) {
                     //throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     //TODO: not throwing exception to not break clients that sends -1 as null for integer values (etc...)
                     $e = new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_USAGE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     $this->{$propertyName} = null;
                     KalturaLog::err($this->getDeclaringClassName($propertyName) . '-' . $propertyName . ' error: ' . $e->getMessage());
                     header($this->getDeclaringClassName($propertyName) . '-' . $propertyName . ' error: ' . $e->getMessage());
                 }
             }
         }
     }
     return $useableProperties;
 }
Exemple #6
0
 public function validateForUpdate($source_object)
 {
     $updatableProperties = array();
     $reflector = KalturaTypeReflectorCacher::get(get_class($this));
     $properties = $reflector->getProperties();
     if ($reflector->requiresUpdatePermission() && !kPermissionManager::getUpdatePermitted(get_class($this), kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER)) {
         throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, get_class($this));
     }
     foreach ($properties as $property) {
         $propertyName = $property->getName();
         if ($this->{$propertyName} !== null) {
             // check if property value is being changed - if not, just continue to the next
             $objectPropertyName = $this->getObjectPropertyName($propertyName);
             $getter_callback = array($source_object, "get{$objectPropertyName}");
             if (is_callable($getter_callback)) {
                 $value = call_user_func($getter_callback);
                 if ($value === $this->{$propertyName}) {
                     continue;
                 }
             }
             if ($property->isReadOnly() || $property->isInsertOnly()) {
                 throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NOT_UPDATABLE, $this->getFormattedPropertyNameWithClassName($propertyName));
             }
             // property requires update permissions, verify that the current user has it
             if ($property->requiresUpdatePermission()) {
                 if (!kPermissionManager::getUpdatePermitted($this->getDeclaringClassName($propertyName), $propertyName)) {
                     //throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     //TODO: not throwing exception to not break clients that sends -1 as null for integer values (etc...)
                     $e = new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     $this->{$propertyName} = null;
                     header($this->getDeclaringClassName($propertyName) . '-' . $propertyName . ' error: ' . $e->getMessage());
                 }
             }
         }
     }
     return $updatableProperties;
 }