【问题标题】:Symfony LDAP invalid credentialsSymfony LDAP 无效凭据
【发布时间】:2020-08-28 04:58:54
【问题描述】:

我在使用 Symfony 测试 LDAP 身份验证时不断收到“无效凭据”错误,即使我的电子邮件和密码应该是正确的。有什么理由说明为什么会发生这种情况?

树枝:

    {% extends 'base.html.twig' %}

{% block body %}
    {% if error %}
        <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
    {% endif %}

    <form action="{{ path('login') }}" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="_username" value="{{ last_username }}" />

        <label for="password">Password:</label>
        <input type="password" id="password" name="_password" />

        <button type="submit">login</button>
    </form>
{% endblock %}

{% block stylesheets %}
{% endblock %}

我的控制器:

 /**
     * @Route("/login", name="login")
     * @param Request $request
     * @param AuthenticationUtils $authenticationUtils
     * @return Response
     */
    public function login(Request $request, AuthenticationUtils $authenticationUtils)
    {
        // get the login error if there is one
        $error = $authenticationUtils->getLastAuthenticationError();
        // last username entered by the user
        $lastUsername = $authenticationUtils->getLastUsername();


        return $this->render('security/login.html.twig', array(
            'last_username' => $lastUsername,
            'error'         => $error,
        ));
    }

services.yaml

services:
    Symfony\Component\Ldap\Ldap:
        arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter']

    Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
        arguments:
            - connection_string: 'xxx'
              options:
                  protocol_version: 3

security.yaml

main:
            anonymous: lazy
            form_login_ldap:
                login_path: login
                check_path: login
                service: Symfony\Component\Ldap\Ldap
                dn_string: 'ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=de'
                query_string: '(&(cn={username})(memberOf=cn=xxx,ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xxx))' 
                search_dn: 'uid=adminUser,ou=xxx,ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xx' 
                search_password: 'xxx' 

我错过了什么吗?

【问题讨论】:

  • 为什么第一个建议是尝试使用 ldap PHP 函数连接 ldap。一旦没问题,您应该在 dn_string、query_string、search_dn 和 search_password 参数中输入正确的值。

标签: symfony authentication ldap forms-authentication


【解决方案1】:

我遇到了同样的问题。问题是,由于 security.yaml 和 services.yaml 中的错误定义,您一定无法访问您的 LDAP。为了确保我有正确的凭据来访问我的 ldap,我所做的是终端中的以下命令:

ldapsearch -x -LLL -h example.com -D "ldap_username@example.com" -w "ldap_password" -b "DC=example,DC=com"

ldap_username 是用于从 LDAP 获取信息的帐户,ldap_password 是该帐户的密码。该帐户需要能够从您的 LDAP 中读取信息。 如果您的 ldap 用户得到了结果,那就太好了!否则您没有正确的凭据。

【讨论】:

    猜你喜欢
    • 2021-09-09
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2019-04-25
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    相关资源
    最近更新 更多