Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap配置后无效 #15

Closed
nsnake opened this issue May 8, 2019 · 12 comments
Closed

ldap配置后无效 #15

nsnake opened this issue May 8, 2019 · 12 comments

Comments

@nsnake
Copy link

nsnake commented May 8, 2019

配置了ldap。也开启了log模式,使用ldap的用户登录发现没有同步,也没任何错误和提示

@mylxsw
Copy link
Owner

mylxsw commented May 8, 2019

用户是不会自动同步的,每个用户登录的时候,会去LDAP查询用户信息,如果查询到就同步过来,如果需要将所有用户同步过来的话,可以在项目根目录下执行

php artisan adldap:import -vvv

我这边配置下面这个样子是可以同步用户,并且用LDAP登录的

WIZARD_USE_LDAP=true
# 这里只配置了只同步包含tp用户组的用户
WIZARD_LDAP_ONLY_MEMBER_OF=CN=tp,CN=Users,DC=xxxxxx,DC=com

LDAP_LOGGING=true
LDAP_ACCOUNT_PREFIX=
LDAP_ACCOUNT_SUFFIX=
LDAP_HOSTS=xx.xx.xx.xx
LDAP_PORT=389
LDAP_BASE_DN=dc=xxxxxx,dc=com
[email protected]
LDAP_PASSWORD=xxxxxxx
LDAP_USE_SSL=false
LDAP_USE_TLS=false
LDAP_PASSWORD_SYNC=true
LDAP_LOGIN_FALLBACK=false
LDAP_SYNC_NAME_ATTR=displayname

其中敏感信息已经用 xxx 来替换了。

如果按照这个样子配置还有问题的话,可以把你的配置贴出来看看,敏感信息替换掉就好了

@mylxsw mylxsw added this to To do in Wizard Development May 10, 2019
@mylxsw mylxsw moved this from To do to In progress in Wizard Development May 13, 2019
@nsnake
Copy link
Author

nsnake commented May 23, 2019

是否启用 LDAP 登录

WIZARD_USE_LDAP=true

是否开启 LDAP 日志

LDAP_LOGGING=true

LDAP 帐号前缀/后缀

LDAP_ACCOUNT_PREFIX=
LDAP_ACCOUNT_SUFFIX=

LDAP 服务地址

LDAP_HOSTS=127.0.0.1
LDAP_PORT=389

LDAP Base DN

LDAP_BASE_DN=dc=xxx,dc=com

LDAP 授权帐号

LDAP_USERNAME=cn=admin,dc=xxx,dc=com
LDAP_PASSWORD=mypass

LDAP 连接安全配置

LDAP_USE_SSL=false
LDAP_USE_TLS=false

同步 LDAP 密码到本地

LDAP_PASSWORD_SYNC=true

如果 LDAP 登录失败,是否使用本地帐号密码登录

LDAP_LOGIN_FALLBACK=false

LDAP 信息中,用哪个字段作为用户的名称,比如 displayname, cn 等

LDAP_SYNC_NAME_ATTR=cn

LDAP 限制只允许属于该成员的用户登录

WIZARD_LDAP_ONLY_MEMBER_OF=

@nsnake
Copy link
Author

nsnake commented May 23, 2019

我在执行了php artisan adldap:import -vvv后提示我
In Import.php line 62:

[RuntimeException]
There were no users found to import.

@nsnake
Copy link
Author

nsnake commented May 23, 2019

直接使用客户端命令
ldapsearch -L -w mypass -x -H ldap:https://127.0.0.1 -D "cn=admin,dc=xxx,dc=com" -b "dc=xxx,dc=com" "(cn=*)"
是可以查出数据的

@nsnake
Copy link
Author

nsnake commented May 23, 2019

另外我的cn中使用的是中文

@nsnake
Copy link
Author

nsnake commented May 23, 2019

日志中的提示
[2019-05-23 11:30:08] production.INFO: LDAP (ldap:https://127.0.0.1:389) - Connection: - Operation: Adldap\Auth\Events\Binding - Username: cn=admin,dc=xxx,dc=com
[2019-05-23 11:30:08] production.INFO: LDAP (ldap:https://127.0.0.1:389) - Connection: - Operation: Adldap\Auth\Events\Bound - Username: cn=admin,dc=xxx,dc=com

@mojie126
Copy link

日志中的提示
[2019-05-23 11:30:08] production.INFO: LDAP (ldap:https://127.0.0.1:389) - Connection: - Operation: Adldap\Auth\Events\Binding - Username: cn=admin,dc=xxx,dc=com
[2019-05-23 11:30:08] production.INFO: LDAP (ldap:https://127.0.0.1:389) - Connection: - Operation: Adldap\Auth\Events\Bound - Username: cn=admin,dc=xxx,dc=com

我也提示的是这个...很纳闷儿...

@mylxsw
Copy link
Owner

mylxsw commented May 29, 2019

用的是OpenLDAP吗

@nsnake
Copy link
Author

nsnake commented May 30, 2019

用的是OpenLDAP吗

对的。openldap

@nsnake
Copy link
Author

nsnake commented Jun 13, 2019

在调试之后找到原因了。
默认使用的是AD的模板,需要编辑config下的ldap.php文件
修改'schema' => Adldap\Schemas\ActiveDirectory::class为'schema' => Adldap\Schemas\OpenLDAP::class,

修改ldap_auth.php中的
'locate_users_by' => 'userprincipalname',
'bind_users_by' => 'distinguishedname',
为你ldap中对应的属性

除此之外你可能还需要修改.env中的 LDAP 帐号前缀/后缀数据以保证该用户在登陆时候的验证数据正确

总体而言,如果你发现上面的修改还是不行,就需要自己断点调试看下数据是否是ldap能正确接受的数据。

@WeiZhixiong
Copy link

Openldap 配置示例

一. 修改 .env

WIZARD_USE_LDAP=true

# 是否开启 LDAP 日志
LDAP_LOGGING=true
# LDAP 帐号前缀/后缀
LDAP_ACCOUNT_PREFIX=uid=
LDAP_ACCOUNT_SUFFIX=,dc=example,dc=com
# LDAP 服务地址
LDAP_HOSTS=1.1.1.1
LDAP_PORT=389
# LDAP Base DN
LDAP_BASE_DN=dc=example,dc=com
# LDAP 授权帐号
LDAP_USERNAME=uid=xxxxx,dc=example,dc=com
LDAP_PASSWORD=xxxxxxxx
# LDAP 连接安全配置
LDAP_USE_SSL=false
LDAP_USE_TLS=false
# 同步 LDAP 密码到本地
LDAP_PASSWORD_SYNC=false
# 如果 LDAP 登录失败,是否使用本地帐号密码登录
#LDAP_LOGIN_FALLBACK=false
LDAP_LOGIN_FALLBACK=false
# LDAP 信息中,用哪个字段作为用户的名称,比如 displayname, cn 等
LDAP_SYNC_NAME_ATTR=displayName
# LDAP 限制只允许属于该成员的用户登录
WIZARD_LDAP_ONLY_MEMBER_OF=

二. 修改 config/ldap.php

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

修改为

'schema' => Adldap\Schemas\OpenLDAP::class,

三. 修改 config/ldap_auth.php

        'ldap' => [

            'locate_users_by' => 'userprincipalname',

            'bind_users_by' => 'distinguishedname',

        ],

修改为

        'ldap' => [

            'locate_users_by' => 'uid',

            'bind_users_by' => 'uid',

        ],


    'scopes' => [

        // Only allows users with a user principal name to authenticate.
        // Suitable when using ActiveDirectory.
        Adldap\Laravel\Scopes\UpnScope::class,

        // Only allows users with a specified member to authenticate.
        \App\Components\Ldap\MemberOfScope::class,

        // Only allows users with a uid to authenticate.
        // Suitable when using OpenLDAP.
        // Adldap\Laravel\Scopes\UidScope::class,

    ],

修改为

    'scopes' => [

        // Only allows users with a user principal name to authenticate.
        // Suitable when using ActiveDirectory.
        // Adldap\Laravel\Scopes\UpnScope::class,

        // Only allows users with a specified member to authenticate.
        // \App\Components\Ldap\MemberOfScope::class,

        // Only allows users with a uid to authenticate.
        // Suitable when using OpenLDAP.
        Adldap\Laravel\Scopes\UidScope::class,

    ],

    'sync_attributes' => [

        'email' => 'userprincipalname',

        'name' => env('LDAP_SYNC_NAME_ATTR', 'cn'),

    ],

修改为

    'sync_attributes' => [

        'email' => 'mail',

        'name' => env('LDAP_SYNC_NAME_ATTR', 'cn'),

    ],

@mrochcn
Copy link

mrochcn commented Aug 7, 2020

可以问一下ldap的登录日志会放在哪边吗@mylxsw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

5 participants