2

I use symfony2 and FOS UserBundle.

I have followed the FOSUSerBundle docs from https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md but I have no redirection if I'm going to a specific page.

I mean, I have to be redirected to http/myapp/login when I type http/myapp/myspecificPage/toto but not. Even if I 'm not logged into my app.

My NamespaceLoginBundle extends to FOSUser.

Here my files routing.yml:

login: pattern: /login defaults: { _controller: NamespaceLoginBundle:Welcome:login } login_check: pattern: /login_check defaults: { _controller: NamespaceLoginBundle:Welcome:checkUser } fos_user_security: resource: "@FOSUserBundle/Resources/config/routing/security.xml" prefix: / fos_user_profile: resource: "@FOSUserBundle/Resources/config/routing/profile.xml" prefix: /profile fos_user_register: resource: "@FOSUserBundle/Resources/config/routing/registration.xml" prefix: /register fos_user_resetting: resource: "@FOSUserBundle/Resources/config/routing/resetting.xml" prefix: /resetting fos_user_change_password: resource: "@FOSUserBundle/Resources/config/routing/change_password.xml" prefix: /change-password 

and security.yml

security: providers: fos_userbundle: id: fos_user.user_manager firewalls: main: pattern: ^/ form_login: provider: fos_userbundle logout: true anonymous: true role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: ROLE_ADMIN access_control: # Liste des pages accessibles à tous les utilisateurs (ne pas toucher) - { path: ^/_wdt/, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/_profiler/, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/js/, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/css/, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resseting$, role: IS_AUTHENTICATED_ANONYMOUSLY } # PAGES ACCESSIBLES AUX ADMINISTRATEURS - { path: ^/admin/, role: ROLE_ADMIN } # PAGES ACCESSIBLES AUX UTILISATEURS CONNECTES - { path: ^/change-password, role: ROLE_USER } # PAGES ACCESSIBLES A TOUS - { path: ^.*, role: IS_AUTHENTICATED_ANONYMOUSLY } acl: connection: default 

I have tried some modification but doesn't work.

Any help please.

See ya

Sam

4
  • You allowed to access all pages except for admin and change-password by the ^.*, role: IS_AUTHENTICATED_ANONYMOUSLY rule.. Commented Dec 15, 2011 at 9:03
  • even if I remove - { path: ^.*, role: IS_AUTHENTICATED_ANONYMOUSLY } it doesn't work Commented Dec 15, 2011 at 9:09
  • 1
    You need to specify roles, not remove it. - { path: ^/.*, role: [IS_AUTHENTICATED_REMEMBERED, IS_AUTHENTICATED_FULLY] } where IS_AUTHENTICATED_FULLY is authenticated by typing login and password, IS_AUTHENTICATED_REMEMBERED is a user that selected 'remember me' on the last login Commented Dec 15, 2011 at 9:42
  • Hi, thanks, now it's work... I have changed the last line by yours and it works. Thanks meze Commented Dec 15, 2011 at 10:10

2 Answers 2

1

You need to specify roles

- { path: ^/.*, role: [IS_AUTHENTICATED_REMEMBERED, IS_AUTHENTICATED_FULLY] }

where:

IS_AUTHENTICATED_FULLY is authenticated by typing login and password, IS_AUTHENTICATED_REMEMBERED is a user that selected 'remember me' on the last login

Sign up to request clarification or add additional context in comments.

Comments

0

EDIT : first time, wrong answer x)

You need to set your access_role in order to allow anonymous user only on the login page :

access_control: - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/logout, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, roles: ROLE_USER } 

2 Comments

Hi I've tried to remove this line but I have this error: "La page n'est pas redirigée correctement" means "The redirection is not correct"
My bad, I was false by saying to delete anonymous: true ; I edit my answer ;) (And I know what it means, I'm french =P)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.