1
votes

I'm beginning to use Symfony2 and I'm really enjoying it!

I have some questions for sure that you will help me easily!

When we use the security layer, the file security.yml we set the property access_control, usually something like this:

  • {Path: ^ / admin roles: ROLE_ADMIN}

Traditionally using php, my rule of access to the system I use 3 tables:

  • User - Users Table
  • Role - Roles Table
  • Resource - Resource Table
  • Permission - Grant Tables

Where, User has a role, and a permission is related to a role and a resource. To check whether the user has access to a resource, check the table permission.

Bringing Symfony2, the property "path" would be a resource and ROLE_ADMIN would be the role of the user.

How to do that security.yml, load the settings from the database. I searched the official documentation and found nothing.

For now, thanks

2

2 Answers

0
votes

Maybe you will find your answers here. It descripes how to load users from Database:

How to Load Security Users from the Database (the Entity Provider)

I would recommend to use FOSUserBundle. It is very easy to handle and helps you managing your Security in Symfony2

FOSUserBundle

Regards!

0
votes

Actually, the way to "read" the path (in the security.yml file) is:

- { path: ^/this/(path|regex|here)$, roles: {CAN_BE_ACCESED_ONLY, BY_THESE_ROLES} }

now, from where do you know which user has which role?

From wherever you load your users.

e.g.:

public function getRoles()
    {
        return array('ROLE_USER');
    }