2014-01-09 24 views
1

我做了一个从DefaultAuthenticationSuccessHandler扩展的子类,以便在身份验证过程中添加自定义功能。如果不符合标准,我想停止认证过程。我怎么做?如何在AuthenticationSuccessHandler中取消认证?

public function onAuthenticationSuccess(Request $request, TokenInterface $token) { 
    if(some_condition_applies){ 
     //if success, resume default flow 
     return parent::onAuthenticationSuccess($request, $token); 
    }else{ 
     //how to fail the authentication here? 
    } 
} 
+0

在验证用户身份之后'onAuthenticationSuccess'被调用**。所以我认为你需要一个自定义的用户提供者。 –

+0

我这么认为。在我查看了Symfony的默认身份验证提供程序之后,我意识到这是我必须进行更改的提供程序,而不是成功处理程序。 – Tholapz

回答

0

根据您的设置,在Symfony的2.4新SimpleFormAuthenticator功能可以帮助你:How to Create a Custom Form Password Authenticator

这可能是只适用,如果你的认证机制是用户名/密码为主(不OAuth的什么)。

此外,您可能只需实现AdvancedUserInterface,然后从类似“isEnabled”的方法返回“false”以阻止登录(Forbid Inactive Users)。唯一的缺点是你只能访问你的User类中的数据。如果你需要的东西超出这个,上面的方法应该工作(但是有一点点工作)。

干杯!

相关问题