/**
  * @return array
  */
 public function getRoles()
 {
     $roles = array();
     $rolesReadOnly = array();
     if (!$this->securityContext->getToken()) {
         return array($roles, $rolesReadOnly);
     }
     // get roles from the Admin classes
     foreach ($this->pool->getAdminServiceIds() as $id) {
         try {
             $admin = $this->pool->getInstance($id);
         } catch (\Exception $e) {
             continue;
         }
         $isMaster = $admin->isGranted('MASTER');
         $securityHandler = $admin->getSecurityHandler();
         // TODO get the base role from the admin or security handler
         $baseRole = $securityHandler->getBaseRole($admin);
         if (strlen($baseRole) == 0) {
             // the security handler related to the admin does not provide a valid string
             continue;
         }
         foreach ($admin->getSecurityInformation() as $role => $permissions) {
             $role = sprintf($baseRole, $role);
             if ($isMaster) {
                 // if the user has the MASTER permission, allow to grant access the admin roles to other users
                 $roles[$role] = $role;
             } elseif ($this->securityContext->isGranted($role)) {
                 // although the user has no MASTER permission, allow the currently logged in user to view the role
                 $rolesReadOnly[$role] = $role;
             }
         }
     }
     $isMaster = $this->securityContext->isGranted('ROLE_SUPER_ADMIN');
     // get roles from the service container
     foreach ($this->rolesHierarchy as $name => $rolesHierarchy) {
         if ($this->securityContext->isGranted($name) || $isMaster) {
             $roles[$name] = $name . ': ' . implode(', ', $rolesHierarchy);
             foreach ($rolesHierarchy as $role) {
                 if (!isset($roles[$role])) {
                     $roles[$role] = $role;
                 }
             }
         }
     }
     return array($roles, $rolesReadOnly);
 }
Ejemplo n.º 2
0
 /**
  * Extract messages to MessageCatalogue.
  *
  * @return MessageCatalogue
  *
  * @throws \Exception|\RuntimeException
  */
 public function extract()
 {
     if ($this->catalogue) {
         throw new \RuntimeException('Invalid state');
     }
     $this->catalogue = new MessageCatalogue();
     foreach ($this->adminPool->getAdminServiceIds() as $id) {
         $admin = $this->getAdmin($id);
         $this->translator = $admin->getTranslator();
         $this->labelStrategy = $admin->getLabelTranslatorStrategy();
         $this->domain = $admin->getTranslationDomain();
         $admin->setTranslator($this);
         $admin->setSecurityHandler($this);
         $admin->setLabelTranslatorStrategy($this);
         //            foreach ($admin->getChildren() as $child) {
         //                $child->setTranslator($this);
         //            }
         // call the different public method
         $methods = array('getShow' => array(array()), 'getDatagrid' => array(array()), 'getList' => array(array()), 'getForm' => array(array()), 'getBreadcrumbs' => array(array('list'), array('edit'), array('create'), array('update'), array('batch'), array('delete')));
         if ($this->logger) {
             $this->logger->info(sprintf('Retrieving message from admin:%s - class: %s', $admin->getCode(), get_class($admin)));
         }
         foreach ($methods as $method => $calls) {
             foreach ($calls as $args) {
                 try {
                     call_user_func_array(array($admin, $method), $args);
                 } catch (\Exception $e) {
                     if ($this->logger) {
                         $this->logger->error(sprintf('ERROR : admin:%s - Raise an exception : %s', $admin->getCode(), $e->getMessage()));
                     }
                     throw $e;
                 }
             }
         }
     }
     $catalogue = $this->catalogue;
     $this->catalogue = false;
     return $catalogue;
 }
Ejemplo n.º 3
0
 public function testGetAdminServiceIds()
 {
     $this->pool->setAdminServiceIds(array('sonata.user.admin.group1', 'sonata.user.admin.group2', 'sonata.user.admin.group3'));
     $this->assertEquals(array('sonata.user.admin.group1', 'sonata.user.admin.group2', 'sonata.user.admin.group3'), $this->pool->getAdminServiceIds());
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     foreach ($this->pool->getAdminServiceIds() as $id) {
         $this->cache->load($this->pool->getInstance($id));
     }
 }