Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
Merge a103d30 into 8a28d65
Browse files Browse the repository at this point in the history
  • Loading branch information
svycka committed May 7, 2020
2 parents 8a28d65 + a103d30 commit 450f1b2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
6 changes: 2 additions & 4 deletions docs/07. Cookbook.md
Expand Up @@ -750,10 +750,8 @@ To use the authentication service from ZfcUser, just add the following alias in

```php
return [
'service_manager' => [
'aliases' => [
'Zend\Authentication\AuthenticationService' => 'zfcuser_auth_service'
]
'zfc_rbac' => [
'authentication_service' => 'zfcuser_auth_service'
]
];
```
Expand Down
Expand Up @@ -39,8 +39,10 @@ class AuthenticationIdentityProviderFactory implements FactoryInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */
$moduleOptions = $container->get('ZfcRbac\Options\ModuleOptions');
/* @var \Zend\Authentication\AuthenticationService $authenticationProvider */
$authenticationProvider = $container->get('Zend\Authentication\AuthenticationService');
$authenticationProvider = $container->get($moduleOptions->getAuthenticationService());

return new AuthenticationIdentityProvider($authenticationProvider);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZfcRbac/Factory/RedirectStrategyFactory.php
Expand Up @@ -42,7 +42,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
/* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */
$moduleOptions = $container->get('ZfcRbac\Options\ModuleOptions');
/** @var \Zend\Authentication\AuthenticationService $authenticationService */
$authenticationService = $container->get('Zend\Authentication\AuthenticationService');
$authenticationService = $container->get($moduleOptions->getAuthenticationService());

return new RedirectStrategy($moduleOptions->getRedirectStrategy(), $authenticationService);
}
Expand Down
27 changes: 27 additions & 0 deletions src/ZfcRbac/Options/ModuleOptions.php
Expand Up @@ -86,6 +86,13 @@ class ModuleOptions extends AbstractOptions
*/
protected $redirectStrategy;

/**
* Authentication service name
*
* @var string
*/
protected $authenticationService = 'Zend\Authentication\AuthenticationService';

/**
* Constructor
*
Expand Down Expand Up @@ -284,4 +291,24 @@ public function getRedirectStrategy()

return $this->redirectStrategy;
}

/**
* Get authentication service name
*
* @return string
*/
public function getAuthenticationService()
{
return $this->authenticationService;
}

/**
* Set authentication service name
*
* @param string $authenticationService
*/
public function setAuthenticationService($authenticationService)
{
$this->authenticationService = $authenticationService;
}
}
Expand Up @@ -20,6 +20,7 @@

use Zend\ServiceManager\ServiceManager;
use ZfcRbac\Factory\AuthenticationIdentityProviderFactory;
use ZfcRbac\Options\ModuleOptions;

/**
* @covers \ZfcRbac\Factory\AuthenticationIdentityProviderFactory
Expand All @@ -29,6 +30,7 @@ class AuthenticationIdentityProviderFactoryTest extends \PHPUnit_Framework_TestC
public function testFactory()
{
$serviceManager = new ServiceManager();
$serviceManager->setService('ZfcRbac\Options\ModuleOptions', new ModuleOptions());
$serviceManager->setService(
'Zend\Authentication\AuthenticationService',
$this->getMock('Zend\Authentication\AuthenticationService')
Expand Down
3 changes: 3 additions & 0 deletions tests/ZfcRbacTest/Factory/RedirectStrategyFactoryTest.php
Expand Up @@ -35,6 +35,9 @@ public function testFactory()
$moduleOptionsMock->expects($this->once())
->method('getRedirectStrategy')
->will($this->returnValue($redirectStrategyOptions));
$moduleOptionsMock->expects($this->once())
->method('getAuthenticationService')
->will($this->returnValue('Zend\Authentication\AuthenticationService'));

$authenticationServiceMock = $this->getMock('Zend\Authentication\AuthenticationService');

Expand Down
2 changes: 2 additions & 0 deletions tests/ZfcRbacTest/Options/ModuleOptionsTest.php
Expand Up @@ -44,6 +44,7 @@ public function testAssertModuleDefaultOptions()
public function testSettersAndGetters()
{
$moduleOptions = new ModuleOptions([
'authentication_service' => 'authentication_service_name',
'identity_provider' => 'IdentityProvider',
'guest_role' => 'unknown',
'guards' => [],
Expand All @@ -61,6 +62,7 @@ public function testSettersAndGetters()
]
]);

$this->assertEquals('authentication_service_name', $moduleOptions->getAuthenticationService());
$this->assertEquals('IdentityProvider', $moduleOptions->getIdentityProvider());
$this->assertEquals('unknown', $moduleOptions->getGuestRole());
$this->assertEquals([], $moduleOptions->getGuards());
Expand Down

0 comments on commit 450f1b2

Please sign in to comment.