armenio / armenio-zf2-restrictaccess-module
Restrict Access (Database|Ldap) Module for Zend Framework 2
1.0.17
2016-06-21 17:21 UTC
Requires
README
The Restrict Access Module for Zend Framework 2
How to install
-
Install via composer. Don't know how? Look here
-
cd my/project/directory
-
Edit composer.json :
{ "require": { "armenio/armenio-zf2-restrictaccess-module": "1.*" } }
-
Edit config/application.config.php :
'modules' => array( 'Application', 'RestrictAccess', //<============================== )
-
Edit module/config/module.config.php
'service_manager' => array( 'factories' => array( 'AuthenticationService' => function(\Zend\ServiceManager\ServiceManager $serviceManager) { $service = new \RestrictAccess\Service\Authentication\DbTableService(); // $service = new \RestrictAccess\Service\Authentication\LdapService(); $service->setServiceManager($serviceManager); return $service; } ), ),
-
Usage inside Controllers
6.1 Use with Zend\Db
$username = $data['username']; $password = $data['password']; $authService = $this->getServiceLocator()->get('AuthenticationService'); $authService->setNamespace('Default'); $authService->setTableName('users'); $authService->setIdentityColumn('username'); $authService->setCredentialColumn('password'); $authenticationResult = $authService->authenticate($username, $password); if( ! $authenticationResult->isValid() ){ var_dump($authenticationResult->getMessages()); } // else var_dump($authService->getIdentity());
6.2 Use with Zend\Ldap
$username = $post['username']; $password = $post['password']; $ldapOptions = array( 'server1' => array( 'host' => 'dc1.w.net', 'useStartTls' => 'false', 'useSsl' => 'false', 'baseDn' => 'CN=Users,DC=w,DC=net', 'accountCanonicalForm' => 3, 'accountDomainName' => 'w.net', 'accountDomainNameShort' => 'W', ), ); $authService = $this->getServiceLocator()->get('AuthenticationService'); $authService->setNamespace('Default'); $authService->setOptions($ldapOptions); $authenticationResult = $authService->authenticate($username, $password); if( ! $authenticationResult->isValid() ){ var_dump($authenticationResult->getMessages()); } // else var_dump($authService->getIdentity());
-
Getting user identity
if( $authService->hasIdentity() ){ var_dump($authService->getIdentity()); }