LDAP Authentication & Management for Laravel
PHP
Latest commit 0b9ffb1 Aug 7, 2018

readme.md

Adldap2 - Laravel

Easy configuration, access, management and authentication to LDAP servers utilizing the root Adldap2 repository.


Index

Requirements

To use Adldap2-Laravel, your application and server must meet the following requirements:

  • Laravel 5.*
  • PHP 7.0 or greater
  • PHP LDAP extension enabled
  • An LDAP Server

Installation

Run the following command in the root of your project:

composer require adldap2/adldap2-laravel

Note: If you are using laravel 5.5 or higher you can skip the service provider and facade registration and continue with publishing the configuration file.

Once finished, insert the service provider in your config/app.php file:

Adldap\Laravel\AdldapServiceProvider::class,

Then insert the facade:

'Adldap' => Adldap\Laravel\Facades\Adldap::class

Publish the configuration file by running:

php artisan vendor:publish --tag="adldap"

Now you're all set!

Usage

First, configure your LDAP connection in the config/adldap.php file.

Then, you can perform methods on your default connection through the Adldap facade like so:

use Adldap\Laravel\Facades\Adldap;

// Finding a user:
$user = Adldap::search()->users()->find('john doe');

// Searching for a user:
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();

// Running an operation under a different connection:
$users = Adldap::getProvider('other-connection')->search()->users()->get();

// Creating a user:
$user = Adldap::make()->user([
    'cn' => 'John Doe',
]);

// Modifying Attributes:
$user->cn = 'Jane Doe';

// Saving a user:
$user->save();

If you do not specify an alternate connection using getProvider(), your default connection will be utilized for all methods.

Upon performing operations without specifying a connection, your default connection will be connected to and bound automatically using your configured username and password.

If you would prefer, you can also inject the Adldap interface into your controllers, which gives you access to all of your LDAP connections and resources as the facade.

use Adldap\AdldapInterface;

class UserController extends Controller
{
    /**
     * @var Adldap
     */
    protected $ldap;
    
    /**
     * Constructor.
     *
     * @param AdldapInterface $adldap
     */
    public function __construct(AdldapInterface $ldap)
    {
        $this->ldap = $ldap;
    }
    
    /**
     * Displays the all LDAP users.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        $users = $this->ldap->search()->users()->get();
        
        return view('users.index', compact('users'));
    }
    
    /**
     * Displays the specified LDAP user.
     *
     * @return \Illuminate\View\View
     */
    public function show($id)
    {
        $user = $this->ldap->search()->findByGuid($id);
        
        return view('users.show', compact('user'));
    }
}

To see more usage in detail, please visit the Adldap2 repository.

Versioning

Adldap2-Laravel is versioned under the Semantic Versioning guidelines as much as possible.

Releases will be numbered with the following format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backward compatibility bumps the major and resets the minor and patch.
  • New additions without breaking backward compatibility bumps the minor and resets the patch.
  • Bug fixes and misc changes bumps the patch.

Minor versions are not maintained individually, and you're encouraged to upgrade through to the next minor version.

Major versions are maintained individually through separate branches.