/**
  * {@inheritDoc}
  *
  * @return \Zend\Mvc\Controller\Plugin\Identity
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     $helper = new Identity();
     if ($services->has('Zend\\Authentication\\AuthenticationService')) {
         $helper->setAuthenticationService($services->get('Zend\\Authentication\\AuthenticationService'));
     }
     return $helper;
 }
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return Identity
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var PluginManager $serviceLocator */
     $serviceLocator = $serviceLocator->getServiceLocator();
     $authentication = $serviceLocator->get(AuthenticationService::class);
     $identity = new Identity();
     $identity->setAuthenticationService($authentication);
     return $identity;
 }
Пример #3
0
 /**
  * Constructor
  *
  * After invoking parent constructor, add an initializer to inject the
  * attached controller, if any, to the currently requested plugin.
  *
  * @param null|ConfigInterface $configuration
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->setFactory('identity', function ($plugins) {
         $services = $plugins->getServiceLocator();
         $plugin = new Plugin\Identity();
         if (!$services->has('Zend\\Authentication\\AuthenticationService')) {
             return $plugin;
         }
         $plugin->setAuthenticationService($services->get('Zend\\Authentication\\AuthenticationService'));
         return $plugin;
     });
 }
Пример #4
0
 public function testGetIdentity()
 {
     $identity = new TestAsset\IdentityObject();
     $identity->setUsername('a username');
     $identity->setPassword('a password');
     $authenticationService = new AuthenticationService(new NonPersistentStorage(), new TestAsset\AuthenticationAdapter());
     $identityPlugin = new IdentityPlugin();
     $identityPlugin->setAuthenticationService($authenticationService);
     $this->assertNull($identityPlugin());
     $this->assertFalse($authenticationService->hasIdentity());
     $authenticationService->getAdapter()->setIdentity($identity);
     $result = $authenticationService->authenticate();
     $this->assertTrue($result->isValid());
     $this->assertEquals($identity, $identityPlugin());
 }
 /**
  * Fetches the entity from the database
  * @return  object|null
  */
 public function __invoke()
 {
     //check whether the entity has alrady been fetched
     if (!is_null($this->entity)) {
         return $this->entity;
     }
     //get the identity
     $identity = parent::__invoke();
     //check the entity is not null
     if (is_null($identity)) {
         return null;
     }
     //fetch the identity object
     $sm = $this->getServiceLocator()->getServiceLocator();
     $options = $sm->get('deit_authentication_options');
     $callback = $options->getFetchEntityFromIdentityCallback();
     if (is_null($callback)) {
         $this->entity = $identity;
     } else {
         $this->entity = call_user_func_array($callback, array($identity, $sm));
     }
     return $this->entity;
 }