| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types = 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * /src/Controller/Profile/RolesController.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @author TLe, Tarmo Leppänen <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace App\Controller\Profile; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use App\Entity\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use App\Security\RolesService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Swagger\Annotations as SWG; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\HttpFoundation\JsonResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Routing\Annotation\Route; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * Class RolesController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @package App\Controller\Profile | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @author TLe, Tarmo Leppänen <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | class RolesController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private RolesService $rolesService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * RolesController constructor. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 31 | 12 |  |     public function __construct(RolesService $rolesService) | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 | 12 |  |         $this->rolesService = $rolesService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 12 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Endpoint action to get current user roles as an array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @Route( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      *     path="/profile/roles", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      *     methods={"GET"}, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      *  ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @Security("is_granted('IS_AUTHENTICATED_FULLY')") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @SWG\Parameter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      *      type="string", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      *      name="Authorization", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      *      in="header", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      *      required=true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      *      description="Authorization header", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      *      default="Bearer _your_jwt_here_", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      *  ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @SWG\Response( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      *      response=200, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      *      description="User roles", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      *      @SWG\Schema( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      *          type="array", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      *          @SWG\Items(type="string"), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      *      ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      *  ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @SWG\Response( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      *      response=401, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      *      description="Invalid token", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      *      @SWG\Schema( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      *          type="object", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      *          @SWG\Property(property="code", type="integer", description="Error code"), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      *          @SWG\Property(property="message", type="string", description="Error description"), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      *      ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      *      examples={ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      *          "Token not found": "{code: 401, message: 'JWT Token not found'}", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      *          "Expired token": "{code: 401, message: 'Expired JWT Token'}", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      *      }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      *  ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @SWG\Tag(name="Profile") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 5 |  |     public function __invoke(User $loggedInUser): JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 5 |  |         return new JsonResponse($this->rolesService->getInheritedRoles($loggedInUser->getRoles())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |  |