I one action controller of my project (Sf 2.7.3), I autologin a user like that:
$providerKey = 'user_provider';
$token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
$this->get('security.token_storage')->setToken($token);
$loginevent = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $loginevent);
Thats it's seems that works fine. In the Symfony toolbar appears:
Logged in as [email protected]
Authenticated No
Token class
UsernamePasswordToken
My security.yml:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
frontend:
pattern: ^/
anonymous: ~
http_basic: ~
provider: user_provider
form_login:
login_path: user_login
check_path: user_login_check
use_referer: true
logout:
path: user_logout
target: /
remember_me:
key: *****
lifetime: 31536000
access_control:
- { path: ^/private-zone/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/private-zone/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/private-zone/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/private-zone*, roles: [ROLE_USER, ROLE_ADMIN] }
providers:
user_provider:
entity:
class: X\AccountBundle\Entity\User
property: email
manager_name: ~
in_memory:
memory: ~
encoders:
X\AccountBundle\Entity\User: { algorithm: sha512, iterations: 10 }
But if I go to the /private-zone path, it's redirecting to /login (infinitely).
If I login with the form login, everything works fine, and the toolbar info is the same. Anyone understant the problem?
use_referrerjust to make a try and let me know - DonCallisto