Download the PHP package rgergo67/openldap without Composer
On this page you can find all versions of the php package rgergo67/openldap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rgergo67/openldap
More information about rgergo67/openldap
Files in rgergo67/openldap
Package openldap
Short Description Laravel package to manage users and groups in OpenLDAP
License GPL-3.0-only
Informations about the package openldap
Don't use this for production
Feel free to fork it and modify it as you wish, but don't use this for production. The version numbering does not follow any conventions, this exists only for test purposes.
Openldap-laravel
With this package you can add users to OpenLdap, edit and delete them, manage their attributes and add them to posix groups. The package is used to a specific project with specific needs, feel free to modify it.
Install
Install using composer:
Run php artisan vendor:publish
this will copy openldap.php
config file to config directory.
Add the following line to the config/app.php
providers array:
Basic usage
To be able to use this package, your User model needs to have two things.
DN attribute
First it has to have a dn
attribute, which you can create virtually or get from a mysql field. In our User.php model it looks like this:
We store employees and students in different organization units, therefor we need to be able to decide which one the given user is. (Students have a 6 char length uid, employees have 10 char length uid). An example value for this dn attribute is cn=rgergo6,ou=student,ou=people,dc=example,dc=com
ldap-format attribute
Second thing is an array called ldap-attribute. This array translates mysql fields to ldap fields. For example:
If you do an addUser($user);
the package will use this array to create a user in ldap.
Object class
The objectClass
attribute tells for ldap what kind of object the user is (which will specify what kind of attributes you can give it). You can edit this value in the config file, we use this:
In most cases the top, person, posixAccount, InetorgPerson
is enough, but we need the others too for our project.
Configuration
In the config file you can see admin_dn
and admin_password
these are used to connect to openldap, and should be defined in your .env file.
dn
There are 4 other dn keys in config:
base_user_dn
: if you have multiple user subtrees like we do (students, employees), then these should go below a ou=people
node, so if you are looking for a user with [email protected]
you don't have to filter twice (once in student tree, once in employee tree).
base_student_dn
and base_employee_dn
: we need to know where these are, so when we create a new employee, we can put it to the right place
bsae_group_dn
: the node where your groups are.
Groups
We use posix groups. The base_group_dn is ou=sys,dc=example,dc=com
but you can use anything. Below this node is a ou=joomla
and a ou=moodle
for grouping the similar systems together. If we create a new joomla site like hr.example.com, we create a new organization unit for it ou=hr.example.com,ou=joomla,ou=sys,dc=example,dc=com
, and a posix group below it for every joomla group (editor, registered, administrator): cn=editor,ou=hr.example.com,ou=joomla,ou=sys,dc=example,dc=com
Usage
Updating user
If you would like to update a user, first check if its uid (or the attribute that is part of the dn) is dirty (is changed). If so, first rename it, and update afterwards. The third parameter of rename should only be used if you move the record somewhere else. Note that second parameter is only RDN, not the full DN.
One more thing: if you rename something, the first parameter should be the old DN. If you for example hook into the users updating event, the $user objects $user->uid field (that is part of the DN) would contain the updated uid (if you modified it). To get the old dn, make use of Laravels $user->getOriginal() function.
Sync groups
Sometimes you just need to be sure the users groups are all synced. This function removes all groups from user, and adds them again.
Sync groups on user save save
Hook into the users saved event, and run group sync there. We have a series of checkboxes with group names that we can retrieve with request('groups')
.
Cleaning arrays
If you get back the search results from LDAP it has an ugly format, it is hard to work with. If you use the cleanUpEntry($entry) function, it will return a beutified cleaned php array. Credit goes to Chl
Example for simple search result:
If we clean the result: