Based on the work from sgomez/adldap2-bundle Updated to match the latest Symfony4 Bundle Best-Practices and ADLDAP2 V10.
Open a command console, enter your project directory and execute:
$ composer require iphis/adldap2-bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require iphis/adldap2-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php
return [
// ...
IPHIS\Adldap2Bundle\IphisAdldap2Bundle::class => ['all' => true],
];
You need to configure your connection. The parameters are the same that use Adldap2.
This is a sample configuration that you need to add in the app/config/adldap2.yml
file:
adldap2:
default:
hosts: ['corp-dc1.corp.acme.org', 'corp-dc2.corp.acme.org']
base_dn: 'dc=corp,dc=acme,dc=org'
username: "admin"
password: "password"
auto_connect: true
schema: Adldap\Schemas\ActiveDirectory::class
account_prefix: "ACME-"
account_suffix: "@acme.org"
port: 389
follow_referrals: false
use_ssl: false
use_tls: false
version: 3
timeout: 5
You don't need to configure all values. See the original adldap2 documentation for more information.
Note: auto_connect
configuration option is not part of the adldap2 library but instead an option for this bundle
to configure whether you want the 'adldap2' service to automatically connect on application boot or not.
A new service called 'adldap2' has been created. It's a configured instance of Adldap class. You can use it as usual:
class DefaultController extends Controller
{
public function indexAction()
{
$user = $this->get('adldap2')->search()->find('username');
}
}
Note: if you have auto_connect: false
in your adldap2 configuration you will need to manually call connect()
before you can perform any queries on the library.