public function testListsCombinedAuthenticationTypes() { $types = ['foo']; $customTypes = ['bar']; $this->listener->addAuthenticationTypes($customTypes); $adapter = $this->getMockBuilder('ZF\\MvcAuth\\Authentication\\AdapterInterface')->disableOriginalConstructor()->getMock(); $adapter->expects($this->atLeastOnce())->method('provides')->will($this->returnValue($types)); $this->listener->attach($adapter); // Order of merge matters, unfortunately $this->assertEquals(array_merge($customTypes, $types), $this->listener->getAuthenticationTypes()); }
protected function getController($localFile, $globalFile) { $authListener = new AuthListener(); $config = array_merge(require $globalFile, require $localFile); /* Register old authentication adapter types */ if (isset($config['zf-oauth2'])) { $authListener->addAuthenticationTypes(array('oauth2')); } elseif (isset($config['zf-mvc-auth']['authentication']['http'])) { $types = array(); if (isset($config['zf-mvc-auth']['authentication']['http']['htpasswd'])) { $types[] = 'basic'; } if (isset($config['zf-mvc-auth']['authentication']['http']['htdigest'])) { $types[] = 'digest'; } $authListener->addAuthenticationTypes($types); } /* Register v1.1+ adapter types */ if (isset($config['zf-mvc-auth']['authentication']['adapters'])) { foreach ($config['zf-mvc-auth']['authentication']['adapters'] as $adapter => $adapterConfig) { if (! isset ($adapterConfig['adapter'])) { continue; } if (false !== stristr($adapterConfig['adapter'], 'http')) { if (isset($adapterConfig['options']['htpasswd'])) { $authListener->addAuthenticationTypes(array($adapter . '-' . 'basic')); } if (isset($adapterConfig['options']['htdigest'])) { $authListener->addAuthenticationTypes(array($adapter . '-' . 'digest')); } continue; } $authListener->addAuthenticationTypes(array($adapter)); } } return new AuthenticationTypeController($authListener); }
/** * @param ServiceLocatorInterface $services * @return DefaultAuthenticationListener */ public function createService(ServiceLocatorInterface $services) { $listener = new DefaultAuthenticationListener(); $httpAdapter = $this->retrieveHttpAdapter($services); if ($httpAdapter) { $listener->attach($httpAdapter); } $oauth2Server = $this->createOAuth2Server($services); if ($oauth2Server) { $listener->attach($oauth2Server); } $authenticationTypes = $this->getAuthenticationTypes($services); if ($authenticationTypes) { $listener->addAuthenticationTypes($authenticationTypes); } $listener->setAuthMap($this->getAuthenticationMap($services)); return $listener; }
/** * Create and return a DefaultAuthenticationListener. * * @param ContainerInterface $container * @param string $requestedName * @param null|array $options * @return DefaultAuthenticationListener */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $listener = new DefaultAuthenticationListener(); $httpAdapter = $this->retrieveHttpAdapter($container); if ($httpAdapter) { $listener->attach($httpAdapter); } $oauth2Server = $this->createOAuth2Server($container); if ($oauth2Server) { $listener->attach($oauth2Server); } $authenticationTypes = $this->getAuthenticationTypes($container); if ($authenticationTypes) { $listener->addAuthenticationTypes($authenticationTypes); } $listener->setAuthMap($this->getAuthenticationMap($container)); return $listener; }