Exemplo n.º 1
0
 /**
  *
  * @param type $entityName
  * @return type 
  */
 public function get($class, $mapping)
 {
     $this->init();
     $fields = array();
     foreach ($this->config[$class]['fields'] as $group => $roleFields) {
         if ($group == 'default') {
             continue;
         }
         // backward compability
         if ($group == 'admin') {
             $group = 'role_admin';
         }
         if (strpos($group, "role") === false) {
             continue;
         }
         if ($this->security->isGranted(strtoupper($group))) {
             // add role fields if configuration has them
             $fields = array_merge($fields, $roleFields);
         }
     }
     if ($mapping != self::DEFAULT_FIELD_GROUP) {
         $fields = array_merge($fields, $this->getGroup($class, $mapping));
     }
     $fields = array_merge($fields, $this->getGroup($class, self::DEFAULT_FIELD_GROUP));
     return $fields;
 }
 /**
  * Assigns the currently logged in user to a Comment.
  *
  * @param  \FOS\CommentBundle\Event\CommentEvent $event
  * @return void
  */
 public function blame(CommentEvent $event)
 {
     $comment = $event->getComment();
     if (null === $this->securityContext) {
         if ($this->logger) {
             $this->logger->debug("Comment Blamer did not receive the security.context service.");
         }
         return;
     }
     if (!$comment instanceof SignedCommentInterface) {
         if ($this->logger) {
             $this->logger->debug("Comment does not implement SignedCommentInterface, skipping");
         }
         return;
     }
     if (null === $this->securityContext->getToken()) {
         if ($this->logger) {
             $this->logger->debug("There is no firewall configured. We cant get a user.");
         }
         return;
     }
     if (null === $comment->getAuthor() && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $comment->setAuthor($this->securityContext->getToken()->getUser());
     }
 }
 /**
  * Assigns the currently logged in user to a Comment.
  *
  * @throws InvalidArgumentException when the Comment is not a SignedCommentInterface
  * @param CommentInterface $comment
  * @return void
  */
 public function blame(CommentInterface $comment)
 {
     if (!$comment instanceof SignedCommentInterface) {
         throw new InvalidArgumentException('The comment must implement SignedCommentInterface');
     }
     if (null === $this->securityContext->getToken()) {
         throw new RuntimeException('You must configure a firewall for this route');
     }
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $comment->setAuthor($this->securityContext->getToken()->getUser());
     }
 }
Exemplo n.º 4
0
 public function hasRouteAccess($routeName)
 {
     $token = $this->securityContext->getToken();
     if ($token->isAuthenticated()) {
         $route = $this->router->getRouteCollection()->get($routeName);
         $controller = $route->getDefault('_controller');
         list($class, $method) = explode('::', $controller, 2);
         $metadata = $this->getMetadata($class);
         if (!isset($metadata->methodMetadata[$method])) {
             return false;
         }
         foreach ($metadata->methodMetadata[$method]->roles as $role) {
             if ($this->securityContext->isGranted($role)) {
                 return true;
             }
         }
     }
     return false;
 }