无效的凭证adldap2 / adldap2-laravel软件包

时间:2020-01-29 07:18:39

标签: php mysql laravel ldap adldap

我正在laravel应用中实现LDAP身份验证。当我运行此代码时,出现错误。

我不知道它是否正确。我对LDAP完全陌生,通过查看到目前为止我已经完成的文档,我不知道它是如何工作的。
请帮助我为laravel-ldap设置正确的配置设置。

Adldap \ Auth \ BindException (49)
Invalid credentials
 protected function attemptLogin(Request $request)
    {
       $ldap = new Adldap;
        $data = Adldap::users()->get();
       dd($data);

    }

我从客户那里获得的证书

User Name: username
 Password: password
 IP:172.16.xx.xx
 Port: 389
 Attributes: CN=user.admin,CN=Users,DC=UATADSRV,DC=COM

我的.env文件

LDAP_HOSTS=172.16.xx.xx
LDAP_BASE_DN=CN=user.admin,CN=Users,DC=UATADSRV,DC=COM
LDAP_USER_ATTRIBUTE=samaccountname
LDAP_CONNECTION=default
LDAP_USERNAME=username
LDAP_PASSWORD=password

ldap.php

return [

    'logging' => env('LDAP_LOGGING', false),

    'connections' => [

        'default' => [
   'auto_connect' => env('LDAP_AUTO_CONNECT', true),

            'connection' => Adldap\Connections\Ldap::class,

            'settings' => [
    'schema' => Adldap\Schemas\ActiveDirectory::class,


                'account_prefix' => env('LDAP_ACCOUNT_PREFIX', ''),

                'account_suffix' => env('LDAP_ACCOUNT_SUFFIX', ''),   

                'hosts' => explode(' ', env('LDAP_HOSTS', 'corp-dc1.corp.acme.org corp-dc2.corp.acme.org')),

         'port' => env('LDAP_PORT', 389),

                'timeout' => env('LDAP_TIMEOUT', 5),

                'base_dn' => env('LDAP_BASE_DN', 'dc=corp,dc=acme,dc=org'),

                'username' => env('LDAP_USERNAME'),
                'password' => env('LDAP_PASSWORD'),

                'follow_referrals' => false,


                'use_ssl' => env('LDAP_USE_SSL', false),
                'use_tls' => env('LDAP_USE_TLS', false),

            ],

        ],

    ],

];


ldap_auth.php

return [

    'connection' => env('LDAP_CONNECTION', 'default'),

    'provider' => Adldap\Laravel\Auth\DatabaseUserProvider::class,

    'model' => App\User::class,
    'rules' => [


        Adldap\Laravel\Validation\Rules\DenyTrashed::class,

    ],



    'scopes' => [



    ],

    'identifiers' => [

    'rules' => [


        Adldap\Laravel\Validation\Rules\DenyTrashed::class,

    ],



    'scopes' => [



    ],

    'identifiers' => [

 'ldap' => [

         //   'locate_users_by' => 'userprincipalname',
             'locate_users_by' => 'samaccountname',

            'bind_users_by' => 'distinguishedname',

        ],

        'database' => [

            'guid_column' => 'objectguid',
           'username_column' => 'username',

        ],
  'windows' => [

            'locate_users_by' => 'samaccountname',

            'server_key' => 'AUTH_USER',

        ],

    ],

    'passwords' => [



        'sync' => env('LDAP_PASSWORD_SYNC', false),



        'column' => 'password',
  ],


    'login_fallback' => env('LDAP_LOGIN_FALLBACK', false),



    'sync_attributes' => [

        'email' => 'userprincipalname',
        'username' => 'samaccountname',
        'name' => 'cn',

    ],

  'logging' => [

        'enabled' => env('LDAP_LOGGING', true),

        'events' => [

            \Adldap\Laravel\Events\Importing::class                 => \Adldap\Laravel\Listeners\LogImport::class,
            \Adldap\Laravel\Events\Synchronized::class              => \Adldap\Laravel\Listeners\LogSynchronized::class,
            \Adldap\Laravel\Events\Synchronizing::class             => \Adldap\Laravel\Listeners\LogSynchronizing::class,
            \Adldap\Laravel\Events\Authenticated::class             => \Adldap\Laravel\Listeners\LogAuthenticated::class,
            \Adldap\Laravel\Events\Authenticating::class            => \Adldap\Laravel\Listeners\LogAuthentication::class,
            \Adldap\Laravel\Events\AuthenticationFailed::class      => \Adldap\Laravel\Listeners\LogAuthenticationFailure::class,
            \Adldap\Laravel\Events\AuthenticationRejected::class    => \Adldap\Laravel\Listeners\LogAuthenticationRejection::class,
            \Adldap\Laravel\Events\AuthenticationSuccessful::class  => \Adldap\Laravel\Listeners\LogAuthenticationSuccess::class,
            \Adldap\Laravel\Events\DiscoveredWithCredentials::class => \Adldap\Laravel\Listeners\LogDiscovery::class,
            \Adldap\Laravel\Events\AuthenticatedWithWindows::class  => \Adldap\Laravel\Listeners\LogWindowsAuth::class,
            \Adldap\Laravel\Events\AuthenticatedModelTrashed::class => \Adldap\Laravel\Listeners\LogTrashedModel::class,

        ],
    ],

];


谢谢

1 个答案:

答案 0 :(得分:1)

LDAP服务器说您提供的凭据错误。 您确定您的用户名和密码正确100%吗?空格还是任何无效字符?

CN=user.admin,CN=Users,DC=UATADSRV,DC=COM`

还可以使用ldap_bind()函数吗?