public static function init() { self::$config = FileCache::get('config'); if (!self::$config) { self::loadXml($_SERVER['DOCUMENT_ROOT'] . '/' . Config::configPath()); } }
/** * Checks and updates the "client_token" and cache if we have a valid one * If we don not have a Client Token in session, we check if we have a cookie * If we don not have a client Token in session or in a cookie, We request a new Client Token. * This method set the Client Token in Things * * @return void * @throws \Exception */ private static function checkAndUpdateClientToken() { try { self::$logger->debug('Checking and update client_token.'); if (!($client_token = unserialize(FileCache::get('client_token'))) instanceof ClientToken || $client_token->getValue() == '') { self::$logger->debug('Get Client token'); if (self::$gid_things->getClientToken() == null || OAuth::getStoredToken(iTokenTypes::CLIENT_TOKEN) == null) { self::$logger->debug('Not has clientToken in session or cookie'); if (!($client_token = OAuth::getStoredToken(iTokenTypes::CLIENT_TOKEN))) { self::$logger->debug('Token Cookie does not exists. Requesting a new one.'); $client_token = OAuth::doGetClientToken(OauthConfig::getEndpointUrl('token_endpoint')); } self::$gid_things->setClientToken($client_token); } else { self::$logger->debug('Client Token from session'); } FileCache::set('client_token', serialize(self::$gid_things->getClientToken()), self::$gid_things->getClientToken()->getExpiresIn()); } else { self::$logger->debug('Client Token from cache'); self::$gid_things->setClientToken($client_token); } } catch (Exception $e) { throw $e; } }
/** * Returns the user data stored trough the Genetsis ID personal identifier. * The identifiers could be: id (ckusid), screenName, email, dni * Sample: array('id'=>'XXXX','screenName'=>'xxxx'); * * @param array The Genetsis IDs identifier to search, 'identifier' => 'value' * @return array A vector of {@link User} objects with user's * personal data. The array could be empty. * @throws /Exception */ public static function getUsers($identifiers) { $druid_user = array(); if (is_array($identifiers)) { try { if (!($druid_user_data = FileCache::get('user-' . reset($identifiers)))) { Identity::getLogger()->debug('Identifier: ' . reset($identifiers) . ' is Not in Cache System'); $client_token = Identity::getThings()->getClientToken(); if (is_null($client_token)) { throw new Exception('The clientToken is empty'); } /** * Parameters: * oauth_token: client token * s (select): dynamic user data to be returned * f (from): User * w (where): param with OR w.param1&w.param2... */ $params = array(); $params['oauth_token'] = $client_token->getValue(); $params['s'] = "*"; $params['f'] = "User"; foreach ($identifiers as $key => $val) { $params['w.' . $key] = $val; } $base = OAuthConfig::getApiUrl('api.user', 'base_url'); $api = OAuthConfig::getApiUrl('api.user', 'user'); $response = Request::execute($base . $api, $params, Request::HTTP_POST); if ($response['code'] != 200 || !isset($response['result']->data) || $response['result']->count == '0') { throw new Exception('The data retrieved is empty'); } $druid_user = $response['result']->data; FileCache::set('user-' . reset($identifiers), $druid_user, self::USER_TTL); } else { Identity::getLogger()->debug('Identifier: ' . reset($identifiers) . ' is in Cache System'); $druid_user = json_decode(json_encode($druid_user_data)); } } catch (Exception $e) { Identity::getLogger()->error($e->getMessage()); } } return $druid_user; }