gpt4 book ai didi

authentication - Silex 应用程序中的自定义身份验证提供程序

转载 作者:行者123 更新时间:2023-12-04 12:48:14 30 4
gpt4 key购买 nike

我尝试使用 silex 文档为 LDAP 身份验证编写自定义身份验证提供程序 - Defining a custom Authentication Provider .

但如果我查看 $app['security.authentication_providers']有两个提供者。我定义的一个 App\LdapAuthenticationProvider和一个 Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider
当我尝试授权用户时,我收到错误消息,因为有一个 App\LdapUserProvider::loadUserByUsername() 的调用来自类 DaoAuthenticationProvider。

如果我在 $app['security.authentication_providers'] 中只有一个提供者我想我不应该出错,因为我的 LDAP 提供程序没有调用 loadUserByUsername。

这是 $app['security.authentication_providers'] 的转储

array (size=2)
0 => object(App\LdapAuthenticationProvider)[194]
private 'userProvider' =>
object(App\LdapUserProvider)[176]
private 'ldap' => resource(57, ldap link)
private 'defaultRoles' =>
array (size=1)
...
private 'providerKey' => string 'default' (length=7)
1 => object(Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider)[195]
private 'encoderFactory' =>
object(Symfony\Component\Security\Core\Encoder\EncoderFactory)[197]
private 'encoders' =>
array (size=1)
...
private 'userProvider' =>
object(App\LdapUserProvider)[176]
private 'ldap' => resource(57, ldap link)
private 'defaultRoles' =>
array (size=1)
...
private 'hideUserNotFoundExceptions' (Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider) => boolean true
private 'userChecker' (Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider) => object(Symfony\Component\Security\Core\User\UserChecker)[196]
private 'providerKey' (Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider) => string 'default' (length=7)

那么,有人知道为什么有额外的提供者,我该如何摆脱它?

bootstraping application 的代码, LdapAuthenticationListenerLdapAuthenticationProvider .

最佳答案

问题解决了。

我刚刚延长了我的 LdapAuthenticationListener与 symfony2 一起上课 UsernamePasswordFormAuthenticationListener并像这样更改 bootstarp:

$app['security.authentication_listener.factory.ldap'] = $app->protect(
function ($name, $options) use ($app) {
$app['security.authentication_provider.'.$name.'.ldap'] = $app->share(
function () use ($app) {
return new LdapAuthenticationProvider(
$app['security.user_provider.default'],
'ldap'
);
}
);

$app['security.authentication_listener.'.$name.'.ldap'] = $app->share(
function () use ($app, $name, $options) {
$app['security.authentication.success_handler.'.$name] =
$app['security.authentication.success_handler._proto']($name, $options);
$app['security.authentication.failure_handler.'.$name] =
$app['security.authentication.failure_handler._proto']($name, $options);

return new LdapAuthenticationListener(
$app['security'],
$app['security.authentication_manager'],
$app['security.session_strategy'],
$app['security.http_utils'],
$name,
$app['security.authentication.success_handler.'.$name],
$app['security.authentication.failure_handler.'.$name],
array_merge(
array(
'check_path' => '/admin/login_check',
'login_path' => '/login',
),
$options
),
$app['logger'],
$app['dispatcher'],
null
);
}
);

return array(
'security.authentication_provider.'.$name.'.ldap',
'security.authentication_listener.'.$name.'.ldap',
null,
'pre_auth'
);
}

我需要自定义身份验证监听器来覆盖身份验证方法中的 token ,身份验证提供程序通过用户名和密码从用户提供程序检索用户 $this->userProvider->loadUserByUsernameAndPassword($usernam, $password)

关于authentication - Silex 应用程序中的自定义身份验证提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16710529/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com