Ejemplo n.º 1
0
 public static function setDefaultCriteriaFilter()
 {
     if (is_null(self::$s_criteria_filter)) {
         self::$s_criteria_filter = new criteriaFilter();
     }
     $c = new Criteria();
     $c->add(self::STATUS, AppTokenStatus::DELETED, Criteria::NOT_EQUAL);
     self::$s_criteria_filter->setFilter($c);
 }
Ejemplo n.º 2
0
 private function calculateId()
 {
     $dc = kDataCenterMgr::getCurrentDc();
     for ($i = 0; $i < 10; $i++) {
         $id = $dc["id"] . '_' . kString::generateStringId();
         $existingObject = AppTokenPeer::retrieveByPkNoFilter($id);
         if ($existingObject) {
             KalturaLog::log("ID [{$id}] already exists");
         } else {
             return $id;
         }
     }
     throw new Exception("Could not find unique id for AppToken");
 }
Ejemplo n.º 3
0
 public function getFieldNameFromPeer($field_name)
 {
     $res = AppTokenPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     return $res;
 }
Ejemplo n.º 4
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(AppTokenPeer::DATABASE_NAME);
         $criteria->add(AppTokenPeer::ID, $pks, Criteria::IN);
         $objs = AppTokenPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Ejemplo n.º 5
0
 /**
  * Starts a new KS (kaltura Session) based on application authentication token id
  * 
  * @action startSession
  * @param string $id application token id
  * @param string $tokenHash hashed token, built of sha1 on current KS concatenated with the application token
  * @param string $userId session user id, will be ignored if a different user id already defined on the application token
  * @param KalturaSessionType $type session type, will be ignored if a different session type already defined on the application token
  * @param int $expiry session expiry (in seconds), could be overwritten by shorter expiry of the application token and the session-expiry that defined on the application token 
  * @param string $privileges session privileges, will be appended to privileges that defined on the application token
  * @throws KalturaErrors::APP_TOKEN_ID_NOT_FOUND
  * @return KalturaSessionInfo
  */
 function startSessionAction($id, $tokenHash, $userId = null, $type = null, $expiry = null)
 {
     $dbAppToken = AppTokenPeer::retrieveByPK($id);
     if (!$dbAppToken) {
         throw new KalturaAPIException(KalturaErrors::APP_TOKEN_ID_NOT_FOUND, $id);
     }
     if ($dbAppToken->getStatus() != AppTokenStatus::ACTIVE) {
         throw new KalturaAPIException(KalturaErrors::APP_TOKEN_NOT_ACTIVE, $id);
     }
     $appTokenHash = sha1(kCurrentContext::$ks . $dbAppToken->getToken());
     if ($appTokenHash !== $tokenHash) {
         throw new KalturaAPIException(KalturaErrors::INVALID_APP_TOKEN_HASH);
     }
     KalturaResponseCacher::disableCache();
     $tokenExpiry = $dbAppToken->getSessionDuration();
     if (!is_null($dbAppToken->getExpiry())) {
         $tokenExpiry = min($tokenExpiry, $dbAppToken->getExpiry() - time());
         if ($tokenExpiry < 0) {
             throw new KalturaAPIException(KalturaErrors::APP_TOKEN_EXPIRED, $id);
         }
     }
     if (!$expiry) {
         $expiry = $tokenExpiry;
     }
     $expiry = min($expiry, $tokenExpiry);
     if (!is_null($dbAppToken->getSessionType())) {
         $type = $dbAppToken->getSessionType();
     }
     if (is_null($type)) {
         $type = SessionType::USER;
     }
     if (!is_null($dbAppToken->getSessionUserId())) {
         $userId = $dbAppToken->getSessionUserId();
     }
     $partnerId = kCurrentContext::getCurrentPartnerId();
     $partner = PartnerPeer::retrieveByPK($partnerId);
     $secret = $type == SessionType::ADMIN ? $partner->getAdminSecret() : $partner->getSecret();
     $privilegesArray = array(ks::PRIVILEGE_SESSION_ID => array($id), ks::PRIVILEGE_APP_TOKEN => array($id));
     if ($dbAppToken->getSessionPrivileges()) {
         $privilegesArray = array_merge_recursive($privilegesArray, ks::parsePrivileges($dbAppToken->getSessionPrivileges()));
     }
     $privileges = ks::buildPrivileges($privilegesArray);
     $ks = kSessionUtils::createKSession($partnerId, $secret, $userId, $expiry, $type, $privileges);
     if (!$ks) {
         throw new KalturaAPIException(APIErrors::START_SESSION_ERROR, $partnerId);
     }
     $sessionInfo = new KalturaSessionInfo();
     $sessionInfo->ks = $ks->toSecureString();
     $sessionInfo->partnerId = $partnerId;
     $sessionInfo->userId = $userId;
     $sessionInfo->expiry = $ks->valid_until;
     $sessionInfo->sessionType = $type;
     $sessionInfo->privileges = $privileges;
     return $sessionInfo;
 }
Ejemplo n.º 6
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(AppTokenPeer::DATABASE_NAME);
     $criteria->add(AppTokenPeer::ID, $this->id);
     if ($this->alreadyInSave) {
         if ($this->isColumnModified(AppTokenPeer::CUSTOM_DATA)) {
             if (!is_null($this->custom_data_md5)) {
                 $criteria->add(AppTokenPeer::CUSTOM_DATA, "MD5(cast(" . AppTokenPeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM);
             } else {
                 $criteria->add(AppTokenPeer::CUSTOM_DATA, NULL, Criteria::ISNULL);
             }
         }
         if (count($this->modifiedColumns) == 2 && $this->isColumnModified(AppTokenPeer::UPDATED_AT)) {
             $theModifiedColumn = null;
             foreach ($this->modifiedColumns as $modifiedColumn) {
                 if ($modifiedColumn != AppTokenPeer::UPDATED_AT) {
                     $theModifiedColumn = $modifiedColumn;
                 }
             }
             $atomicColumns = AppTokenPeer::getAtomicColumns();
             if (in_array($theModifiedColumn, $atomicColumns)) {
                 $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
             }
         }
     }
     return $criteria;
 }