Ok guys, it has been 10 hours that I search a solution for my problem. My firewall on Symfony 2.7 doesn't redirect me if i'm not logged in.
If I go on domain.com/admin/, the firewall should redirect me on /login, but not.
I use FOSUSerBundle. I alway obtain this error message :
You are not authenticated 401 Unauthorized - HttpException 1 linked Exception: AuthenticationCredentialsNotFoundException »
Here is my code:
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
admin:
pattern: ^/
context: site
form_login:
provider: fos_userbundle
check_path: /login_check
login_path: /login
logout:
path: /admin/logout
anonymous: false
My access control:
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
Here is the code in PhpStorm if you prefer :
Thanks for your help!
Finally I found the problem!! FOSRestBundle have a conflict with FOSUserBundle. If I disable RestBundle in config.yml, all works!!
So, I just move my API bundle in another symfony project. One project for my API and one project for my site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With