Symfony 2.5: $ this-> getUser () is empty

  • I have a form that users can enter.
  • After logging in, I redirect the user to the control panel page.

Problem . In my input controller, I am getting the user object. But when I go to the toolbar, the custom object is empty.

SigninController

 if ($this->isAuthUser($request)) {
          $signinUser = $request->get('signin');
          $token = new UsernamePasswordToken($signinUser, null, 'secured_area', $signinUser->getRoles());
          $this->get("security.context")->setToken($token);      

          $event    = new InteractiveLoginEvent($request, $token);
          $this->get("event_dispatcher")->dispatch("security.interactive_login", $event);

          $session = $this->get('session');
          $session->set('user', $signinUser->getUsername());
    }

      

security.yml

security:
    providers:        
        in_memory:
            memory: ~

    access_control: 
      #- { path: ^/(signin|signup)?$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      #- { path: ^/, roles: IS_AUTHENTICATED_FULLY }      

    firewalls:
      secured_area:
        pattern:   ^/
        anonymous: true
        form_login:
          login_path: /signin
          check_path: _security_check
        access_denied_url: signin
#        logout:
#          path:   /signout
#          #target: /
#          invalidate_session: false
#          delete_cookies:
#              a: { path: null, domain: null }
#              b: { path: null, domain: null }
#          #handlers: [some.service.id, another.service.id]
#          #success_handler: some.service.id
      dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

      default:
        anonymous: true

      

object token: Signincontroller

Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken Object
(
    [credentials:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => 
    [providerKey:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => secured_area
    [user:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Headset\Bundle\AccountsBundle\Entity\User Object
        (
            [email:Headset\Bundle\AccountsBundle\Entity\User:private] => operator1@flavr.com
            [password:Headset\Bundle\AccountsBundle\Entity\User:private] => operator123#46
            [oldPassword:Headset\Bundle\AccountsBundle\Entity\User:private] => 
            [id:Headset\Bundle\AccountsBundle\Entity\User:private] => 
            [userId:Headset\Bundle\AccountsBundle\Entity\User:private] => 
            [firstName:Headset\Bundle\AccountsBundle\Entity\User:private] => 
            [lastName:Headset\Bundle\AccountsBundle\Entity\User:private] => 
            [username:Headset\Bundle\AccountsBundle\Entity\User:private] => operator1@flavr.com
        )

    [roles:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
        (
            [0] => Symfony\Component\Security\Core\Role\Role Object
                (
                    [role:Symfony\Component\Security\Core\Role\Role:private] => ROLE_USER
                )

        )

    [authenticated:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 1
    [attributes:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
        (
        )

)

      

Control panel controller

Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken Object
(
    [credentials:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => 
    [providerKey:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => secured_area
    [user:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 

    [roles:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
        (
            [0] => Symfony\Component\Security\Core\Role\Role Object
                (
                    [role:Symfony\Component\Security\Core\Role\Role:private] => ROLE_USER
                )

        )

    [authenticated:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 1
    [attributes:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
        (
        )

)

      

Can anyone figure out what is the reason?

any help would be much appreciated ...

+3


source to share


1 answer


Probably a configuration problem. According to users, part of the configuration, you just don't have users.

security:
    providers:        
        in_memory:
            memory: ~

      



Check out the symfony documentation for user uploads

0


source







All Articles