/** * * @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()); } }
/** * @return User */ public function getUser() { if (null === ($token = $this->securityContext->getToken())) { return null; } if (!is_object($user = $token->getUser())) { return null; } return $user; }
/** * 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()); } }
/** * Method actually invoked upon dispatching an event "kernel.response" * * @param FilterResponseEvent $event * * @return void */ public function onKernelRequest(GetResponseEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } $token = $this->securityContext->getToken(); if ($token instanceof UsernamePasswordToken and $token->isAuthenticated()) { $user = $token->getUser(); $user->setLastActive(new \DateTime(date('Y-m-d H:i:s', time()))); $this->entityManager->persist($user); $this->entityManager->flush(); } }
/** * Gets the list of current votes on this object by the current user * * @param Member $user * * @return ArrayList */ public function currentVotesByUser($user = null) { if (!$user) { $user = $this->securityContext->getMember(); } $votes = MicroPostVote::get()->filter(array('UserID' => $user->ID, 'PostID' => $this->ID)); return $votes->toArray(); }
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; }
/** * Lookup files that you have uploaded * * @param string $fileId */ public function fileLookup($fileId) { $member = $this->securityContext->getMember(); if (!$member) { return; } $file = File::get()->filter(array('ID' => $fileId, 'OwnerID' => $member->ID))->first(); if ($file && $file->ID) { return array('Title' => $file->Title, 'Link' => $file->getAbsoluteURL(), 'IsImage' => $file instanceof Image, 'ID' => $file->ID); } }
public function UserFeed() { if (!$this->securityContext->getMember()) { // return; } $id = $this->ViewingUserID(); if ($id) { $user = DataObject::get_by_id('Member', $id); if ($user && $user->exists()) { $data = $this->microBlogService->getStatusUpdates($user); } } else { if ($this->securityContext->getMember()) { $data = $this->microBlogService->getTimeline($this->securityContext->getMember()); } } return $data; }