authentication - 从 Symfony2 中的身份验证失败处理程序访问原则

标签 authentication symfony doctrine-orm

我正在尝试通过自定义身份验证处理程序在数据库中写入一些登录失败信息。 我的问题是获得对数据库的访问权限,因为我不知道 Doctrine 对象可能存储在哪里

这是我现在的代码:

namespace MyApp\FrontBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request as Request;
use Symfony\Component\HttpFoundation\RedirectResponse as RedirectResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Security\Http\Authentication as Auth;
use Symfony\Component\Security\Core\Exception\AuthenticationException as AuthException;

class SecurityHandler implements Auth\AuthenticationFailureHandlerInterface
{
    public function onAuthenticationFailure(Request $request, AuthException $token)
    {
        try
        {
            $lastLoginFailure = new DateTime();

            // get database object here
        }
        catch(\Exception $ex)
        {
        }
    }
}

有什么想法吗?

最佳答案

将您的 SecurityHandler 变成一个服务,然后将 doctrine 实体管理器注入(inject)其中。

http://symfony.com/doc/current/book/service_container.html

关于authentication - 从 Symfony2 中的身份验证失败处理程序访问原则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9491652/

相关文章:

php - 为在 CakePHP 2 中使用 AuthComponent 的 Controller 编写单元测试

python - 如何在 Google 应用引擎上使用 session

php - Symfony 控制台 Doctrine :schema:update --force SQLSTATE[HY000] [1045] Access denied for user 'root' @'localhost' (using password: NO)

orm - Doctrine DQL QueryBuilder 排除存在关系的实体

Symfony2/Doctrine - postFlush

php - $_SERVER ['REMOTE_USER'] 是否被视为 'safe' ?

authentication - 我使用 yeroon.net/ggplot2 登录 Google 电子表格有多安全

php - fatal error 异常: Error: Class 'PDO' not found on symfony2

symfony - 如何在运行 "composer install"时自动选择默认参数而不是按回车键确认?

sql - Symfony/Doctrine : SUM and AVG score of players