gpt4 book ai didi

Silex 身份验证 - 3 次尝试失败后限制访问

转载 作者:行者123 更新时间:2023-12-01 14:19:45 25 4
gpt4 key购买 nike

我是 Silex 的新手,我找不到如何更改 SecurityServiceProvider 以在 3 次错误连接后限制访问 24 小时。身份验证工作完美。

非常感谢您的帮助和想法。

最佳答案

您可以创建一个 CustomAuthenticationFailureHandler 来扩展 DefaultAuthenticationFailureHandler

创建一个类:

use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;

class CustomAuthenticationFailureHandler extends DefaultAuthenticationFailureHandler
{
/**
* (non-PHPdoc)
* @see \Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler::onAuthenticationFailure()
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
// create a failure counter for the access restriction

return $this->httpUtils->createRedirectResponse($request, $this->options['failure_path']);
}
}

分享这个类:

$app['security.authentication.failure_handler.general'] = $app->share(function() use ($app) {
return new CustomAuthenticationFailureHandler($app['security.http_utils'], array(), $app);
});

此故障处理程序与名为general防火墙匹配的位置:

// init the firewall
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'general' => array(
'pattern' => '^/',
'anonymous' => true,
'form' => array(
'login_path' => '/login',
'check_path' => '/admin/login_check'
),
...
)
)
);

您还需要一个 CustomAuthenticationSuccessHandler,它扩展 DefaultAuthenticationSuccessHandler:

use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;

class CustomAuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler
{
/**
* (non-PHPdoc)
* @see \Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler::onAuthenticationSuccess()
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
// handle the 24 hour restriction for the user ...

return $this->httpUtils->createRedirectResponse($request, $this->determineTargetUrl($request));
}
}

并分享这个类:

$app['security.authentication.success_handler.general'] = $app->share(function () use ($app) {
return new CustomAuthenticationSuccessHandler($app['security.http_utils'], array(), $app);
});

希望对你有帮助...

关于Silex 身份验证 - 3 次尝试失败后限制访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22070246/

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