【发布时间】: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