symfony - Set Auth Token manually for different firewall -


my application has 2 security firewalls

"admin" - used internal staff

"account" - used customers.

previoly had 1 action under account firewall, action in controller looks this.

$user = //get user somehow $token = new usernamepasswordtoken($user, null, 'account', $user->getroles()); $this->get('security.token_storage')->settoken($token); 

with code above, able "login as" different users, , working not wanted.

however, when move code action inside admin firewall, instead changing token admin firewall, still want change token account firewall, possible? (in other words, want admin users have ability login different account users)

i rather not share "context" between firewalls, able logged admin , account firewalls @ same time.

this may little hacky, manually wiriting token session achieved wanted

$token = new usernamepasswordtoken($user, null, 'account', $user->getroles()); $this->get('session')->set('_security_account',serialize($token)); // needed prepend "_security_" firewall name "_security_account" 

didnt need call lines such as

//didnt seem need call either of these $this->get('security.token_storage')->settoken($token); //symfony 2.6+ $this->get('security.context')->settoken($token) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -