Permalink
Browse files

Merge pull request #115 from radmar/master

Annotations : array of roles and permissions
  • Loading branch information...
2 parents b0a7ffe + b6572ea commit a136a4beb07beab275aaf8b7cf4d074d2a7f47c1 @schmittjoh committed Feb 18, 2013
View
@@ -37,6 +37,6 @@ public function __construct(array $values)
throw new InvalidArgumentException('"roles" must be defined for RunAs annotation.');
}
- $this->roles = array_map('trim', explode(',', $values['roles']));
+ $this->roles = is_array($values['roles']) ? $values['roles'] : array_map('trim', explode(',', $values['roles']));
}
}
View
@@ -40,6 +40,6 @@ public function __construct(array $values)
throw new InvalidArgumentException('You must define a "roles" attribute for each Secure annotation.');
}
- $this->roles = array_map('trim', explode(',', $values['roles']));
+ $this->roles = is_array($values['roles']) ? $values['roles'] : array_map('trim', explode(',', $values['roles']));
}
}
@@ -43,6 +43,6 @@ public function __construct(array $values)
$this->name = $values['name'];
- $this->permissions = array_map('trim', explode(',', $values['permissions']));
+ $this->permissions = is_array($values['permissions']) ? $values['permissions'] : array_map('trim', explode(',', $values['permissions']));
}
}
@@ -40,6 +40,6 @@ public function __construct(array $values)
throw new InvalidArgumentException('You must define a "permissions" attribute for each SecureReturn annotation.');
}
- $this->permissions = array_map('trim', explode(',', $values['permissions']));
+ $this->permissions = is_array($values['permissions']) ? $values['permissions'] : array_map('trim', explode(',', $values['permissions']));
}
}
@@ -89,7 +89,7 @@ public function testLoadMetadataFromClassWithShortNotation()
$this->assertTrue(isset($metadata->methodMetadata['shortNotation']));
$method = $metadata->methodMetadata['shortNotation'];
$this->assertEquals(array('ROLE_FOO', 'ROLE_BAR'), $method->roles);
- }
+ }
public function testLoadMetadataFromClassDoesNotProcessMethodsForWhichNoSecurityMetadataExists()
{
@@ -99,4 +99,16 @@ public function testLoadMetadataFromClassDoesNotProcessMethodsForWhichNoSecurity
$this->assertTrue(class_exists('JMS\SecurityExtraBundle\Tests\Fixtures\Annotation\NonSecurityAnnotation', false));
$this->assertFalse(isset($metadata->methodMetadata['foo']));
}
+
+ public function testLoadMetadataFromClassWithRolesAndPermissionsArrayNotation()
+ {
+ $driver = new AnnotationDriver(new AnnotationReader());
+
+ $metadata = $driver->loadMetadataForClass(new \ReflectionClass('JMS\SecurityExtraBundle\Tests\Mapping\Driver\FooService'));
+ $this->assertTrue(isset($metadata->methodMetadata['bar']));
+ $method = $metadata->methodMetadata['bar'];
+ $this->assertEquals(array('ROLE_FOO', 'ROLE_BAR'), $method->roles);
+ $this->assertEquals(array(0 => array('OWNER')), $method->paramPermissions);
+ $this->assertEquals(array('MASTER'), $method->returnPermissions);
+ }
}
@@ -34,6 +34,13 @@ public function foo($param, $anotherParam) { }
* @Secure("ROLE_FOO, ROLE_BAR")
*/
public function shortNotation() { }
+
+ /**
+ * @Secure(roles={"ROLE_FOO", "ROLE_BAR"})
+ * @SecureParam(name="param", permissions={"OWNER"})
+ * @SecureReturn(permissions={"MASTER"})
+ */
+ public function bar($param) { }
}
/**
* @SecureParam(name="param", permissions="VIEW")

0 comments on commit a136a4b

Please sign in to comment.