Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8227697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:12:47+00:00 2026-06-07T16:12:47+00:00

I have a basic form-login authentication in my app, and I set up a

  • 0

I have a basic form-login authentication in my app, and I set up a handler using AuthenticationHandlerInterface, in which I’m setting session vars in the onAuthenticationSuccess() method.

The problem is that when I switch to another user (using ROLE_ALLOWED_TO_SWITCH), my handler is not called anymore, and the session vars I set before remain those of the user before switching.

Example :

  • Logging with user X
  • Setting session var myVar to X->someAttribute (inside the authentication handler)
  • Switching to user Y
  • Handler not called : myVar keeps keeps the same value

(I know that myVar = X->someAttribute is not a good example since I can already access it from the security token object, but it was to simplify the problem)

Thanks

EDIT : extract of security.yml

firewalls:
    main:
        pattern:    ^/
        anonymous: ~
        switch_user: { role: ROLE_ADMIN, parameter: _switch }
        form_login:
            provider: sso
            success_handler: authentication_handler
            login_path: /login
            check_path: /login_check
        logout:
            path:   /logout
            target: /home
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:12:49+00:00Added an answer on June 7, 2026 at 4:12 pm

    When the security component success to switch the current user, it will dispatch an event security.switch_user with the following event class : https://github.com/symfony/symfony/blob/2.0/src/Symfony/Component/Security/Http/Event/SwitchUserEvent.php .

    So you may need/want to listen to this event, and do your logic when your listener is called.

    To listen to this event, read the symfony cookbook entry on listeners : http://symfony.com/doc/current/cookbook/service_container/event_listener.html

    services:
        rocky.balboa.listener.security_switch_user:
            class: Rocky\BalboaBundle\Listener\SecuritySwitchUserListener
            tags:
                - { name: kernel.event_listener, event: security.switch_user, method: onSecuritySwitchUser }
    

    .

    // src/Rocky/BalboaBundle/Listener/SecuritySwitchUserListener.php
    
    namespace Rocky\BalboaBundle\Listener;
    
    use Symfony\Component\Security\Http\Event\SwitchUserEvent;
    
    class SecuritySwitchUserListener
    {
        public function onSecuritySwitchUser(SwitchUserEvent $event)
        {
            $newUser = $event->getTargetUser();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c# app and I'm trying to write a basic login form
I have a basic login form, which uses ajax to login users. If the
I have a very basic login form which accepts username and password. When the
I have a basic form that I'm using for member registration. I'm using the
I have just a basic html form within index.php which contains two text fields:
i have a form button in the form,which i need to perform basic action
I have a Spring Security (form based authentication) web app running CXF JAX-RS webservices
I have been requested to implement a login form into a friend's Visual Basic
I have this code for login validation using a Struts2 action class which calls
I have a basic form with a search input and a submit button within.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.