芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/vision.mgaplay.com.br/lib/Entity/Application.php
setCommonDependencies($store, $log); $this->applicationRedirectUriFactory = $applicationRedirectUriFactory; $this->applicationScopeFactory = $applicationScopeFactory; } /** * @param ApplicationRedirectUri $redirectUri */ public function assignRedirectUri($redirectUri) { $this->load(); // Assert client id $redirectUri->clientId = $this->key; if (!in_array($redirectUri, $this->redirectUris)) $this->redirectUris[] = $redirectUri; } /** * Unassign RedirectUri * @param ApplicationRedirectUri $redirectUri */ public function unassignRedirectUri($redirectUri) { $this->load(); $this->redirectUris = array_udiff($this->redirectUris, [$redirectUri], function($a, $b) { /** * @var ApplicationRedirectUri $a * @var ApplicationRedirectUri $b */ return $a->getId() - $b->getId(); }); } /** * @param ApplicationScope $scope */ public function assignScope($scope) { $this->load(); if (!in_array($scope, $this->scopes)) $this->scopes[] = $scope; } /** * @param ApplicationScope $scope */ public function unassignScope($scope) { $this->load(); $this->scopes = array_udiff($this->scopes, [$scope], function($a, $b) { /** * @var ApplicationScope $a * @var ApplicationScope $b */ return $a->getId() - $b->getId(); }); } /** * Load */ public function load() { if ($this->loaded) return; $this->redirectUris = $this->applicationRedirectUriFactory->getByClientId($this->key); // Get scopes $this->scopes = $this->applicationScopeFactory->getByClientId($this->key); $this->loaded = true; } public function save() { if ($this->key == null || $this->key == '') $this->add(); else $this->edit(); $this->getLog()->debug('Saving redirect uris: %s', json_encode($this->redirectUris)); foreach ($this->redirectUris as $redirectUri) { /* @var \Xibo\Entity\ApplicationRedirectUri $redirectUri */ $redirectUri->save(); } $this->manageScopeAssignments(); } public function delete() { $this->load(); foreach ($this->redirectUris as $redirectUri) { /* @var \Xibo\Entity\ApplicationRedirectUri $redirectUri */ $redirectUri->delete(); } // Clear out everything owned by this client $this->deleteTokens(); $this->getStore()->update('DELETE FROM `oauth_session_scopes` WHERE id IN (SELECT session_id FROM `oauth_sessions` WHERE `client_id` = :id)', ['id' => $this->key]); $this->getStore()->update('DELETE FROM `oauth_sessions` WHERE `client_id` = :id', ['id' => $this->key]); $this->getStore()->update('DELETE FROM `oauth_client_scopes` WHERE `clientId` = :id', ['id' => $this->key]); $this->getStore()->update('DELETE FROM `oauth_clients` WHERE `id` = :id', ['id' => $this->key]); } public function resetKeys() { $this->secret = SecureKey::generate(254); $this->deleteTokens(); } private function deleteTokens() { $this->getStore()->update('DELETE FROM `oauth_access_token_scopes` WHERE access_token IN (SELECT access_token FROM `oauth_access_tokens` WHERE session_id IN (SELECT session_id FROM `oauth_sessions` WHERE `client_id` = :id))', ['id' => $this->key]); $this->getStore()->update('DELETE FROM `oauth_refresh_tokens` WHERE access_token IN (SELECT access_token FROM `oauth_access_tokens` WHERE session_id IN (SELECT session_id FROM `oauth_sessions` WHERE `client_id` = :id))', ['id' => $this->key]); $this->getStore()->update('DELETE FROM `oauth_access_tokens` WHERE session_id IN (SELECT session_id FROM `oauth_sessions` WHERE `client_id` = :id)', ['id' => $this->key]); $this->getStore()->update('DELETE FROM `oauth_auth_code_scopes` WHERE auth_code IN (SELECT auth_code FROM `oauth_auth_codes` WHERE session_id IN (SELECT session_id FROM `oauth_sessions` WHERE `client_id` = :id))', ['id' => $this->key]); $this->getStore()->update('DELETE FROM `oauth_auth_codes` WHERE session_id IN (SELECT session_id FROM `oauth_sessions` WHERE `client_id` = :id)', ['id' => $this->key]); } private function add() { $this->key = SecureKey::generate(); // Simple Insert for now $this->getStore()->insert(' INSERT INTO `oauth_clients` (`id`, `secret`, `name`, `userId`, `authCode`, `clientCredentials`) VALUES (:id, :secret, :name, :userId, :authCode, :clientCredentials) ', [ 'id' => $this->key, 'secret' => $this->secret, 'name' => $this->name, 'userId' => $this->userId, 'authCode' => $this->authCode, 'clientCredentials' => $this->clientCredentials ]); } private function edit() { $this->getStore()->update(' UPDATE `oauth_clients` SET `id` = :id, `secret` = :secret, `name` = :name, `userId` = :userId, `authCode` = :authCode, `clientCredentials` = :clientCredentials WHERE `id` = :id ', [ 'id' => $this->key, 'secret' => $this->secret, 'name' => $this->name, 'userId' => $this->userId, 'authCode' => $this->authCode, 'clientCredentials' => $this->clientCredentials ]); } /** * Compare the original assignments with the current assignments and delete any that are missing, add any new ones */ private function manageScopeAssignments() { $i = 0; $params = ['clientId' => $this->key]; $unassignIn = ''; foreach ($this->scopes as $link) { $this->getStore()->update(' INSERT INTO `oauth_client_scopes` (clientId, scopeId) VALUES (:clientId, :scopeId) ON DUPLICATE KEY UPDATE scopeId = scopeId', [ 'clientId' => $this->key, 'scopeId' => $link->id ]); $i++; $unassignIn .= ',:scopeId' . $i; $params['scopeId' . $i] = $link->id; } // Unlink any NOT in the collection $sql = 'DELETE FROM `oauth_client_scopes` WHERE clientId = :clientId AND scopeId NOT IN (\'0\'' . $unassignIn . ')'; $this->getStore()->update($sql, $params); } }