/** * @param $requiredPermissions * @param OwnedSecurableItem $ownedSecurableItem * @param User $user * @return bool * @throws AccessDeniedSecurityException */ protected static function resolveAndCheckPermissionsForRead($requiredPermissions, OwnedSecurableItem $ownedSecurableItem, User $user) { try { if (AllPermissionsOptimizationCache::getHasReadPermissionOnSecurableItem($ownedSecurableItem, $user)) { return true; } else { throw new AccessDeniedSecurityException($user, $requiredPermissions, Permission::NONE); } } catch (NotFoundException $e) { try { $hasReadPermission = self::checkPermissionsHasRead($requiredPermissions, $ownedSecurableItem, $user); AllPermissionsOptimizationCache::cacheHasReadPermissionOnSecurableItem($ownedSecurableItem, $user, $hasReadPermission); return $hasReadPermission; } catch (AccessDeniedSecurityException $e) { $hasReadPermission = false; AllPermissionsOptimizationCache::cacheHasReadPermissionOnSecurableItem($ownedSecurableItem, $user, $hasReadPermission); throw new AccessDeniedSecurityException($user, $requiredPermissions, Permission::NONE); } } }
public function testForgetAll() { if (PermissionsCache::supportsAndAllowsMemcache()) { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $account = new Account(); $account->name = 'Ocean Inc2.'; $this->assertTrue($account->save()); $combinedPermissions = 5; // Set some GeneralCache, which should stay in cache after cleanup GeneralCache::cacheEntry('somethingForTesting', 34); $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); AllPermissionsOptimizationCache::cacheHasReadPermissionOnSecurableItem($account, $super, true); $hasReadPermission = AllPermissionsOptimizationCache::getHasReadPermissionOnSecurableItem($account, $super); $this->assertTrue($hasReadPermission); AllPermissionsOptimizationCache::forgetAll(); try { AllPermissionsOptimizationCache::getHasReadPermissionOnSecurableItem($account, $super); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { // Data from generalCache should still be in cache $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); } } // To-Do: Add test for forgetAll with $forgetDbLevelCache = true. It could be added to testForgetAll() function. // To-Do: Add test for forgetSecurableItem with $forgetDbLevelCache = true. . It could be added to testForgetSecurableItem() function. }