Bonsoir,

Je me suis lancé dans la configuration et l'utilisation des ACL, jusque là pas de soucis j'arrive à créer mes ACL et attribuer des ACE sans problème.

La question que je me pose c'est comment ça se passe ensuite ? En effet, si je crée un MaskBuilder avec les droits (view, edit, delete) à son créateur.

Comment moi administrateur, aurais-je accès à son objet, comment puis-je le modifier ou le supprimer ? A quel moment et comment dois-je m'attribuer les droits sur son objet ?

Ci-dessous mon action de création d'un joueur :

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
    /**
     * Create Player action
     * @Secure(roles="ROLE_USER")
     */
    public function createPlayerAction()
    {
        // Instance a new Player
        $player = new Player;
 
        // Instance a new form PlayerType
        $form = $this->createForm(new PlayerType, $player);
 
        // Get the request
        $request = $this->get('request');
 
        // If the request method is POST
        if ($request->getMethod() == 'POST')
        {
            // Bind the request to the form
            $form->bind($request);
 
            // if the form is valid
            if ($form->isValid())
            {
                // Get current User
                $user = $this->get('security.context')->getToken()->getUser();
                $player->setUser($user);
 
                // Persist and save the Player
                $em = $this->getDoctrine()->getManager();
                $em->persist($player);
                $em->flush();
 
                // ACL creation
                $aclProvider = $this->get('security.acl.provider');
                $objectIdentity = objectIdentity::fromDomainObject($player);
                $acl = $aclProvider->createAcl($objectIdentity);
 
                // Get the security identity from the User
                $securityIdentity = new UserSecurityIdentity($user->getUsername(), 'Sac\UserBundle\Entity\User');
 
                // Create the MaskBuilder
                $builder = new MaskBuilder;
                $builder
                    ->add('view')
                    ->add('edit')
                    ->add('delete');
 
                $mask = $builder->get();
 
                // Give access to the owner
                $acl->insertObjectAce($securityIdentity, $mask);
                $aclProvider->updateAcl($acl);
 
                $this->get('session')->getFlashBag()->add('notice', 'Votre joueur a bien été crée');
 
                return $this->redirect($this->generateUrl('SacSiteBundle_index'));
            }
        }
 
        return $this->render('SacAppBundle:App:create_player.html.twig', array('form' => $form->createView()));
    }
J'ai contourné le problème, mais je ne pense pas que se soit la bonne méthode à adopter. J'ai crée donc mon Player avec un utilisateur Test sur lequel j'ai mis les droits view, edit, delete sur le Player.

Et sur mon editAction je fais comme ceci :

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
65
66
67
68
69
    /**
     * Edit Player action
     * @Secure(roles="ROLE_USER")
     */
    public function editPlayerAction(Player $player)
    {
        $securityContext = $this->get('security.context');
 
        if ($securityContext->isGranted('ROLE_ADMIN'))
        {
            // Instance a new form PlayerEditType
            $form = $this->createForm(new PlayerEditType, $player);
 
            // Get the request
            $request = $this->get('request');
 
            // If the request method is POST
            if ($request->getMethod() == 'POST')
            {
                // Bind the request to the form
                $form->bind($request);
 
                // if the form is valid
                if ($form->isValid())
                {
                    $em = $this->getDoctrine()->getManager();
                    $em->flush();
 
                    $this->get('session')->getFlashBag()->add('notice', 'Votre joueur a bien été édité');
 
                    return $this->redirect($this->generateUrl('SacSiteBundle_index'));
                }
            }
 
            return $this->render('SacAppBundle:App:edit_player.html.twig', array('form' => $form->createView()));
        }
 
        // Check for edit access
        if (false === $securityContext->isGranted('EDIT', $player))
        {
            throw new AccessDeniedException();
        }
 
        // Instance a new form PlayerEditType
        $form = $this->createForm(new PlayerEditType, $player);
 
        // Get the request
        $request = $this->get('request');
 
        // If the request method is POST
        if ($request->getMethod() == 'POST')
        {
            // Bind the request to the form
            $form->bind($request);
 
            // if the form is valid
            if ($form->isValid())
            {
                $em = $this->getDoctrine()->getManager();
                $em->flush();
 
                $this->get('session')->getFlashBag()->add('notice', 'Votre joueur a bien été édité');
 
                return $this->redirect($this->generateUrl('SacSiteBundle_index'));
            }
        }
 
        return $this->render('SacAppBundle:App:edit_player.html.twig', array('form' => $form->createView()));
    }
Par ce biais, mon ADMIN à accès en édition mais je trouve cela relativement lourd ... Est-ce la bonne méthode ? Dois-je faire autrement ?

Merci d'avance.