security.yaml 6.68 KB
Newer Older
Julien Jorry committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# security:
#     # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
#     providers:
#         in_memory: { memory: ~ }
#     firewalls:
#         dev:
#             pattern: ^/(_(profiler|wdt)|css|images|js)/
#             security: false
#         main:
#             anonymous: true

#             # activate different ways to authenticate

#             # http_basic: true
#             # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate

#             # form_login: true
#             # https://symfony.com/doc/current/security/form_login_setup.html

#     # Easy way to control access for large sections of your site
#     # Note: Only the *first* access control that matches will be used
#     access_control:
#         # - { path: ^/admin, roles: ROLE_ADMIN }
#         # - { path: ^/profile, roles: ROLE_USER }

security:
    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email
        in_memory: { memory: ~ }
32 33 34 35
        entity_provider:
            entity:
                class: App\Entity\User
                property: username
36 37
        api_key_user_provider:
            id: App\Security\ApiKeyUserProvider
Julien Jorry committed
38 39 40 41 42
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        # -> custom firewall for the admin area of the URL
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        # admin:
        #     pattern:            /admin(.*)
        #     form_login:
        #         provider:       fos_userbundle
        #         login_path:     fos_user_security_login
        #         check_path:     /admin/login_check
        #         use_forward:    false
        #         failure_path:   null
        #         success_handler: redirect.after.login
        #     logout:
        #         path:           /admin/logout
        #         target:         /admin/login
        #     anonymous:          true
        #     switch_user:
        #         provider: fos_userbundle
        #     context: mlc_context
59
            # access_denied_handler: App\Security\AccessDeniedHandler
Julien Jorry committed
60
         # -> end custom configuration
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        
        # login:
        #     pattern:  ^/api/login
        #     stateless: true
        #     anonymous: true
        #     provider: api_key_user_provider
        #     form_login:
        #         check_path:               /api/login_check
        #         success_handler:          lexik_jwt_authentication.handler.authentication_success
        #         failure_handler:          lexik_jwt_authentication.handler.authentication_failure
        #         require_previous_session: false
        # api:
        #     pattern:  ^/api/
        #     stateless: true
        #     anonymous: true
        #     provider: api_key_user_provider
        #     guard:
        #         authenticators:
        #             - lexik_jwt_authentication.jwt_token_authenticator
        api:
            pattern:  ^/api
            stateless: true
            # can be set to false to disabled API doc available for anonymous user !
            anonymous: true
            guard:
                authenticators:
                    - App\Security\ApiKeyAuthenticator
                provider: api_key_user_provider
Julien Jorry committed
89 90 91 92 93 94 95 96 97 98
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                login_path: fos_user_security_login
                check_path: fos_user_security_check
                csrf_token_generator: security.csrf.token_manager
                success_handler: redirect.after.login
            logout:
                path: fos_user_security_logout
99
                target: index
Julien Jorry committed
100
            anonymous: true
101 102 103 104
            guard:
                authenticators:
                    - App\Security\EmailTokenAuthenticator
                provider: fos_userbundle
Julien Jorry committed
105 106 107 108 109 110 111
            remember_me:
                secret:         "%kernel.secret%"
                lifetime:       31536000
                path:           /
                domain:         ~
                user_provider:  fos_userbundle
                always_remember_me: true
Julien Jorry committed
112 113 114
            context: mlc_context
            switch_user:
                provider: fos_userbundle
115
            # access_denied_handler: App\Security\AccessDeniedHandler
116
       
Julien Jorry committed
117
    encoders:
118 119 120 121 122 123
        # FOS\UserBundle\Model\UserInterface: bcrypt
        FOS\UserBundle\Model\UserInterface:
            # Use native password encoder
            # This value auto-selects the best possible hashing algorithm
            # (i.e. Sodium when available).
            algorithm: auto
Julien Jorry committed
124 125

    role_hierarchy:
126
        ROLE_API:               ROLE_USER
Julien Jorry committed
127 128
        ROLE_ADHERENT:          ROLE_USER
        ROLE_PRESTATAIRE:       ROLE_USER
129 130 131 132 133 134 135
        ROLE_ADMIN_SIEGE:       [ROLE_USER, ROLE_ADMIN]
        ROLE_REDACTEUR:         [ROLE_USER, ROLE_ADMIN]
        ROLE_TRESORIER:         [ROLE_USER, ROLE_ADMIN]
        ROLE_CONTROLEUR:        [ROLE_USER, ROLE_ADMIN]
        ROLE_GESTION_GROUPE:    [ROLE_USER, ROLE_ADMIN]
        ROLE_COMPTOIR:          [ROLE_USER, ROLE_ADMIN]
        ROLE_CONTACT:           [ROLE_USER, ROLE_ADMIN]
Julien Jorry committed
136
        ROLE_ADMIN:             [ROLE_USER, ROLE_SONATA_ADMIN]
137
        ROLE_SUPER_ADMIN:       [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH, ROLE_API]
Julien Jorry committed
138 139 140 141

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    access_control:
142 143 144
        # 
        # @TODO : better access control !
        # 
Julien Jorry committed
145
        # Admin login page needs to be accessed without credential
146 147 148 149
        # - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # - { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # - { path: ^/admin/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
Julien Jorry committed
150 151 152 153 154 155
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # Secured part of the site
        # This config requires being logged for the whole site and having the admin role for the admin part.
        # Change these rules to adapt them to your needs
Julien Jorry committed
156 157
        # - { path: ^/admin/, role: [ROLE_SUPER_ADMIN, ROLE_SONATA_ADMIN, ROLE_ADMIN_SIEGE, ROLE_REDACTEUR, ROLE_TRESORIER, ROLE_CONTROLEUR, ROLE_GESTION_GROUPE, ROLE_COMPTOIR, ROLE_CONTACT] }
        - { path: ^/admin/, role: [ROLE_ADMIN] }
158 159
        # Bottom line can be uncommented to disabled API doc available for anonymous user !
        # - { path: '^/api', roles: ROLE_API }
Julien Jorry committed
160 161
        - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }