Я пытаюсь сделать то же самое из вопроса в посте Как расширить LdapUserProvider и использовать пользовательский провайдер LDAP в Symfony? . Я воспроизвожу код de sames, но без результата.
Это мой service.yml
App\Security\CustomLDAPUserProvider:
arguments:
$ldap: ['@Symfony\Component\Ldap\Ldap']
$baseDn: 'OU=****,DC=****,DC=****,DC=****'
$searchDn: 'CN=****,OU=****,DC=***,DC=***,DC=***'
$searchPassword: '*********'
$filter: '({uid_key}={username})'
$uidKey: 'samAccountName'
$defaultRoles: ['ROLE_USER']
Symfony\Component\Ldap\Ldap:
arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter']
Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
arguments:
- host: ******
port: 389
options:
protocol_version: 3
referrals: false
Это security.yml
providers:
app_users:
id: App\Security\CustomLDAPUserProvider
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
form_login_ldap:
# ...
login_path: /login
check_path: /login
provider: app_users
service: App\Security\CustomLDAPUserProvider
dn_string: 'DC=****,DC=****,DC=***'
query_string: '(&(sAMAccountName={username})(|(memberOf=CN=RSUsers,OU=***,DC=***,DC=***,DC=**)(memberOf=CN=Admins. del dominio,CN=Users,DC=***,DC=****,DC=***)))'
search_dn: 'CN=****,OU=***,DC=***,DC=***,DC=**'
search_password: '*******'
Это провайдер .
class CustomLDAPUserProvider extends LdapUserProvider
{
/* EXTRA PARA LOS GRUPOS */
/** @var array maps ldap groups to roles */
private $groupMapping = [
'ROLE_USER' => 'Usuarios del dominio',
'ROLE_ADMIN' => 'Admins. del dominio',
'ROLE_RSUsers' => 'RSUsers'
];
/** @var string extracts group name from dn string */
private $groupNameRegExp = '/CN=(.+?),/';
protected function loadUser($username, Entry $entry)
{
$roles = ['ROLE_USER'];
// Check if the entry has attribute with the group
if (!$entry->hasAttribute('memberOf')) {
return new User($username, '', $roles);
}
// Iterate through each group entry line
foreach ($entry->getAttribute('memberOf') as $groupLine) {
// Extract the group name from the line
$groupName = $this->getGroupName($groupLine);
// Check if the group is in the mapping
if (array_key_exists($groupName, $this->groupMapping)) {
// Map the group to the role(s) the user will have
$roles[] = $this->groupMapping[$groupName];
}
}
// Create and return the user object
return new User($username, null, $roles);
}
/**
* Get the group name from the DN
* @param string $dn
* @return string
*/
private function getGroupName($dn)
{
$matches = [];
return preg_match($this->groupNameRegExp, $dn, $matches) ? $matches[1] : '';
}
}
И это ошибка.
TypeError HTTP 500 Внутренняя ошибка сервера Аргумент 1 передаваемый в App \ Security \ CustomLDAPUserProvider :: __ construct () должен реализовывать интерфейс Symfony \ Component \ Ldap \ LdapInterface, данный массив вызывается в C: \ xampp \ htdocs \ ultimo \ var \ cache \ dev \ ContainerHRnCi5I \ App_KernelDevDebugContainer. 1028 * в строке 1719
Я уже пробовал все, но безрезультатно. Может ли какое-нибудь тело помочь мне ???