抛出AuthenticationException但仍允许访问安全区域

时间:2016-07-17 01:30:35

标签: symfony

我们的遗留应用程序已更新为使用Symfony 2.7,而simple_form身份验证似乎工作正常。现在尝试将更多逻辑添加到自定义验证器类中并接收一些意外行为。

以下是发生的事情:

  • 用户可以使用正确的凭据登录。
  • 如果提供的凭据不正确,则会将用户重定向回登录路径,并在表单上显示相应的错误。
  • 问题:在自定义身份验证器类中,我们检查一个条件,然后抛出一个AuthenticationException。但是,登录仍然成功,用户将收到" USER"。
  • 的角色

问题是: 这是预期的行为吗?

我问的原因是我们有这个已经转换为Symfony的遗留PHP应用程序而且我没有参与这个初始转换过程。因此,可能已经更改了身份验证系统以促进此过程,但我无法追踪正在发生的事情。

到目前为止,我已使用this page作为参考,并尝试了对create a custom exception listenercalling pre-/post-auth methods on the UserChecker和其他几种替代方案的建议。没有人能够减轻"忽视"自定义验证器的authenticateToken方法中抛出的AuthenticationException。

# security.yml
security:
providers:
    our_db_provider:
        entity:
            class: AccountBundle:User
firewalls:
    default:
        anonymous: ~
        http_basic: ~
        provider: our_db_provider
        simple_form:
            authenticator: our_authenticator
            login_path: /secure/login/
            check_path: /secure/login_check/
    main:
        anonymous: ~
        access_control:
            - { path: ^/secure/, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
            - { path: ^/account/, roles: ROLE_USER, requires_channel: https }
# custom authenticator class
class OurAuthenticator implements SimpleFormAuthenticatorInterface
{
    public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        throw new AuthenticationException('$error');
    }

    public function supportsToken(TokenInterface $token, $providerKey)
    {
        return $token instanceof UsernamePasswordToken && $token->getProviderKey() === $providerKey;
    }

    public function createToken(Request $request, $username, $password, $providerKey)
    {
        return new UsernamePasswordToken($username, $password, $providerKey);
    }
}

作为备注,遗憾的是我们无法访问此应用中的Symfony探查器。

0 个答案:

没有答案