0

is it possible to check if user is authenticated to access the URl he requested. What I want to do is when user not logged in he can't see files by url.

example : => Screenshot

Any suggestions? Thank you

Update

this is my access control: All access working fine for my application

    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

    - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/login-check$, role: IS_AUTHENTICATED_ANONYMOUSLY }

    - { path: ^/admin/, role: [ROLE_USER] }
    - { path: ^/admin/rlsh/dashboard, role: IS_AUTHENTICATED_FULLY }
    - { path: ^/uploads/media, role: IS_AUTHENTICATED_FULLY }
    - { path: ^/profile/, role: IS_AUTHENTICATED_FULLY }
    - { path: ^/shop/basket/step/, role: IS_AUTHENTICATED_FULLY }
    - { path: ^/shop/user/, role: IS_AUTHENTICATED_FULLY }
    # - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
karim
  • 1
  • 2
  • Possible duplicate of [php restrict access to files in directory](https://stackoverflow.com/questions/19645196/php-restrict-access-to-files-in-directory) – Niels May 24 '18 at 15:05
  • thank u for quick response but i can't use my own access logic cause i have more than 50 bundles in my project and i can't go one by one and send a logic value to test with it i need something global and more secure – karim May 24 '18 at 15:23
  • What is the difference between your `admin` and `main` firewalls ? Could you check your logs in debug mode (especially the security context) to have more informations of what is happening when requestinga media. Could you also add your `access_control` definition from the `security.yml`, maybe you have a definition overriding my answer suggestion :) – Mcsky May 25 '18 at 10:44
  • i add my access_control definition from the security.yml – karim May 25 '18 at 10:55
  • I don't understand the difference between the main and admin firewalls I don't see missconfiguration for what you're trying to do. To debug this you'll have to add the logs for a request to a media. Process as follow, from the root level of your project `echo '' > app/logs/dev.log`, then do a call to a media, and then run command: `cat app/logs/dev.log` and update the question with the output. Configure your monolog to the `debug` before doing it :) – Mcsky May 25 '18 at 11:58

1 Answers1

1

If you want the user to be connected to access to your files, you could use a simple access_control, please take a look

access_control:
    - { path: ^/uploads/media, role: IS_AUTHENTICATED_FULLY }

A not authenticated user trying to access to your files will get a 403 forbidden response.

Btw you can customize the path with a regex and many others things, feel free to take a look

Mcsky
  • 1,426
  • 1
  • 10
  • 20
  • Thank you for your answer but I already have This path in my security.yml – karim May 25 '18 at 09:43
  • So if you try to access a ressource without being authenticated you should receive a forbidden response. If not, could you please provide in your question the firewalls part of your `security.yml` configuration – Mcsky May 25 '18 at 10:07