Yii 2 AD LDAP

cd localhost\yii2basic

правим composer.json
добавляем
  
{
    "name": "yiisoft/yii2-app-advanced",
    "description": "Yii 2 Advanced Project Template",
    "keywords": ["yii2", "framework", "advanced", "project template"],
    "homepage": "http://www.yiiframework.com/",
    "type": "project",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "http://www.yiiframework.com/forum/",
        "wiki": "http://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },
    "minimum-stability": "stable",
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "adldap/adLDAP",
                "version": "4.0.4",
                "source": {
                    "url": "https://github.com/adldap/adLDAP",
                    "type": "git",
                    "reference": "v4.0.4"
                }
            }
        }
    ],
    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.4",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "adldap/adldap": "4.0.4 as 4.0-stable",
        "edvlerblog/yii2-adldap-module": "v1.0.0"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    },
    "config": {
        "process-timeout": 1800
    },
    "extra": {
        "asset-installer-paths": {
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        }
    }
}

composer update


видать из-за версии не можеть увидеть  adLDAP
в \yii2basic\vendor\edvlerblog\yii2-adldap-module\src\Ldap.php
исправим

use yii\base\Component; //include YII component class
//include  dirname(dirname(dirname(dirname(__FILE__)))) .'/adldap/adldap/src/adLDAP.php';  -точно работает
use Adldap\Adldap; //нет возможности проверить, но по логике должно
use adLDAP; //include the adLDAP class


таким образом мы установили Wrapper для ad ldap

config\main (advanced) либо config\web (basic)

'components' => [
    ..... 

    'ldap' => [
        'class'=>'Edvlerblog\Ldap',
        'options'=> [
                //'ad_port'      => 389,
                'domain_controllers'    => array('AdServerName1'),
                'account_suffix' =>  '@test.lan',
                'base_dn' => "DC=test,DC=lan",
                // for basic functionality this could be a standard, non privileged domain user (required)
                'admin_username' => 'ActiveDirectoryUser',
                'admin_password' => 'StrongPassword'
            ]
    ]

    ...
]

\yii2basic\models\LoginForm.php

    public function login()
    {
        $authUser = \Yii::$app->ldap->authenticate($this->username, $this->password);
        
        if ($authUser)
            return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);

        if ($this->validate())
        {
            return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
        }
        return false;
    }

****Спасибо

Популярные сообщения из этого блога

Пишем логи на C# (.NET). Легкий способ.

Средства для работы с базой данный PostgreSql

Авторизация yii 2 из базы