Cara menggunakan php ldap not working

LDAP (Light Directory Access Protocol) adalah sebuah. Sebenarnya saya juga belum begitu mengerti bagaimana bentuk atau cara kerja LDAP sendiri, mungkin bisa cari-cari sendiri untuk pengertian dan cara kerja dari LDAP itu sendiri.

Pada kesempatan kali ini, saya akan sedikit berbagi ilmu bagaimana cara membuat autentikasi menggunakan LDAP di laravel.

Requirement

Disini kita akan menggunakan laravel versi 5.6 yang terbaru. Untuk versi php yang digunakan PHP 7.* . Untuk server LDAP sendiri, kita akan menggunakan online LDAP test server yang ada di sini . Jangan lupa untuk cek apakah PHP LDAP extensionnya sudah enable atau belum. Caranya ketik “php -m” di command line, maka akan muncul ldap seperti gambar dibawah ini.

Gambar 1. List PHP modules

Jika ternyata module LDAP tidak ada pada list tersebut, maka kita tinggal enable kan di php.ini. Untuk di linux, biasanya ada di /etc/php/php.ini .

Gambar 2. Letak php.iniLangkah 1

Install composer dan laravel, atau ikuti yang ada di sini . Lalu install package adldap2-laravel dengan command :

composer require adldap2/adldap2-laravel

Setelah package terinstall, kita publish vendor config untuk adldap2-laravel dengan command seperti dibawah :

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

Kita akan menggunakan LDAP test server menggunakan yang ada https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/. Setting config auth di config/auth.php dan ubah driver auth menjadi ‘adldap’.

Gambar 3. Setting auth driver untuk LDAPLangkah 3

Karena kita akan menggunakan openLDAP, kita ubah settingan config schema untuk koneksi adldap yang ada di folder config/adldap.php menjadi Adldap\Schemas\OpenLDAP::class.

Langkah 4

Kemudian, untuk autentikasi kita tidak akan menggunakan email yang merupakan settingan default dari package adldap2. Kita akan menggunakan akun username LDAP untuk login autentikasi ke aplikasi kita.

Langkah 5

Atur config untuk auth nya, sekarang kita setting config untuk menghubungkan aplikasi kita dengan LDAP test server. Karena config ini adalah sensitif, maka kita akan simpan config ini di .env milik kita seperti gambar di bawah ini.

LDAP (Lightweight Directory Access Protocol) adalah salah satu protokol direktori yang sampai saat ini masih bertahan dan populer digunakan di kelas menengah dan enterprise. Beberapa produk yang bisa anda pakai misalnya Microsoft Active Directory, Fedora Directory Access, Mandriva Directory Access, SUSE Linux Enterprise, OpenLDAP dan TurnkeyLinux LDAP.

Disini saya hanya akan membahas bagaimana cara koneksi ke protokol LDAP dari PHP. Beberapa hal yang harus anda perhatikan adalah:

1. pastikan extension php_ldap (php_ldap.dll untuk Windows dan php_ldap.so untuk Linux) sudah tersedia dan sudah di enable dalam file php.ini

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

Connection to LDAP in PHP isn’t that easy task by itself. Things get even more complicated, if you’re working in XAMPP environment under Windows. It hope this article will help you in getting un-stuck, if you’re stuck on the similar things.

As in our experience, on a very rare situation, we were required to use Windows Active Directory or OpenLdap as our user database in WordPress. We need to enable php ldap module in XAMPP. By default this php ldap module is not enable in XAMPP as most web servers are not using ldap as their database or directory. Follow these simple steps to enable this module.

To use LDAP support in PHP served under Windows you need to have three libraries:

libsasl.dll
ssleay32.dll
libeay32.dll

You have to put them into system32 folder, if you’re serving your PHP through XAMPP.

You need to have libsasl.dll library not only for very old PHP 4.3 or older. Even newest versions of PHP 5.3 and above require this lib.

What is even more strange, I had this library (along with required ssleay32.dll and libeay32.dll) in my PHP’s directory and my PHP’s directory was listed in Windows’ PATH variable. And even so, I’m facing the problem of Apache failing to start. The only workaround, I found, was to copy libsasl.dll to system32 system directory.

Enable support

You have to edit your php.ini file and uncomment extension=php_ldap.dll line. Then you have to restart your Apache / XAMPP server.

If you don’t have above mentioned libraries, next run of server will fail with information, which directory is missing. Newest XAMPP brings these libraries in XAMPP's php folder, so you only have to copy them to system32 folder, because for some strange reason, libraries in XAMPP's php are not loaded, though all of them are in PATH system environment variable.

Copy all of these libraries (or just libsasl.dll, as many other programs are using ssleay32.dll and libeay32.dll libraries and one of them could already put these two libs) to your system32 folder.