2017 © Pedro Peláez
 

cakephp-plugin cakephp-ldap-utility

Cakephp-ldap-utility plugin for CakePHP

image

arvindh93/cakephp-ldap-utility

Cakephp-ldap-utility plugin for CakePHP

  • Sunday, March 4, 2018
  • by arvindh93
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Cakephp-ldap-auth plugin for CakePHP

Requirements

  • CakePHP 3.1+

Installation

You can install this plugin into your CakePHP application using composer., (*1)

The recommended way to install composer packages is:, (*2)

composer require arvindh93/Cakephp-ldap

Usage

In your app's config/bootstrap.php add:, (*3)

// In config/bootstrap.php
Plugin::load('LdapUtility');

or using cake's console:, (*4)

./bin/cake plugin load LdapUtility

Configuration:

Basic configuration for creating ldap handler instance, (*5)

    $config = [
        'host' => 'ldap.example.com',
        'port' => 389,
        'baseDn' => 'dc=example,dc=com',
        'startTLS' => true,
        'hideErrors' => true,
        'commonBindDn' => 'cn=readonly.user,ou=people,dc=example,dc=com',
        'commonBindPassword' => 'secret'
    ]
    $ldapHandler = new LdapUtility\Ldap($config);

Setup Ldap authentication config in Controller, (*6)

    // In your controller, for e.g. src/Api/AppController.php
    public function initialize()
    {
        parent::initialize();

        $this->loadComponent('Auth', [
            'storage' => 'Memory',
            'authenticate', [
                'LdapUtility.Ldap' => [
                    'host' => 'ldap.example.com',
                    'port' => 389,
                    'baseDn' => 'dc=example,dc=com',
                    'startTLS' => true,
                    'hideErrors' => true,
                    'commonBindDn' => 'cn=readonly.user,ou=people,dc=example,dc=com',
                    'commonBindPassword' => 'secret',
                    'fields' => [
                        'username' => 'cn',
                        'suffix' => 'ou=people,dc=test,dc=com'
                    ]
                ]
            ],

            'unauthorizedRedirect' => false,
            'checkAuthIn' => 'Controller.initialize',
        ]);
    }

Usage:

Creating Query object for Search/Read operation:

Search - $ldapHandler->search() Read - $ldapHandler->read(), (*7)

Operations on query object:

select() - accepts an array of attributes to fetch from ldap entry
setBaseDn() - accepts baseDn string defaults to config - baseDn
where() - accepts filter string
first() - execute the query and get the first entry details as array
all() - executes the query and get all the possible entries as array

Example:

Search for entry with cn starting with test, (*8)

    $ldapHandler->search()
        ->setBaseDn('ou=people,dc=example,dc=com')
        ->select(['cn', 'sn', 'mail'])
        ->where('cn=test*')
        ->all()

Search for entry with cn starting with test and get first entry, (*9)

    $ldapHandler->search()
        ->setBaseDn('ou=people,dc=example,dc=com')
        ->select(['cn', 'sn', 'mail'])
        ->where('cn=test*')
        ->first()

Read a particular entry with cn=test.user, (*10)

    $ldapHandler->read()
        ->setBaseDn('cn=test.user,ou=people,dc=example,dc=com')
        ->select(['cn', 'sn', 'mail'])
        ->where('cn=test.user')
        ->first()

The Versions

04/03 2018

dev-master

9999999-dev

Cakephp-ldap-utility plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

21/02 2018

v1.0

1.0.0.0

Cakephp-ldap-utility plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires