LDAP Plugin for Pletfix
This plugin provides a LDAP service to authenticate the user through the Active Directory.
Fetch the package by running the following terminal command under the application's directory:
composer require pletfix/ldap-plugin
After downloading, enter this command in your terminal to register the plugin:
php console plugin pletfix/ldap-plugin
Environment and Configuration
Add the following environment variables in your
LDAP_ACCOUNT_SUFFIX=YourYccountSuffix LDAP_DOMAIN_CONTROLLER_1=YourPrimaryDC LDAP_DOMAIN_CONTROLLER_2=YourSecondDC LDAP_BASE_DN=YouBaseDN
At the next, open the configuration file
./config/ldap.php under the application's directory and override the
defaults if you wish.
If you would like to modified the views of the plugin, create a folder
ldap under the view directory of the
application, and copy the views there. Here you can edit the views as you like:
mkdir ./resources/views/ldap cp -R ./vendor/pletfix/ldap-plugin/views/* ./resources/views/ldap
If you have installed the Pletfix Application Skeleton, you could add the necessary
menu items ("login" and "logout") by including the partial
_nav in your
resources/views/app.blade.php layout just
above the marker
If you like to use another route paths, copy the route entries from
into the application's routing file
./boot/routes.php, where you can modify them as you wish:
$route->get('ldap/login', 'LdapController@showForm'); $route->post('ldap/login', 'LdapController@login');
Enter the following URL into your Browser to open the login form:
The "memberof" attribute is used to determine the user role. You may edit the member mapping in the configuration file
If you have defined a user model in the configuration, the user attributes are stored in the database. By default, the user model from the Pletfix Application Skeleton is used and no further migration is required.
You may invoke just the following command to logout the user:
Accessing the LDAP service
You can get an instance of the LDAP Service from the Dependency Injector:
/** @var Pletfix\Ldap\Services\Contracts\Ldap $ldap */ $ldap = DI::getInstance()->get('ldap');
You can also use the
ldap() function to get the LDAP service, it is more comfortable:
$ldap = ldap();
Search LDAP tree and get all result entries.
$users = $ldap->search('userprincipalname=Fr*');
Get the user entries.
$users = $ldap->getUsers();
You may also set a filter for the
$users = $ldap->getUsers('Fr*');
Get the user attributes by given username (userPrincipalName or samAccountName).
$user = $ldap->getUser('FrankR');
You may define the attributes of the user in the configuration file
Authenticate the user through the Active Directory.
$isAuthenticated = $ldap->authenticate($username, $password);
Return the LDAP error code of the last LDAP command.
$errorCode = $ldap->getErrorCode();
Return the LDAP error message of the last LDAP command.
$errorMessage = $ldap->getErrorMessage();