/** * Loads ACL annotations from PHP files * * @param AclAnnotationStorage $storage */ public function load(AclAnnotationStorage $storage) { $configLoader = OroSecurityExtension::getAclAnnotationLoader(); $resources = $configLoader->load(); foreach ($resources as $resource) { foreach ($resource->data as $file) { $className = $this->getClassName($file); if ($className !== null) { $reflection = $this->getReflectionClass($className); // read annotations from class $annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName()); } else { $ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName()); } } // read annotations from methods foreach ($reflection->getMethods() as $reflectionMethod) { $annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName(), $reflectionMethod->getName()); } else { $ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName()); } } } } } } }
public function testSerialization() { $storage = new AclAnnotationStorage(); $storage->add(new AclAnnotation(['id' => 'annotation', 'type' => 'entity']), 'Acme\\SomeClass', 'SomeMethod'); $this->assertEquals('annotation', $storage->findById('annotation')->getId()); $this->assertEquals('annotation', $storage->find('Acme\\SomeClass', 'SomeMethod')->getId()); $data = serialize($storage); $storage = unserialize($data); $this->assertEquals('annotation', $storage->findById('annotation')->getId()); $this->assertEquals('annotation', $storage->find('Acme\\SomeClass', 'SomeMethod')->getId()); }
/** * Loads ACL annotations from config files * * @param AclAnnotationStorage $storage */ public function load(AclAnnotationStorage $storage) { $configLoader = OroSecurityExtension::getAclConfigLoader(); $resources = $configLoader->load(); foreach ($resources as $resource) { foreach ($resource->data as $id => $data) { $data['id'] = $id; $storage->add(new AclAnnotation($data)); if (isset($data['bindings'])) { foreach ($data['bindings'] as $binding) { $storage->addBinding($id, isset($binding['class']) ? $binding['class'] : null, isset($binding['method']) ? $binding['method'] : null); } } } } }
/** * Loads ACL annotations from PHP files * * @param AclAnnotationStorage $storage */ public function load(AclAnnotationStorage $storage) { if (!empty($this->subDirs)) { $directories = []; foreach ($this->bundleDirectories as $bundleDir) { foreach ($this->subDirs as $subDir) { $dir = $bundleDir . DIRECTORY_SEPARATOR . $subDir; if (is_dir($dir)) { $directories[] = $dir; } } } } else { $directories = $this->bundleDirectories; } $files = $this->findFiles('*.php', $directories); foreach ($files as $file) { $className = $this->getClassName($file); if ($className !== null) { $reflection = $this->getReflectionClass($className); // read annotations from class $annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName()); } else { $ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName()); } } // read annotations from methods foreach ($reflection->getMethods() as $reflectionMethod) { $annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS); if ($annotation) { $storage->add($annotation, $reflection->getName(), $reflectionMethod->getName()); } else { $ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS); if ($ancestor) { $storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName()); } } } } } }
/** * Loads ACL annotations from YAML config files * * @param AclAnnotationStorage $storage */ public function load(AclAnnotationStorage $storage) { foreach ($this->bundleDirectories as $bundleDir) { $file = $bundleDir . '/Resources/config/acl.yml'; if (is_file($file)) { $config = Yaml::parse(realpath($file)); foreach ($config as $id => $data) { $data['id'] = $id; $storage->add(new AclAnnotation($data)); if (isset($data['bindings'])) { foreach ($data['bindings'] as $binding) { $storage->addBinding($id, isset($binding['class']) ? $binding['class'] : null, isset($binding['method']) ? $binding['method'] : null); } } } } } }
/** * Checks whether the given method of the given class is protected by ACL security policy * * @param string $class * @param string $method * @return bool true if the method is protected; otherwise, false */ public function isProtectedMethod($class, $method) { $this->ensureAnnotationsLoaded(); return $this->storage->isKnownMethod($class, $method); }