开发者

How to decline user authentication request depending on its ip address in Symfony2

In my case some of users can login only from specific ip addresses (one for each user).

I need 开发者_如何学Goto decline all auth requests for a user if user's ip address doesn't match with ip from database.

For now I have this User entity:

class User implements AdvancedUserInterface
{
    // ....
    protected $id;

    // ....
    protected $allowedIp;
}

This check needs to be done at the authentication stage.


You'll want to use an authentication voter. The Symfony cookbook has a recipe for an IP blacklist voter, so you can follow their example and change the code to deny if it's not on the list, instead of denying if it is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜