mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-08 18:49:26 +03:00
Merge pull request #206 from dothiv/master
Show authorized roles in key icon tooltip
This commit is contained in:
commit
87328e27f5
@ -115,6 +115,11 @@ class ApiDoc
|
|||||||
*/
|
*/
|
||||||
private $authentication = false;
|
private $authentication = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $authenticationRoles = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
@ -200,6 +205,12 @@ class ApiDoc
|
|||||||
$this->setAuthentication((bool) $data['authentication']);
|
$this->setAuthentication((bool) $data['authentication']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($data['authenticationRoles'])) {
|
||||||
|
foreach ($data['authenticationRoles'] as $key => $role) {
|
||||||
|
$this->authenticationRoles[] = $role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($data['cache'])) {
|
if (isset($data['cache'])) {
|
||||||
$this->setCache($data['cache']);
|
$this->setCache($data['cache']);
|
||||||
}
|
}
|
||||||
@ -436,6 +447,22 @@ class ApiDoc
|
|||||||
$this->authentication = $authentication;
|
$this->authentication = $authentication;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAuthenticationRoles()
|
||||||
|
{
|
||||||
|
return $this->authenticationRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $authenticationRoles
|
||||||
|
*/
|
||||||
|
public function setAuthenticationRoles($authenticationRoles)
|
||||||
|
{
|
||||||
|
$this->authenticationRoles = $authenticationRoles;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
@ -542,6 +569,7 @@ class ApiDoc
|
|||||||
|
|
||||||
$data['https'] = $this->https;
|
$data['https'] = $this->https;
|
||||||
$data['authentication'] = $this->authentication;
|
$data['authentication'] = $this->authentication;
|
||||||
|
$data['authenticationRoles'] = $this->authenticationRoles;
|
||||||
$data['deprecated'] = $this->deprecated;
|
$data['deprecated'] = $this->deprecated;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -22,8 +22,11 @@ class JmsSecurityExtraHandler implements HandlerInterface
|
|||||||
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
|
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
|
||||||
{
|
{
|
||||||
foreach ($annotations as $annot) {
|
foreach ($annotations as $annot) {
|
||||||
if ($annot instanceof Secure || $annot instanceof PreAuthorize) {
|
if ($annot instanceof PreAuthorize) {
|
||||||
$annotation->setAuthentication(true);
|
$annotation->setAuthentication(true);
|
||||||
|
} else if ($annot instanceof Secure) {
|
||||||
|
$annotation->setAuthentication(true);
|
||||||
|
$annotation->setAuthenticationRoles(is_array($annot->roles) ? $annot->roles : explode(',', $annot->roles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ Also bundle will get information from the other annotations:
|
|||||||
|
|
||||||
* @FOS\RestBundle\Controller\Annotations\QueryParam - use as `requirements` (when strict parameter is true), `filters` (when strict is false)
|
* @FOS\RestBundle\Controller\Annotations\QueryParam - use as `requirements` (when strict parameter is true), `filters` (when strict is false)
|
||||||
|
|
||||||
* @JMS\SecurityExtraBundle\Annotation\Secure - set `authentification` to true
|
* @JMS\SecurityExtraBundle\Annotation\Secure - set `authentification` to true, `authenticationRoles` to the given roles
|
||||||
|
|
||||||
* @Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache - set `cache`
|
* @Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache - set `cache`
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<span class="icon lock" title="HTTPS"></span>
|
<span class="icon lock" title="HTTPS"></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if data.authentication %}
|
{% if data.authentication %}
|
||||||
<span class="icon keys" title="Needs authentication"></span>
|
<span class="icon keys" title="Needs {{ data.authenticationRoles|length > 0 ? data.authenticationRoles|join(', ') : 'authentication' }}"></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<span class="path">
|
<span class="path">
|
||||||
|
@ -32,6 +32,7 @@ class ApiDocTest extends TestCase
|
|||||||
$this->assertFalse(isset($array['parameters']));
|
$this->assertFalse(isset($array['parameters']));
|
||||||
$this->assertNull($annot->getInput());
|
$this->assertNull($annot->getInput());
|
||||||
$this->assertFalse($array['authentication']);
|
$this->assertFalse($array['authentication']);
|
||||||
|
$this->assertTrue(is_array($array['authenticationRoles']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConstructWithInvalidData()
|
public function testConstructWithInvalidData()
|
||||||
|
@ -186,6 +186,9 @@ class ApiDocExtractorTest extends WebTestCase
|
|||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$annotation->getAuthentication()
|
$annotation->getAuthentication()
|
||||||
);
|
);
|
||||||
|
$this->assertContains('ROLE_USER', $annotation->getAuthenticationRoles());
|
||||||
|
$this->assertContains('ROLE_FOOBAR', $annotation->getAuthenticationRoles());
|
||||||
|
$this->assertCount(2, $annotation->getAuthenticationRoles());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetWithCache()
|
public function testGetWithCache()
|
||||||
|
@ -167,7 +167,8 @@ class TestController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ApiDoc(
|
* @ApiDoc(
|
||||||
* authentication=true
|
* authentication=true,
|
||||||
|
* authenticationRoles={"ROLE_USER","ROLE_FOOBAR"}
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function authenticatedAction()
|
public function authenticatedAction()
|
||||||
|
@ -60,6 +60,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
1 =>
|
1 =>
|
||||||
@ -94,6 +95,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
2 =>
|
2 =>
|
||||||
@ -134,6 +136,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
3 =>
|
3 =>
|
||||||
@ -174,6 +177,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -196,6 +200,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
1 =>
|
1 =>
|
||||||
@ -205,6 +210,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'description' => 'Action without HTTP verb',
|
'description' => 'Action without HTTP verb',
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
2 =>
|
2 =>
|
||||||
@ -223,6 +229,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
3 =>
|
3 =>
|
||||||
@ -231,6 +238,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'uri' => '/authenticated',
|
'uri' => '/authenticated',
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => true,
|
'authentication' => true,
|
||||||
|
'authenticationRoles' => array('ROLE_USER','ROLE_FOOBAR'),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
4 =>
|
4 =>
|
||||||
@ -431,6 +439,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
5 =>
|
5 =>
|
||||||
@ -450,6 +459,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
6 =>
|
6 =>
|
||||||
@ -490,6 +500,7 @@ And, it supports multilines until the first \'@\' char.',
|
|||||||
'description' => 'This method is useful to test if the getDocComment works.',
|
'description' => 'This method is useful to test if the getDocComment works.',
|
||||||
'documentation' => "This method is useful to test if the getDocComment works.\nAnd, it supports multilines until the first '@' char.",
|
'documentation' => "This method is useful to test if the getDocComment works.\nAnd, it supports multilines until the first '@' char.",
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
7 =>
|
7 =>
|
||||||
@ -498,6 +509,7 @@ And, it supports multilines until the first \'@\' char.',
|
|||||||
'uri' => '/return-nested-output',
|
'uri' => '/return-nested-output',
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
'response' =>
|
'response' =>
|
||||||
array (
|
array (
|
||||||
@ -706,6 +718,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => true,
|
'https' => true,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
9 =>
|
9 =>
|
||||||
@ -723,6 +736,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
10 =>
|
10 =>
|
||||||
@ -731,6 +745,7 @@ With multiple lines.',
|
|||||||
'uri' => '/z-action-with-deprecated-indicator',
|
'uri' => '/z-action-with-deprecated-indicator',
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => true,
|
'deprecated' => true,
|
||||||
),
|
),
|
||||||
11 =>
|
11 =>
|
||||||
@ -748,6 +763,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
12 =>
|
12 =>
|
||||||
@ -764,6 +780,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
13 =>
|
13 =>
|
||||||
@ -781,6 +798,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
14 =>
|
14 =>
|
||||||
@ -799,6 +817,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -820,6 +839,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -841,6 +861,7 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
|
'authenticationRoles' => array(),
|
||||||
'deprecated' => false,
|
'deprecated' => false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -889,7 +910,8 @@ With multiple lines.',
|
|||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
'authentication' => false,
|
'authentication' => false,
|
||||||
'deprecated' => false,
|
'authenticationRoles' => array(),
|
||||||
|
'deprecated' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user