/** * Start an impersonated session with Kaltura's server. * The result KS info contains the session key that you should pass to all services that requires a ticket. * Type, expiry and privileges won't be changed if they're not set * * @action impersonateByKs * @param string $session The old KS of the impersonated partner * @param KalturaSessionType $type Type of the new KS * @param int $expiry Expiry time in seconds of the new KS * @param string $privileges Privileges of the new KS * @return KalturaSessionInfo * * @throws APIErrors::START_SESSION_ERROR */ function impersonateByKsAction($session, $type = null, $expiry = null, $privileges = null) { KalturaResponseCacher::disableCache(); $oldKS = null; try { $oldKS = ks::fromSecureString($session); } catch (Exception $e) { KalturaLog::err($e->getMessage()); throw new KalturaAPIException(APIErrors::START_SESSION_ERROR, $this->getPartnerId()); } $impersonatedPartnerId = $oldKS->partner_id; $impersonatedUserId = $oldKS->user; $impersonatedType = $oldKS->type; $impersonatedExpiry = $oldKS->valid_until - time(); $impersonatedPrivileges = $oldKS->privileges; if (!is_null($type)) { $impersonatedType = $type; } if (!is_null($expiry)) { $impersonatedExpiry = $expiry; } if ($privileges) { $impersonatedPrivileges = $privileges; } // verify partner is allowed to start session for another partner $impersonatedPartner = null; if (!myPartnerUtils::allowPartnerAccessPartner($this->getPartnerId(), $this->partnerGroup(), $impersonatedPartnerId)) { $c = PartnerPeer::getDefaultCriteria(); $c->addAnd(PartnerPeer::ID, $impersonatedPartnerId); $impersonatedPartner = PartnerPeer::doSelectOne($c); } else { // get impersonated partner $impersonatedPartner = PartnerPeer::retrieveByPK($impersonatedPartnerId); } if (!$impersonatedPartner) { KalturaLog::err("Impersonated partner [{$impersonatedPartnerId} ]could not be fetched from the DB"); throw new KalturaAPIException(APIErrors::START_SESSION_ERROR, $this->getPartnerId()); } // set the correct secret according to required session type if ($impersonatedType == KalturaSessionType::ADMIN) { $impersonatedSecret = $impersonatedPartner->getAdminSecret(); } else { $impersonatedSecret = $impersonatedPartner->getSecret(); } $sessionInfo = new KalturaSessionInfo(); $result = kSessionUtils::startKSession($impersonatedPartnerId, $impersonatedSecret, $impersonatedUserId, $sessionInfo->ks, $impersonatedExpiry, $impersonatedType, '', $impersonatedPrivileges, $this->getPartnerId()); if ($result < 0) { KalturaLog::err("Failed starting a session with result [{$result}]"); throw new KalturaAPIException(APIErrors::START_SESSION_ERROR, $this->getPartnerId()); } $sessionInfo->partnerId = $impersonatedPartnerId; $sessionInfo->userId = $impersonatedUserId; $sessionInfo->expiry = $impersonatedExpiry; $sessionInfo->sessionType = $impersonatedType; $sessionInfo->privileges = $impersonatedPrivileges; return $sessionInfo; }
/** * Retrieve partner object by Id * * @action get * @param int $id * @return KalturaPartner * * @throws APIErrors::INVALID_PARTNER_ID */ public function getAction($id = null) { if (is_null($id)) { $id = $this->getPartnerId(); } $c = PartnerPeer::getDefaultCriteria(); $c->addAnd(PartnerPeer::ID, $id); $dbPartner = PartnerPeer::doSelectOne($c); if (is_null($dbPartner)) { throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $id); } $partner = new KalturaPartner(); $partner->fromObject($dbPartner); return $partner; }
/** * Function to change a sub-publisher's status * @action updateStatus * @param int $id * @param KalturaPartnerStatus $status * @throws KalturaErrors::UNKNOWN_PARTNER_ID */ public function updateStatusAction($id, $status) { $c = PartnerPeer::getDefaultCriteria(); $c->addAnd(PartnerPeer::ID, $id); $dbPartner = PartnerPeer::doSelectOne($c); if (!$dbPartner) { throw new KalturaAPIException(KalturaErrors::UNKNOWN_PARTNER_ID, $id); } $dbPartner->setStatus($status); $dbPartner->save(); PartnerPeer::removePartnerFromCache($id); }