title: Managing user access to pages in Symfony2
body: <p>I'm working on managing access for users to some pages on my site. I have 1 type of fully authenticated users (<code>role: ROLE_MEMBER</code>, based on <code>ROLE_USER</code>) and, of course, anonymous users too.</p>
  
  <p>Let's say I have 2 pages (<code>/index</code>, <code>/account</code>) on the site, both with <code>secure: true</code>. Let's say <code>/index</code> requires <code>role: IS_AUTHENTICATED_ANONYMOUSLY</code> and <code>/account</code> requires <code>role: IS_AUTHENTICATED_FULLY</code> (for <code>ROLE_MEMBER</code>).</p>
  
  <p>I want to show special "account menu"  for logged in members on both pages, so in template i check <code>is_granted('ROLE_MEMBER')</code>. </p>
  
  <p>That works great for <code>/account</code>, of course. The problem, when member is navigated to <code>/index</code> (which is "anonymous" page) function <code>is_granted('ROLE_MEMBER')</code> returns <code>0</code>, and <code>is_granted('IS_AUTHENTICATED_ANONYMOUSLY')</code> returns <code>1</code>. When members navigates to <code>/account</code> again, everything works without reentering password (that means member still not logged out).</p>
  
  <p>So, the question is how to detect what member is logged in user inside template for <code>/index</code> page?</p>
  
  <p>UPDATED.
  @alessandro1997 here is my <code>app/config/security.yml</code> configuration</p>
  
  <pre><code>security:
      encoders:
          AG\MemberBundle\Entity\Member:
              id: member_saltedpassword_encoder
  
      role_hierarchy:
          ROLE_MEMBER: ROLE_USER
          ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_MEMBER, ROLE_ALLOWED_TO_SWITCH]
  
      providers:
          member_db:
              entity: { class: AGMemberBundle:Member, property: email }
  
      firewalls:
          members:
              pattern:  ^/account
              security: true
              form_login: 
                  login_path: /account/login
                  check_path: /account/login/check
                  post_only: true
                  username_parameter:  _email
                  password_parameter:  _password
                  default_target_path: /account/
                  always_use_default_target_path: true
                  # csrf token options
                  csrf_parameter: _csrf_token
                  intention: authenticate
              provider: member_db
              logout:
                  path: /account/logout
                  target: /
              remember_me:
                  key:      "qwewqeqwerwxeweqweqwe"
                  lifetime: 3600
                  path:     /
                  domain:   ~ # Defaults to the current domain from $_SERVER
          pages:
              pattern: ^/
              security: true
              anonymous: ~
  
      access_control:
          - { path: ^/account, roles: IS_AUTHENTICATED_FULLY }
          - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  </code></pre>