是的,我知道有。 co/书的论文。 但我只想稍有不同。 我需要两个不同的黑名单:
- deny certain IP to access whole site
- deny certain IP to log in
我写道,如果用户的IP正在数据库中,就会进行检查。 对于第一个情况,我写了一位凯尔听器,对每一项请求进行核查,并在遇到被禁用户时扔下403条:
if (VoterInterface::ACCESS_DENIED === $this->voter->vote($token, $this, array())) {
throw new AccessDeniedHttpException( Blacklisted, punk! );
}
First problem lies in VoterInterface
itself, which forces me to use TokenInterface $token
, which I don t really need in this case. But that doesn t matter that much I guess. Next thing is that I actually had to use AccessDeniedHttpException
as AccessDeniedException
always tries to redirect me to login page and causes endless redirect loop in this case. I d live with it as it works just fine in dev
environment, but when I switch to prod
I keep getting 503 with following in prod log:
[2011-11-21 20:54:04] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2011-11-21 20:54:04] request.ERROR: SymfonyComponentHttpKernelExceptionAccessDeniedHttpException: Blacklisted, punk! (uncaught exception) at xxx line 28 [] []
[2011-11-21 20:54:04] request.ERROR: Exception thrown when handling an exception (SymfonyComponentHttpKernelExceptionAccessDeniedHttpException: Blacklisted, punk!) [] []
从我刚才看,它可能遇到 x问题,但甚至在我离开时就会出现问题。 我也尝试了vanilla Exception
,而且这样做也是一样的。 没有人会想为什么会发生? 也可能是这种黑名单化案件的其他解决办法。
此外,我没有想如何解决第二起案件,因为我不知道如何在被指定之前停止使用。 我目前的解决办法是:rel=“noreferer”>Interactive式LoginEvent,检查用户是否被黑名单,如果是的话,则去除。 这似乎是一种安全的做法,我不敢真正感到安慰。 因此,如何解决这一问题的想法是什么? 我猜测Im略去掉一些明显的“原始事件”。