2017 © Pedro Peláez
 

library ldap-bundle

LDAP bundle for Symfony 2.1

image

instaclick/ldap-bundle

LDAP bundle for Symfony 2.1

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 102 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

LdapBundle

LdapBundle provides a Ldap authentication system without the apache mod_ldap. It uses php-ldap extension with a form to authenticate the users. LdapBundle also can be used for the authorization. It retrieves the Ldap users' roles., (*1)

Contact

You can try to contact me on freenode irc ; channel #symfony-fr ; pseudo : aways, (*2)

Install

  1. Download LdapBundle
  2. Configure the Autoloader
  3. Enable the Bundle
  4. Configure LdapBundle security.yml
  5. Import LdapBundle security.yml
  6. Import LdapBundle routing
  7. Implement Logout
  8. Subscribe to PRE_BIND event

Get the Bundle

Composer

Modify your composer.json on your project root, (*3)

``` php // {root}/composer.json, (*4)

{ [...], "require": { [...], "imag/ldap-bundle": "dev-master" } }, (*5)


### Enable the Bundle ``` php <?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new IMAG\LdapBundle\IMAGLdapBundle(), ); }

Configure security.yml

``` yaml, (*6)

src/IMAG/LdapBundle/Resources/config/security.yml

security: firewalls: restricted_area: pattern: ^/ anonymous: ~ provider: ldap imag_ldap: ~ # alternative configuration # imag_ldap: # login_path: /ninja/login logout: path: /logout target: /, (*7)

providers: ldap: id: imag_ldap.security.user.provider, (*8)

encoders: IMAG\LdapBundle\User\LdapUser: plaintext, (*9)

access_control: - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, roles: IS_AUTHENTICATED_FULLY }, (*10)

imag_ldap: client: host: your.host.foo port: 389, (*11)

version: 3 # Optional

username: foo # Optional

password: bar # Optional

user: base_dn: ou=people,dc=host,dc=foo, (*12)

filter: (&(foo=bar)(ObjectClass=Person)) #Optional

name_attribute: uid

role: base_dn: ou=group, dc=host, dc=foo, (*13)

filter: (ou=group) #Optional

name_attribute: cn
user_attribute: member
user_id: [ dn or username ]

**You need to configure the parameters under the imag_ldap section.** **Note:** > If are not set, the optional parameters have default values. > You can disable this ; Just set parameter to NULL. ``` yaml imag_ldap: # ... role: # ... filter: NULL

Import security.yml

``` yaml, (*14)

app/config/config.yml

imports: - { resource: ../../src/IMAG/LdapBundle/Resources/config/security.yml }, (*15)


### Import routing ``` yaml # app/config/routing.yml imag_ldap: resource: "@IMAGLdapBundle/Resources/config/routing.yml"

Implement Logout

Just create a link with logout target., (*16)

``` html logout, (*17)


**Note:** You can refer to the official Symfony documentation : http://symfony.com/doc/2.0/book/security.html#logging-out ### Subscribe to PRE_BIND event Now you can perform you own logic before the user is authenticated on Ldap. If you want to break the authentication just return an Exception. To subscribe: ``` xml <tag name="kernel.event_listener" event="imag_ldap.security.authentication.pre_bind" method="onPreBind" />

Exemple: ``` php <?php use IMAG\LdapBundle\Event\LdapUserEvent,, (*18)

public function onPreBind(LdapUserEvent $event) { $user = $event->getUser(); $config = $this->appContext->getConfig();, (*19)

$ldapConf = $config['ldap'];

if (!in_array($user->getUsername(), $ldapConf['allowed'])) {
    throw new \Exception('Not allowed ldap user');
}

$user->addRole('ROLE_LDAP');

} ```, (*20)

The Versions

30/07 2012

dev-develop

dev-develop http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

The Requires