【发布时间】:2014-07-20 18:01:01
【问题描述】:
我对安全定制 symfony 的主题真的很陌生,按照我创建的指南,我创建了一种简单的方法来验证我的 API。
如果用户没有发送带有令牌的特殊标头,应用程序会抛出一个
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
use Symfony\Component\HttpFoundation\Request;
//...
public function createToken(Request $request, $providerKey)
{
if (!$request->headers->has(self::API_TOKEN)) {
throw new BadCredentialsException('No API key found');
}
return new PreAuthenticatedToken('anon.', $request->headers->get(self::API_TOKEN), $providerKey);
}
我不知道什么应该返回 symfony,但我知道一定是 401 错误而不是 500。我该如何处理这个问题,我需要自己写 SimplePreAuthenticationListener?当我读到Simple*AuthenticatorInterface是avoid that背后的想法时,
【问题讨论】: