symfony - Symfony2: How to restrict / deny access to certain routes by IP address? -


i'd disallow access /login , /register if client's ip address has been banned.

the (black-) list of banned ips stored in database.

how can solve this?

since symfony 2.4 can use expression language component in config-files.

now implementing simple ip check easy:

  • create service (i.e. access_manager) method (i.e. getbannedips()) fetches list of banned ips storage layer
  • add expression security configuration compares returned array against client's ip address
  • that's it.

example

# app/config/security.yml security:     # ...     access_control:         - path: ^/(login|register)$           allow_if: "request.getclientip() not in @=service('access_manager').getbannedips()" 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -