Search code examples
securitysymfonyacl

app.user is not accessible from unsecured area


How is it possible to get app.user from unsecure area?

So I have secured area which starts from ^/user.

But I need to display logout form on area which is accessible for everyone and not secured. How is this possible? My security.yml:

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        ###:
            algorithm: sha512
            encode-as-base64: true
            iterations: 10
        ###:
            algorithm: sha512
            encode-as-base64: true
            iterations: 10

    role_hierarchy:


    providers:
      admin:
        name: admin
        entity: { class: ###, property: login }
      user:
        name: user
        entity: { class: ###, property: login }        

    firewalls:
      admin:
        pattern: ^/admin
        form_login:
          login_path: ###_login
          check_path: ###_login_process
          default_target_path: /admin/dashboard
        anonymous: ~
        logout:
          path: /admin/logout
          target: /admin/login
        provider: admin
        remember_me:
            key:      "###"
            lifetime: 604800
            path:     /
            domain:   ~ 
      user:
        pattern: ^/user
        form_login:
          login_path: ###_login
          check_path: ###_login_process
          default_target_path: ###
        anonymous: ~
        logout:
          path: /user/logout
          target: /user/login
        provider: user
        remember_me:
            key:      "###"
            lifetime: 604800
            path:     /
            domain:   ~             


    access_control:        
        - { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, roles: ROLE_ADMIN }
        - { path: ^/user/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/user/, roles: ROLE_USER }                   

Solution

  • Well I changed a little bit my security.yml. So currently everything works ok.

          user:
            pattern: ^/   
    
    
        access_control:
            - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
            ...
    

    UPDATE 1

    It seems that line in access_controll is not required. Moreover by some reason(might be cache) anonymoous users were accessing /user areas