public function testClearCache()
 {
     $this->cache->expects($this->once())->method('delete')->with('SomeType');
     $this->cache->expects($this->once())->method('deleteAll');
     $provider = new Provider($this->securityConfigProvider, $this->entityConfigProvider, $this->cache);
     $provider->clearCache('SomeType');
     $provider->clearCache();
 }
 /**
  * @param PersistConfigEvent $event
  */
 public function prePersistEntityConfig(PersistConfigEvent $event)
 {
     $cp = $event->getConfigManager()->getProvider('security');
     $className = $event->getConfig()->getId()->getClassName();
     if ($cp->hasConfig($className)) {
         $config = $cp->getConfig($className);
         $this->provider->clearCache($config->get('type'));
     }
 }
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     if ($event->isFieldConfig()) {
         return;
     }
     $className = $event->getClassName();
     $configProvider = $event->getConfigManager()->getProvider('security');
     if ($configProvider->hasConfig($className)) {
         $this->provider->clearCache($configProvider->getConfig($className)->get('type'));
     }
 }
 /**
  * Get data for query acl access level check
  * Return null if entity has full access, empty array if user does't have access to the entity
  *  and array with entity field and field values witch user have access.
  *
  * @param $entityClassName
  * @param $permissions
  * @return null|array
  */
 public function getAclConditionData($entityClassName, $permissions = 'VIEW')
 {
     if ($this->aclVoter === null || !$this->getUserId() || !$this->entityMetadataProvider->isProtectedEntity($entityClassName)) {
         return [];
     }
     $condition = null;
     $observer = new OneShotIsGrantedObserver();
     $this->aclVoter->addOneShotIsGrantedObserver($observer);
     $isGranted = $this->getSecurityContext()->isGranted($permissions, 'entity:' . $entityClassName);
     if ($isGranted) {
         $condition = $this->buildConstraintIfAccessIsGranted($entityClassName, $observer->getAccessLevel(), $this->metadataProvider->getMetadata($entityClassName));
     }
     return $condition;
 }
 /**
  * Get data for query acl access level check
  *
  * @param $entityClassName
  * @param $permissions
  *
  * @return array Returns empty array if entity has full access,
  *               array with null values if user does't have access to the entity
  *               and array with entity field and field values which user has access to.
  *               Array structure:
  *               0 - owner field name
  *               1 - owner values
  *               2 - owner association type
  *               3 - organization field name
  *               4 - organization values
  *               5 - should owners be checked
  *                  (for example, in case of Organization ownership type, owners should not be checked)
  */
 public function getAclConditionData($entityClassName, $permissions = 'VIEW')
 {
     if ($this->aclVoter === null || !$this->getUserId() || !$this->entityMetadataProvider->isProtectedEntity($entityClassName)) {
         // return full access to the entity
         return [];
     }
     $observer = new OneShotIsGrantedObserver();
     $this->aclVoter->addOneShotIsGrantedObserver($observer);
     $groupedEntityClassName = $entityClassName;
     if ($this->aclGroupProvider) {
         $group = $this->aclGroupProvider->getGroup();
         if ($group) {
             $groupedEntityClassName = sprintf('%s@%s', $this->aclGroupProvider->getGroup(), $entityClassName);
         }
     }
     $isGranted = $this->getSecurityContext()->isGranted($permissions, new ObjectIdentity('entity', $groupedEntityClassName));
     if ($isGranted) {
         $condition = $this->buildConstraintIfAccessIsGranted($entityClassName, $observer->getAccessLevel(), $this->metadataProvider->getMetadata($entityClassName));
     } else {
         $condition = $this->getAccessDeniedCondition();
     }
     return $condition;
 }
 /**
  * Checks whether an entity is protected.
  *
  * @param  string $entityClass
  * @return bool
  */
 public function isProtectedEntity($entityClass)
 {
     return $this->entitySecurityMetadataProvider->isProtectedEntity($entityClass);
 }
 /**
  * {@inheritdoc}
  */
 public function getClasses()
 {
     return $this->entityMetadataProvider->getEntities();
 }
 /**
  * {inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $this->provider->warmUpCache();
 }
 /**
  * {inheritdoc}
  */
 public function clear($cacheDir)
 {
     $this->provider->clearCache();
 }