Bonjour je suis noviste sur symfony et je developpe une application sur symfony3 j'ai besoin d'aide mais surtout d'eclaircissement concernant l'access control j'ai fait un handler pour la redirection après login et ça marche bien mais l'ennuie est que mon acces est non autoriser " access denied"
voici mon handler
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 <?php namespace AppBundle\Listener; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; /** * Class AfterLoginRedirection * * @package AppBundle\AppListener */ class AfterLoginRedirection implements AuthenticationSuccessHandlerInterface { private $router; /** * AfterLoginRedirection constructor. * * @param RouterInterface $router */ public function __construct(RouterInterface $router) { $this->router = $router; } /** * @param Request $request * * @param TokenInterface $token * * @return RedirectResponse */ public function onAuthenticationSuccess(Request $request, TokenInterface $token) { $roles = $token->getRoles(); $rolesTab = array_map(function ($role) { return $role->getRole(); }, $roles); if (in_array('ROLE_SUPER_USER', $rolesTab, true)) { // c'est un aministrateur : on le rediriger vers l'espace admin $redirection = new RedirectResponse($this->router->generate('human_admin')); } else if (in_array('ROLE_CHEF_ENTREPRISE', $rolesTab, true)) { // c'est un aministrateur : on le rediriger vers l'espace admin $redirection = new RedirectResponse($this->router->generate('human_entreprise_sira')); } else { // c'est un utilisaeur lambda : on le rediriger vers l'accueil $redirection = new RedirectResponse($this->router->generate('human_candidat_offre_liste')); } return $redirection; } }
et voici mon security.yml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44 # To get started with security, check out the documentation: # https://symfony.com/doc/current/security.html security: encoders: FOS\UserBundle\Model\UserInterface: bcrypt role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: ROLE_ADMIN providers: fos_userbundle: id: fos_user.user_provider.username firewalls: main: pattern: ^/ form_login: provider: fos_userbundle login_path: /login default_target_path: /human/admin csrf_token_generator: security.csrf.token_manager success_handler: redirect.after.login logout: path: fos_user_security_logout target: /human anonymous: true access_control: - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register/candidat, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/candidat, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/human/admin, role: ROLE_SUPER_USER } - { path: ^/human/candidat/espace, role: ROLE_CANDIDAT} - { path: ^/human/entreprise/espace, role: ROLE_SUPER_USER } - { path: ^/human/entreprise/espace, role: ROLE_CHEF_ENTREPRISE } - { path: ^/human/entreprise, role: ROLE_SUPER_USER } - { path: ^/human/entreprise/sira, role: ROLE_CHEF_ENTREPRISE } - { path: ^/human/admin, role: ROLE_ADMIN} - { path: ^/human/candidat/espace, role: ROLE_SUPER_USER } - { path: ^/human/candidat/espace, role: ROLE_ADMIN }
Question : est ce parce que une pages ne peu pas etre acceder pas deux roles ?
merci d'avance pour votre aide
Partager