Symfony security access_control syntax - symfony

I currently have the below code, which does pretty much what I want.
There's just a few things I don't understand.
What's the ^/ in front of each path?
What's the $ behind ^/login?
Why do I get redirected to the login page when I don't have access to a page? Where do I set this up or change this?
Is there an easy way to grant access to my frontpage (/) while requiring users to be logged in to access any other page (except for the login/register pages)?
Should I use IS_AUTHENTICATED_FULLY or ROLE_USER?
Can't find any clear info on the subject either ...
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 }
- { path: ^/, role: IS_ATHENTICATED_FULLY }

Regarding ^ and $
^ = start of the string
$ = end of string
https://en.wikipedia.org/wiki/Regular_expression#Delimiters
IS_AUTHENTICATED_FULLY or ROLE_USER:
You can't compare these 2 directly. You could be authenticated fully and not have the role user.
IS_AUTHENTICATED_FULLY only means that you're not logged in through the remember_me mechanism in this session but actively entered your password.
It does not however check which role the logged in user is granted.
More here:
http://symfony.com/doc/current/security.html#checking-to-see-if-a-user-is-logged-in-is-authenticated-fully
Is there an easy way to grant access to my frontpage (/) while requiring users to be logged in to access any other page (except for the login/register pages)?
Try:
access_control:
- { path: ^/$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/*, role: IS_AUTHENTICATED_FULLY }

Related

In Symfony 3.4.11, I get a crash after adding access control

enter image description hereHere is my security.yml:
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
Here is my error:
It says the YAML file is not valid. How can I proceed?
Yml file should be indented correctly.
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }

Symfony access control

I want to authorize the access to only one ip to my API. But even if I write it in the access_control from my security.yml file, it seem to not work.
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 }
- { path: ^/administration, role: ROLE_ADMIN}
- { path: ^/api, role: IS_AUTHENTICATED_ANONYMOUSLY, ip: 527.0.2.1 }
The route I would like to block is all coming after ^/api/*
Thank for helping.
You can try this
access_control:
#
- { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
- { path: ^/api, roles: ROLE_NO_ACCESS }
Replace 127.0.0.1 with your IP
Read Official doc Symfony Matching access_control By IP

Symfony 2 fosuserbundle logout

here's my problem i have 2 pages : index page when i'm not connected and an index page when i'm connected so when i'm connected and i try to type the url path of the index page when i'm not connected i find myself disconnected and on the page index when i'm not logged in
i'm using fosuserbundle and here's 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 }
need help thanks

how to authenticate ROLE_USER and ROLE_ADMIN separately in fos userbundle

I have made two different login section in my website, one for admin section and another for frontend users.
When I logged into to frontend it logged in. The problem is that when i try to login the admin section it throws access denied error.
Is it possible make two different login sessions so that both login session are independent of eachother
you don't show security.yml, so no way to know for sure:
try deleting this row:
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
but most likely you have something like this in your security.yml
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 }
- { path: ^/, role: ROLE_USER }
and your login page is on url /admin/login/
so it requires ROLE_ADMIN to access login page, before you can login as admin

Problems with page resources using FOSUserBundle

I would like to have the whole page access enabled only if user logged in (except the FOS user login page)
This is how I set the access control:
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_ADMIN }
But the problem is as it now blocks all my scripts. CSS and JS are not available, so login page is not styled! If I remove:
- { path: ^/, role: ROLE_ADMIN }
From the access control everything is OK and the login page is styled. Any help on how to put the whole page under "lockdown" (except the login page) but still have the styles displayed (CSS)?
The paths to your js, css and bundles directories are being caught by your access control that is stating that the user must be ROLE_ADMIN. To sort this you can just add rules for these directories above the ^/ rule using IS_AUTHENTICATED_ANONYMOUSLY like..
access_control:
- { path: ^/css, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/js, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/bundles, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_ADMIN }

Resources