我正在使用Symfony框架v2.4.2更新一个现有网站,该网站执行双重检查,将用户登录到:
ldap_bind()函数);如何在Symfony2?中复制这一过程?
到目前为止,我一直在使用FOSUserBundle和FR3DLdapBundle:我成功地使用了链式提供程序(ldap和db),但是似乎LDAP凭据被完全忽略了:用户可以使用存储在DB中的凭据登录,即使ldap_bind()失败了--这与第1和第2点的正好相反。
此外,在使用FOSUserBundle时,似乎必须在DB中存储密码。
请注意第2点:用户必须可以在网站外(即Active Directory)自由更改LDAP密码,然后使用新的凭据登录,而不需要更新网站的用户数据库。
任何解决方案都是受欢迎的,我不太喜欢FOSUserBundle,更不喜欢FR3DLdapBundle。
发布于 2014-03-24 11:29:39
我是这样想出来的:
app/config/security.yml中的我的app/config/security.yml部分;发布于 2014-03-19 15:46:33
您需要为LDAP定义一个CustomUserProvider,它将在AD中找到用户,在security.yml中需要设置此提供程序(自定义用户提供程序)。
providers:
ldap_provider:
id: myprovider.security.user.provider # as you know when you create a custom web service provider you need to define it as a service and use the ID of the service here #您还需要在防火墙中启用服务。
下一步是为LDAP创建自定义身份验证提供程序,它通过LDAP对用户和密码进行身份验证,并从DB (自定义身份验证提供者)返回用户对象。
基于这个过程,首先它将尝试在LDAP中找到用户,如果它存在,它将继续通过LDAP进行身份验证,如果用户经过身份验证,它将从DB返回用户对象。
以下是自定义用户提供程序的示例
public function loadUserByUsername($username)
{
$ldap_obj = new adLDAP('exampl.ldapdircetory.com', 'prot', 'Base_DN', 'ldap_admin_user', 'ldap_admin_pass'));
$filter = "( &(objectclass=person)( |(uid=".$username.")(cn=".$username.")(mail=".$username.") ) )";
$info = $ldap_obj->search_user($filter);
if ($info['count'] != 0) {
// create temp User instance of UserInterface base on the returned info
$user = new User();
...
return $user
}
else {
throw new UsernameNotFoundException('No match username was found.');
}我假设您有adLDAP类通过LDAP对用户进行身份验证。
https://stackoverflow.com/questions/22501134
复制相似问题