Пример #1
0
 /**
  * @param $file
  * @throws \RuntimeException
  * @return UploadedFile
  */
 public function getInput($file)
 {
     if (!file_exists($file)) {
         throw new \RuntimeException('File does not exist: ' . $file);
     }
     $objMapping = ['file' => $file];
     $uploadModel = new UploadedFile();
     $mapping = ['UPLOAD_SIZE' => 'size', 'UPLOAD_PERMS' => 'perms', 'UPLOAD_UID' => 'uid', 'UPLOAD_GID' => 'gid', 'UPLOAD_USER' => 'user', 'UPLOAD_GROUP' => 'group', 'UPLOAD_VUSER' => 'vUser'];
     foreach ($mapping as $export => $property) {
         if (isset($_SERVER[$export])) {
             switch ($property) {
                 case 'size':
                 case 'uid':
                 case 'gid':
                     $objMapping[$property] = (int) $_SERVER[$export];
                     break;
                 default:
                     $objMapping[$property] = $_SERVER[$export];
             }
         }
     }
     $authUser = $this->authApi->getUserData($objMapping['vUser']);
     if ($authUser) {
         $objMapping['fileHandler'] = $authUser->getFileHandler();
     }
     ObjectUtil::hydrateObject($uploadModel, $objMapping);
     return $uploadModel;
 }
Пример #2
0
 /**
  * @param $hostUid
  * @return Credentials
  */
 public function getCredentialsForHostUid($hostUid)
 {
     $hostData = $this->dataProvider->findHostByUid($hostUid);
     if (!$hostData) {
         return null;
     }
     $credentials = new Credentials();
     ObjectUtil::hydrateObject($credentials, $hostData);
     return $credentials;
 }
Пример #3
0
 /**
  * @param $login
  * @return AuthUser|null
  */
 public function getUserData($login)
 {
     $authUser = null;
     if (isset($this->config['auth']['users'][$login])) {
         $data = $this->config['auth']['users'][$login];
         $data['login'] = $login;
         $authUser = new AuthUser();
         ObjectUtil::hydrateObject($authUser, $data);
     }
     return $authUser;
 }
Пример #4
0
 /**
  * @param $login
  * @param $password
  * @param array $authScope
  * @return AbstractAuthAccount|null
  */
 public function getAuthAccountByCredentials($login, $password, array $authScope = [])
 {
     $authAccount = null;
     $result = $this->dataProvider->findUserByCredentials($login, $password, $authScope);
     if ($result) {
         $authAccount = new ContentPartnerAuthAccount();
         $mapping = ['isAuthenticated' => true, 'uid' => (int) $result['USR_ID'], 'login' => $result['CPM_NAME'], 'emailTech' => $result['CPM_EMAIL_TECH'], 'ipRanges' => $result['CPM_IP_RANGES'], 'flags' => $this->resolveFlags($result['CPM_FLAGS']), 'lang' => $result['USR_LANGUAGE_CODE'], 'userType' => UserTypeEnum::CONTENTPARTNER, 'lockType' => (int) $result['LCK_TP_HOST']];
         ObjectUtil::hydrateObject($authAccount, $mapping);
     }
     return $authAccount;
 }
Пример #5
0
 /**
  * @param array $uids
  * @param array $ftrTypes
  *
  * @return array
  */
 public function getFeatureTypesByUids(array $uids, array $ftrTypes)
 {
     $result = [];
     foreach ($this->findFeatureTypesByUids($uids, $ftrTypes) as $uid => $ftrTypesPerUid) {
         foreach ($ftrTypesPerUid as $ftrTypeId => $ftTypeData) {
             $ftrTypeModel = new FeatureTypeModel();
             ObjectUtil::hydrateObject($ftrTypeModel, ['uid' => (int) Functions::navl($ftTypeData, 'USR_ID'), 'ftrType' => (int) Functions::navl($ftTypeData, 'FTR_TP'), 'number' => (int) Functions::navl($ftTypeData, 'UFT_NUMBER'), 'text' => Functions::navl($ftTypeData, 'UFT_TEXT'), 'startDate' => Functions::nadvl($ftTypeData, 'UFT_START_DATE', $this->oracle), 'endDate' => Functions::nadvl($ftTypeData, 'UFT_END_DATE', $this->oracle), 'timestamp' => Functions::nadvl($ftTypeData, 'UFT_TIMESTAMP', $this->oracle)]);
             $result[$uid][$ftrTypeId] = $ftrTypeModel;
         }
     }
     return $result;
 }
Пример #6
0
 /**
  * @param array $result
  *
  * @return Model\RealPerson
  */
 protected function buildModel(array $result)
 {
     $model = null;
     if (is_array($result) && count($result) > 0) {
         $mapping['uid'] = (int) $result['USR_ID'];
         $mapping['login'] = $result['USR_LOGIN'];
         $mapping['userType'] = UserTypeEnum::resolveUserType($result['USR_TYPE']);
         $mapping['hostUids'] = array_map('intval', explode(',', $result['hostUids']));
         $model = new Model\RealPerson();
         ObjectUtil::hydrateObject($model, $mapping);
     }
     return $model;
 }
Пример #7
0
 /**
  * get or create external user
  *
  * @param $contentPartnerId
  * @param $externalUserId
  * @param $externalUsername
  * @return null|ExternalUserModel
  */
 public function getExternalUserByData($contentPartnerId, $externalUserId, $externalUsername)
 {
     $externalUser = $this->getExternalUserByContentPartnerIdAndExternalUserId($contentPartnerId, $externalUserId);
     if (!$externalUser) {
         $id = $this->dataProvider->getUserSubId($contentPartnerId, $externalUsername, $externalUserId);
         if (!$id) {
             $externalUser = ExternalUserModel::createFromArray(['contentPartnerId' => $contentPartnerId, 'username' => $externalUsername, 'externalUserId' => $externalUserId, 'externalUserName' => $externalUsername]);
             $externalUser->setDisplayName($this->getDisplayNameFromExternalUser($contentPartnerId, $externalUserId, $externalUsername));
             $id = $this->dataProvider->insertExternalUser($externalUser);
             ObjectUtil::hydrateObject($externalUser, ['id' => $id]);
             $this->dataProvider->setExternalUserToRedis($externalUser);
         }
     }
     return $externalUser;
 }
Пример #8
0
 /**
  * @param array $result
  *
  * @return Model\User
  */
 protected function buildModel(array $result)
 {
     $model = null;
     if (is_array($result) && count($result) > 0) {
         $mapping['uid'] = $result['USR_ID'];
         $mapping['login'] = $result['USR_LOGIN'];
         $mapping['userType'] = UserTypeEnum::resolveUserType($result['USR_TYPE']);
         $mapping['password'] = $result['USR_PWD'];
         $mapping['masterPassword'] = $result['USR_MASTERPWD'];
         $mapping['onlineState'] = $result['ONLINE_STATE'];
         $model = new Model\User();
         ObjectUtil::hydrateObject($model, $mapping);
     }
     return $model;
 }
Пример #9
0
 /**
  * @param mixed $object
  * @param array $mapping
  * @param bool $onlyObjectProperties
  */
 public static function hydrateObject($object, $mapping, $onlyObjectProperties = false)
 {
     if ($onlyObjectProperties) {
         $mapping = array_intersect_key($mapping, array_flip(ObjectUtil::getPropertyNames($object)));
     }
     // Closure::bind — Duplicates a closure with a specific bound object and class scope
     // @see http://www.php.net/manual/en/closure.bind.php
     /** @noinspection PhpUndefinedMethodInspection */
     $closure = Closure::bind(function () use($object, $mapping) {
         foreach ($mapping as $property => $value) {
             $object->{$property} = $value;
         }
     }, null, $object);
     $closure();
 }
Пример #10
0
 /**
  * @param $code
  * @return null|OAuthAuthAccount
  * @throws LoginFailedException
  */
 public function login($code)
 {
     $authAccount = null;
     if ($code) {
         $token = $this->getAccessTokenRequest($code);
         $jsonUserObj = $this->findUserObject($token);
         $roles = $jsonUserObj->ldap->roles;
         unset($roles->count);
         $mapping = array('isAuthenticated' => true, 'userId' => (int) $jsonUserObj->userdata->user_id, 'email' => $jsonUserObj->userdata->user_email, 'login' => $jsonUserObj->userdata->user_email, 'status' => $jsonUserObj->userdata->user_status, 'lastLogin' => $jsonUserObj->userdata->user_lastlogin ? new \DateTime($jsonUserObj->userdata->user_lastlogin, new DateTimeZone('Europe/Berlin')) : null, 'roles' => $roles, 'name' => $jsonUserObj->ldap->name);
         $authAccount = new OAuthAuthAccount();
         ObjectUtil::hydrateObject($authAccount, $mapping);
     } else {
         throw new InvalidArgumentException('Argument $code is empty in ' . __METHOD__);
     }
     return $authAccount;
 }
Пример #11
0
 /**
  * @param $userType
  * @param $result
  * @return Model\HostAuthAccount|Model\RealPersonAuthAccount|Model\UserAuthAccount
  */
 private function buildAuthAccount($userType, $result)
 {
     switch ($userType) {
         case UserTypeEnum::HOST:
             $authAccount = new Model\HostAuthAccount();
             break;
         case UserTypeEnum::REALPERSON:
             $authAccount = new Model\RealPersonAuthAccount();
             break;
         default:
             $authAccount = new Model\UserAuthAccount();
             break;
     }
     $mapping = ['isAuthenticated' => true, 'isMaster' => $result['IS_MASTER'], 'uid' => (int) $result['USR_ID'], 'login' => $result['USR_LOGIN'], 'email' => $result['URA_EMAIL'], 'lang' => $result['USR_LANGUAGE_CODE'], 'type' => $userType, 'lockType' => (int) $result['LOCK_TYPE']];
     ObjectUtil::hydrateObject($authAccount, $mapping);
     return $authAccount;
 }
Пример #12
0
 /**
  * @param array $data
  * @return VideoAmateurTexts
  */
 public static function createFromArray(array $data = [])
 {
     $model = new self();
     foreach ($data as $key => &$value) {
         switch ($key) {
             case 'hostUid':
                 $value = (int) $value;
                 break;
             case 'pictures':
                 if (!is_array($value)) {
                     throw new InvalidArgumentException('Invalid value for ' . $key . ', must be an array');
                 }
         }
     }
     ObjectUtil::hydrateObject($model, $data);
     return $model;
 }
Пример #13
0
 /**
  * @return AuthInputModel
  */
 public function getInput()
 {
     $objMapping = [];
     $authModel = new AuthInputModel();
     $mapping = ['AUTHD_ACCOUNT' => 'account', 'AUTHD_PASSWORD' => 'password', 'AUTHD_LOCAL_IP' => 'localIp', 'AUTHD_LOCAL_PORT' => 'localPort', 'AUTHD_REMOTE_IP' => 'remoteIp', 'AUTHD_ENCRYPTED' => 'encrypted'];
     foreach ($mapping as $export => $property) {
         if (isset($_SERVER[$export])) {
             switch ($property) {
                 case 'localPort':
                     $objMapping[$property] = (int) $_SERVER[$export];
                     break;
                 case 'encrypted':
                     $objMapping[$property] = (bool) $_SERVER[$export];
                     break;
                 default:
                     $objMapping[$property] = $_SERVER[$export];
             }
         }
     }
     ObjectUtil::hydrateObject($authModel, $objMapping);
     return $authModel;
 }
Пример #14
0
 /**
  * @param $data
  * @return ExternalUser
  */
 public static function createFromArray(array $data)
 {
     $model = new self();
     foreach ($data as $key => &$value) {
         switch ($key) {
             case 'id':
             case 'contentPartnerId':
             case 'externalUserId':
                 $value = (int) $value;
                 break;
             case 'modified':
             case 'created':
                 if (!$value instanceof DateTime) {
                     $value = new DateTime($value, new DateTimeZone('UTC'));
                 }
                 break;
         }
     }
     if (!isset($data['userIdentifier']) || !$data['userIdentifier']) {
         $data['userIdentifier'] = $data['contentPartnerId'] . ':' . $data['externalUserId'];
     }
     ObjectUtil::hydrateObject($model, $data);
     return $model;
 }
Пример #15
0
 /**
  * @param $result
  * @return FtpUserModel
  */
 public function createFtpUserFromResult($result)
 {
     $result['hostUid'] = (int) Functions::navl($result, 'hostUid');
     $result['created'] = Functions::nadvl($result, 'created', $this->oracle);
     $result['modified'] = Functions::nadvl($result, 'modified', $this->oracle);
     $ftpUser = new FtpUserModel();
     ObjectUtil::hydrateObject($ftpUser, $result);
     return $ftpUser;
 }
Пример #16
0
 /**
  * @param array $data
  * @return static
  */
 public static function createFromData(array $data)
 {
     $model = new static();
     ObjectUtil::hydrateObject($model, $data);
     return $model;
 }
Пример #17
0
 /**
  * @param $login
  * @param $isMasterAccount
  * @param $remoteAddress
  * @return null|Model\Session
  */
 private function recoverSession($login, $isMasterAccount, $remoteAddress)
 {
     $sql = '
         SELECT
             ses.USR_ID as "uid",
             ses.SES_MNUMBER as "sid",
             ses.SES_FLAGS as "flags",
             um.USR_LOGIN as "login"
         FROM VIDEKOMASTER.SESSIONS ses
         INNER JOIN VIDEKOMASTER.USER_MASTER um on (um.USR_ID = ses.USR_ID)
         WHERE um.USR_LOGIN = :LOGIN
           AND ses.SES_IP = :REMOTE_ADDRESS
           AND ses.SET_TP = 200
           AND ses.SES_FLAGS = :IS_MASTER_ACCOUNT
     ';
     $query = $this->oracle->query($sql)->bindString('LOGIN', $login)->bindString('REMOTE_ADDRESS', $remoteAddress)->bindInt('IS_MASTER_ACCOUNT', (int) $isMasterAccount);
     $result = $query->fetchRow();
     if (!$result) {
         return null;
     }
     $session = new Model\Session();
     $result['uid'] = (int) $result['uid'];
     $result['flags'] = (int) $result['flags'];
     ObjectUtil::hydrateObject($session, $result);
     return $session;
 }
Пример #18
0
 /**
 * @param array $data
 *
 *@return SessionDeprecated
 */
 public static function createFromArray(array $data)
 {
     $authAccount = new self();
     foreach ($data as $key => &$value) {
         switch ($key) {
             case 'uid':
                 $value = (int) $value;
                 break;
             case 'active':
                 $value = (bool) $value;
                 break;
             case 'validFrom':
             case 'validUntil':
                 if (is_string($value)) {
                     $value = new DateTime($value);
                 }
         }
     }
     ObjectUtil::hydrateObject($authAccount, $data);
     return $authAccount;
 }
Пример #19
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  * which is a value of any type other than a resource.
  */
 function jsonSerialize()
 {
     return ObjectUtil::getObjectVars($this);
 }
Пример #20
0
 /**
 * @param $sessionIdentifier
 *
 *@return SessionDeprecated|null
 */
 public function getHistorySession($sid)
 {
     if (!isset($this->session[$sid])) {
         $this->historySession[$sid] = $this->dataProvider->getHistorySessionFromRedis($sid);
     }
     if (!isset($this->session[$sid]) || isset($this->session[$sid]) && !$this->session[$sid]) {
         $this->historySession[$sid] = $this->dataProvider->getHistorySessionFromOracle($sid);
         if ($this->historySession[$sid]) {
             $host = $this->userFactory->getHostById($this->historySession[$sid]->getUserId());
             if ($host) {
                 $data = $host->asArray();
                 $data['sid'] = $sid;
                 $data['sessionType'] = SessionTypeEnum::SID_SESSION;
                 ObjectUtil::hydrateObject($this->historySession[$sid], $data);
             }
             $this->dataProvider->setHistorySessionToRedis($sid, $this->historySession[$sid]);
         }
     }
     return isset($this->historySession[$sid]) ? $this->historySession[$sid] : null;
 }
Пример #21
0
 /**
  * @param array $data
  * @return IncomingAMQPEvent
  */
 private function createIncomingAMQPEventFromArray(array $data = [])
 {
     $event = new IncomingAMQPEvent();
     foreach ($data as $key => &$value) {
         switch ($key) {
             case 'triggered':
                 if (is_string($value)) {
                     $value = new DateTime($value);
                 }
                 break;
             case 'userId':
             case 'userType':
             case 'eventType':
                 $value = $value ? (int) $value : null;
                 break;
             case 'eventVars':
                 $value = (array) $value;
                 break;
         }
     }
     ObjectUtil::hydrateObject($event, $data);
     return $event;
 }