Is it possible to authenticate via username or IP in Symfony2?
I know that it’s possible to login with username and password or by IP address, but is it also possible to authenticate when I come from a specfic IP address automatically and if not then via username and password?
Example:
If I come from 10.1.1.1 I want to get the ADMIN_ROLE
If I come from a different IP I have to login via username and password
Here comes my security.yml
secured_area:
pattern: ^/
anonymous: ~
form_login:
check_path: /login_check
login_path: /login
logout:
path: /logout
target: /login
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_ADMIN }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 10.1.1.1 }
Thanks for help!
It is possible but not secure. You can do chained authentication providers (firewall section in the security.yml)
In your case you will need to implement a custom one for the IP authentication method. You can find a documentation writing a custom authentication provider in the Symfony cookbook( want: http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html)
You will have to chain your custom provider and the Symfony2 form auth provider.