2017 © Pedro Peláez
 

library ldap-bundle

LDAP Bundle for Symfony 3 (backward compatible)

image

svajiraya/ldap-bundle

LDAP Bundle for Symfony 3 (backward compatible)

  • Wednesday, August 23, 2017
  • by svajiraya
  • Repository
  • 3 Watchers
  • 0 Stars
  • 169 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 102 Forks
  • 0 Open issues
  • 16 Versions
  • 15 % Grown

The README.md

Support

Dropping support for symfony versions < 3.0. Recent patches might not be compatible with versions lower than 3.0 since some of the core methods were deprecated and removed from this package., (*1)

LdapBundle

LdapBundle provides LDAP authentication without using Apache's mod_ldap. The bundle instead relies on PHP's LDAP extension along with a form to authenticate users. LdapBundle can also be used for authorization by retrieving the user's roles defined in LDAP., (*2)

Credits

This Bundle was originally created by BorisMorel. Since this bundle is used frequently in almost all our projects, and since the original bundle was not being maintained by anyone we have tried to add our own mods to the project. Anyone is free to use this bundle and modify it as they please. I will try to keep this bundle upto date, but with my busy schedule that may not the case all the time. if you do manage to update the project, please submit a pull request and I would be happy to examine and merge it., (*3)

Install

  1. Download with composer
  2. Enable the Bundle
  3. Configure LdapBundle in security.yml
  4. Import LdapBundle routing
  5. Implement Logout
  6. Use chain provider
  7. Subscribe to PRE_BIND event
  8. Subscribe to POST_BIND event

Get the Bundle

Composer

Add LdapBundle in your project's composer.json, (*4)

{
    "require": {
        "svajiraya/ldap-bundle": "dev-master"
    }
}

or, (*5)

``` shell, (*6)

composer require svajiraya/ldap-bundle, (*7)


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

Configure security.yml

Note:, (*8)

An example security.yml file is located within the bundle at ./Resources/Docs/security.yml, (*9)

``` yaml, (*10)

./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: /, (*11)

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

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

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

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

version: 3 # Optional

username: foo # Optional

password: bar # Optional

network_timeout: 10 # Optional

referrals_enabled: true # Optional

bind_username_before: true # Optional

skip_roles: false # Optional

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

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

name_attribute: uid

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

filter: (ou=group) #Optional

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

user_class: IMAG\LdapBundle\User\LdapUser # Optional


**You should configure the parameters under the `imag_ldap` section to match your environment.** **Note:** > The optional parameters have default values if not set. > You can disable default values by setting a parameter to NULL. ``` yaml # app/config/security.yml imag_ldap: # ... role: # ... filter: NULL

Import routing

``` yaml, (*18)

app/config/routing.yml

imag_ldap: resource: "@IMAGLdapBundle/Resources/config/routing.yml", (*19)


### Implement Logout Just create a link with a logout target. ``` html <a href="{{ path('logout') }}">Logout</a>

Note:, (*20)

You can refer to the official Symfony documentation : http://symfony.com/doc/current/book/security.html#logging-out, (*21)

Chain provider

You can also chain the login form with other providers, such as database_provider, in_memory provider, etc., (*22)

``` yml, (*23)

app/config/security.yml

security: firewalls: secured_area: pattern: ^/ anonymous: ~ imag_ldap: provider: multiples logout: path: logout providers: multiples: chain: providers: [ldap, db]
ldap: id: imag_ldap.security.user.provider db: entity: { class: FQDN\User }, (*24)


**Note:** > If you have set the config option `bind_username_before: true` you must chain the providers with the ldap provider in the last position. ``` yml # app/config/security.yml providers: [db, ldap]

Subscribe to PRE_BIND event

The PRE_BIND is fired before the user is authenticated via LDAP. Here you can write a listener to perform your own logic before the user is bound/authenticated to LDAP. For example, to add your own roles or do other authentication/authorization checks with your application., (*25)

If you want to break the authentication process within your listener, throw an Exception., (*26)

Example listener: ``` xml , (*27)


Example: ```php <?php namespace Acme\HelloBundle\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use IMAG\LdapBundle\Event\LdapUserEvent; /** * Performs logic before the user is found to LDAP */ class LdapSecuritySubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( \IMAG\LdapBundle\Event\LdapEvents::PRE_BIND => 'onPreBind', ); } /** * Modifies the User before binding data from LDAP * * @param \IMAG\LdapBundle\Event\LdapUserEvent $event */ public function onPreBind(LdapUserEvent $event) { $user = $event->getUser(); $config = $this->appContext->getConfig(); $ldapConf = $config['ldap']; if (!in_array($user->getUsername(), $ldapConf['allowed'])) { throw new \Exception(sprintf('LDAP user %s not allowed', $user->getUsername())); } $user->addRole('ROLE_LDAP'); $event->setUser($user); } }

Subscribe to POST_BIND event

The POST_BIND is fired after the user is authenticated via LDAP. You can use it in exactly the same manner as PRE_BIND., (*28)

Note:, (*29)

However each time a page is refreshed, Symfony call the refreshUser method in the provider that is used and doesn't trigger these events (PRE_BIND and POST_BIND). If you want to override user (for example like credentials, roles ...), you must create a new provider and override this method., (*30)

The Versions

23/08 2017

dev-master

9999999-dev http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

23/08 2017

v2.4.7

2.4.7.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

16/08 2017

v2.4.6

2.4.6.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

16/08 2017

v2.4.5

2.4.5.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

15/08 2017

v2.4.4

2.4.4.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

14/08 2017

v2.4.3

2.4.3.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

14/08 2017

v2.4.2

2.4.2.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

23/05 2017

v2.4.1

2.4.1.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

19/03 2017

v2.4.0

2.4.0.0 http://github.com/svajiraya/LdapBundle

LDAP Bundle for Symfony 3 (backward compatible)

  Sources   Download

MIT

The Requires

 

26/02 2014

v2.3.1

2.3.1.0 http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

CeCILL

The Requires

 

12/08 2013

v2.1.6

2.1.6.0 http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

CeCILL

The Requires

 

10/04 2013

v2.1.5

2.1.5.0 http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

CeCILL

The Requires

 

14/03 2013

v2.1.4

2.1.4.0 http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

CeCILL

The Requires

 

07/03 2013

v2.1.3

2.1.3.0 http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

CeCILL

The Requires

 

06/03 2013

v2.1.2

2.1.2.0 http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

CeCILL

The Requires

 

31/07 2012

2.1.0

2.1.0.0 http://github.com/BorisMorel/LdapBundle

LDAP Bundle for Symfony 2

  Sources   Download

The Requires