开发者

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

开发者 https://www.devze.com 2023-03-28 17:11 出处:网络
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

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

精彩评论

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