PHP code example of templatemonster / ldap-auth

1. Go to this page and download the library: Download templatemonster/ldap-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

templatemonster / ldap-auth example snippets


...
'bootstrap' => ['ldap'],
...
'modules' => [
    ...
    'ldap' => [,
        'class' => 'templatemonster\ldapauth\Module',
        'host' => 'localhost',
        'port' => 389,
        'baseDN' => 'dc=example,dc=com',
        'userDN' => 'uid={$username},ou=Users,dc=example,dc=com',
        'groupDN' => 'ou=Groups,dc=example,dc=com',
    ],
    ...
],
...
'as globalAccess'=>[
    ...
    'rules'=>[
        ...
        [
            'controllers'=>['ldap/acl'],
            'allow' => true,
            'roles' => ['administrator'],
        ],
        [
            'controllers'=>['ldap/acl'],
            'allow' => false,
        ],
        ...
    ],
    ...
],
...

...
'controllerMap' => [
    ...
    'migrate'=>[
        'class' => 'indigerd\migrationaware\controllers\MigrateController',
        'configFiles' => [
            '@backend/config/web.php',
        ],
        'migrationPath'=>'@common/migrations/db', //leave as it was before
        'migrationTable'=>'{{%system_db_migration}}' //leave as it was before
    ],
    ...
],
...



use yii\db\Migration;
use common\models\User;

class m161011_115434_assign_ldap_roles extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        /** @var \yii\rbac\DbManager $auth */
        $auth = \Yii::$app->ldapGroupsManager;

        $this->insert('{{%ldap_group}}', [
            'id' => 1,
            'ldap_group' => 'Administrators',
            'rbac_roles' => User::ROLE_ADMINISTRATOR
        ]);
        $auth->assign($auth->getRole(User::ROLE_ADMINISTRATOR), 1);
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        $this->delete('{{%ldap_group}}', ['id' => [1]]);
        \Yii::$app->ldapGroupsManager->revokeAll(1);
    }
}

...
[
    'label'=>Yii::t('backend', 'ACL Roles'),
    'icon'=>'<i class="fa fa-user-plus"></i>',
    'url'=>['/ldap/acl/index'],
    'visible'=>Yii::$app->user->can('administrator')
],
...

php console/yii migrate