当前位置: 首页>>代码示例>>PHP>>正文


PHP SecurityContext::isGranted方法代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\SecurityContext::isGranted方法的典型用法代码示例。如果您正苦于以下问题:PHP SecurityContext::isGranted方法的具体用法?PHP SecurityContext::isGranted怎么用?PHP SecurityContext::isGranted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Security\Core\SecurityContext的用法示例。


在下文中一共展示了SecurityContext::isGranted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onFilterController

 public function onFilterController(FilterControllerEvent $event)
 {
     list($object, $method) = $event->getController();
     // the controller could be a proxy
     $className = ClassUtils::getClass($object);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionMethod = $reflectionClass->getMethod($method);
     $allControllerAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass);
     $allMethodAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod);
     $guardAnnotationsFilter = function ($annotation) {
         return $annotation instanceof Guard;
     };
     $controllerGuardAnnotations = array_filter($allControllerAnnotations, $guardAnnotationsFilter);
     $methodGuardAnnotations = array_filter($allMethodAnnotations, $guardAnnotationsFilter);
     $guardAnnotations = array_merge($controllerGuardAnnotations, $methodGuardAnnotations);
     $permissions = [];
     foreach ($guardAnnotations as $guardAnnotation) {
         $value = $guardAnnotation->value;
         if (!is_array($value)) {
             $value = [$value];
         }
         $permissions = array_merge($value, $permissions);
     }
     $permissions = array_unique($permissions);
     if (!empty($permissions) && !$this->security->isGranted($permissions)) {
         $e = new PermissionRequiredException();
         $e->setRequiredPermissions($permissions)->setCurrentPermissions($this->security->getToken()->getUser()->getPermissions());
         throw $e;
     }
 }
开发者ID:ymarillet,项目名称:sknife,代码行数:30,代码来源:ControllerListener.php

示例2: avoidIncorrectVoting

 /**
  * Listener for comments' votes persistence to avoid voting for own comments
  * and multiple voting for comments
  *
  * @param VotePersistEvent $event
  * @return void
  */
 public function avoidIncorrectVoting(VotePersistEvent $event)
 {
     try {
         if (!$this->context->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)) {
             throw new \Exception('Avoid voting if user is not authenticated');
         }
         /** @var $vote SignedVoteInterface */
         $vote = $event->getVote();
         /** @var $user User */
         $user = $this->context->getToken()->getUser();
         if ($vote->getVoter() !== $user) {
             throw new \Exception('Attempt to vote for different user');
         }
         if ($vote->getComment()->getAuthor() === $user) {
             throw new \Exception('Attempt to vote for own comment');
         }
         $existingVote = $this->voteManager->findVoteBy(array('comment' => $vote->getComment(), 'voter' => $user));
         if ($existingVote) {
             throw new \Exception('Attempt to vote multiple times for same comment');
         }
     } catch (\Exception $e) {
         $event->abortPersistence();
         $event->stopPropagation();
     }
 }
开发者ID:sopinet,项目名称:timeline-bundle,代码行数:32,代码来源:CommentVotePersistenceListener.php

示例3: contentBlock

 /**
  * @param string $blockName
  * @param array  $options
  * @param string $default
  * @return string
  */
 public function contentBlock($blockName, $options = array(), $default = null)
 {
     $em = $this->doctrine->getManager();
     $repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock');
     $contentBlock = $repository->findOneByName($blockName);
     $tag = isset($options['tag']) ? $options['tag'] : 'div';
     $attr = isset($options['attr']) ? $options['attr'] : array();
     if (isset($options['class'])) {
         $attr['class'] = $options['class'];
     }
     if (isset($options['href'])) {
         $attr['href'] = $options['href'];
     }
     if (!$contentBlock) {
         $contentBlock = new ContentBlock();
         $contentBlock->setName($blockName);
         $contentBlock->setBody($default ? $default : $blockName);
         $em->persist($contentBlock);
         $em->flush();
     }
     $contentEditable = '';
     $dataBlockName = '';
     $isEditable = $this->request && $this->request->get('contenteditable') && $this->securityContext->isGranted('ROLE_ADMIN');
     if ($isEditable) {
         $contentEditable = ' contenteditable="true"';
         $dataBlockName = ' data-block-name="' . $blockName . '"';
         $attr['class'] = isset($attr['class']) ? $attr['class'] . ' js-content-block' : 'js-content-block';
     }
     $attrParts = array();
     foreach ($attr as $attrName => $value) {
         $attrParts[] = sprintf('%s="%s"', $attrName, $value);
     }
     return '<' . $tag . ' ' . implode(' ', $attrParts) . ' ' . $contentEditable . $dataBlockName . '>' . $contentBlock->getBody() . '</' . $tag . '>';
 }
开发者ID:glavweb,项目名称:GlavwebContentBlockBundle,代码行数:40,代码来源:ContentBlockExtension.php

示例4: onSecurityInteractiveLogin

 /**
  * Do the magic.
  *
  * @param InteractiveLoginEvent $event
  */
 public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
 {
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         // user has just logged in
     }
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         // user has logged in using remember_me cookie
     }
     // do some other magic here
     $session = $event->getRequest()->getSession();
     $referrer = $session->get('referrer');
     if (empty($referrer)) {
         $referrer = $event->getRequest()->getUri();
     }
     $user = $event->getAuthenticationToken()->getUser();
     $log = new Log();
     $log->setIdUsuario($user);
     $log->setDtAcao(new \DateTime());
     $log->setNmTabela('acesso');
     $log->setCsAcao('ACE');
     $log->setTeIpOrigem($event->getRequest()->getClientIp());
     $log->setNmScript($referrer);
     // Registra login
     $this->em->persist($log);
     $this->em->flush();
     // TODO: Redireciona para útima página visitada
 }
开发者ID:mithilpatel07,项目名称:cacic,代码行数:32,代码来源:LoginListener.php

示例5: getUserPermissions

 /**
  * Gets permissions of the given user
  *
  * @param User          $user
  * @param Criteria|null $filters
  *
  * @return array
  */
 public function getUserPermissions(User $user, Criteria $filters = null)
 {
     $entityAclExtension = $this->aclSelector->select($user);
     $resources = array_map(function (AclClassInfo $class) use($entityAclExtension) {
         return ['type' => $entityAclExtension->getExtensionKey(), 'resource' => $class->getClassName()];
     }, $entityAclExtension->getClasses());
     if ($filters) {
         $collection = new ArrayCollection($resources);
         $resources = $collection->matching($filters)->toArray();
     }
     $result = [];
     $originalToken = $this->impersonateUser($user);
     try {
         foreach ($resources as $resource) {
             $oid = new ObjectIdentity($resource['type'], $resource['resource']);
             $permissions = [];
             foreach ($entityAclExtension->getAllowedPermissions($oid) as $permission) {
                 if ($this->securityContext->isGranted($permission, $oid)) {
                     $permissions[] = $permission;
                 }
             }
             $result[] = array_merge($resource, ['permissions' => $permissions]);
         }
         $this->undoImpersonation($originalToken);
     } catch (\Exception $e) {
         $this->undoImpersonation($originalToken);
         throw $e;
     }
     return $result;
 }
开发者ID:Maksold,项目名称:platform,代码行数:38,代码来源:UserPermissionApiEntityManager.php

示例6: build

 /**
  * Construit le menu supplémentaire de la gestion des services du serveur
  * 
  * @param SidebarItem $sidebar Sidebar d'origine à completer
  */
 public function build(SidebarItem $sidebar)
 {
     if (!$this->context->isGranted('ROLE_SUPER_ADMIN')) {
         return;
     }
     $server = $sidebar->addChild('olix_server', array('label' => 'Gestion du serveur', 'icon' => 'fa fa-server fa-fw'));
     $server->addChild('olix_server_monit', array('label' => 'Gestion des services', 'icon' => 'fa fa-circle fa-fw', 'route' => 'olix_server_monit'));
     $server->addChild('olix_server_collectd', array('label' => 'Monitoring', 'icon' => 'fa fa-area-chart fa-fw', 'route' => 'olix_server_collectd'));
 }
开发者ID:sabinus52,项目名称:OlixServerBundle,代码行数:14,代码来源:ServerSidebar.php

示例7: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('grid', 'enhavo_grid', array('label' => 'form.label.content', 'translation_domain' => 'EnhavoAppBundle'));
     if ($this->securityContext->isGranted('WORKFLOW_ACTIVE', $this->dataClass)) {
         $entityName = array();
         $entityName[0] = $this->dataClass;
         $builder->add('workflow_status', 'enhavo_workflow_status', array('label' => 'workflow.form.label.next_state', 'translation_domain' => 'EnhavoWorkflowBundle', 'attr' => $entityName));
     }
 }
开发者ID:enhavo,项目名称:enhavo,代码行数:9,代码来源:PageType.php

示例8: onSecurityInteractiveLogin

 /**
  * Do the magic.
  *
  * @param InteractiveLoginEvent $event
  */
 public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
 {
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         $user = $this->securityContext->getToken()->getUser();
         if ($user instanceof User) {
             $user->setLastLoginAt(new DateTime());
             $this->em->persist($user);
             $this->em->flush($user);
         }
     }
 }
开发者ID:mishki-svami,项目名称:pa-core,代码行数:16,代码来源:LoginListener.php

示例9: setDefaultOptions

 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $choices = [];
     if ($this->context->isGranted(User::ROLE_SUPER_ADMIN)) {
         $choices = $this->repository->findAll();
     } else {
         $groups = $this->groupResolver->getAccessibleGroupsId();
         $choices = $this->repository->findByGroups($groups);
     }
     $resolver->setDefaults(array('label' => 'game.selectMachine', 'class' => 'DPMachineBundle:Machine', 'choices' => $choices));
 }
开发者ID:Onneil,项目名称:dedipanel,代码行数:14,代码来源:MachineEntityType.php

示例10: checkAction

 /**
  * @Route("/check", name="check_oauth")
  * Cette action vérifie que l'utilisateur a remplis son inscription et que le compte est actif.
  */
 public function checkAction()
 {
     $this->securityContext = $this->get('security.context');
     $this->token = $this->securityContext->getToken();
     if (!$this->securityContext->isGranted('ROLE_ORGA')) {
         // Si l'utilisateur ne s'est pas enregistré
         return $this->redirect($this->generateUrl("register_oauth"));
     } else {
         return $this->redirect($this->generateUrl("base_accueil"));
     }
 }
开发者ID:PhilippeGeek,项目名称:PHPM,代码行数:15,代码来源:OAuthController.php

示例11: checkAnyRole

 /**
  * @param array $roles
  * @return bool
  */
 public function checkAnyRole(array $roles)
 {
     if ($this->securityContext->isGranted('ROLE_SUPER_ADMIN')) {
         return true;
     }
     foreach ($roles as $role) {
         if ($this->securityContext->isGranted($role)) {
             return true;
         }
     }
     return false;
 }
开发者ID:Exanrus,项目名称:crm-bundle,代码行数:16,代码来源:PermissionManager.php

示例12: onSlugSecurityEvent

 /**
  *
  */
 public function onSlugSecurityEvent()
 {
     $node = $this->request->attributes->get('_nodeTranslation')->getNode();
     /* @var SecurityContextInterface $securityContext */
     if (false === $this->securityContext->isGranted(PermissionMap::PERMISSION_VIEW, $node)) {
         throw new AccessDeniedException('You do not have sufficient rights to access this page.');
     }
     $locale = $this->request->attributes->get('_locale');
     $preview = $this->request->attributes->get('preview');
     $nodeMenu = new NodeMenu($this->em, $this->securityContext, $this->acl, $locale, $node, PermissionMap::PERMISSION_VIEW, $preview);
     $this->request->attributes->set('_nodeMenu', $nodeMenu);
 }
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:15,代码来源:SlugSecurityListener.php

示例13: createUserMenu

 /**
  * @param Request $request
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function createUserMenu(Request $request)
 {
     $menu = $this->factory->createItem('user');
     if (false === $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         $menu->addChild('login', ['route' => 'fos_user_security_login', 'label' => $this->translator->trans('login', [], 'menu')]);
     } else {
         $user = $this->securityContext->getToken()->getUser();
         $currentUserMenu = $menu->addChild('current_user', ['label' => $user->getUsername()]);
         $currentUserMenu->addChild('profile', ['route' => 'fos_user_profile_show', 'label' => '.icon-user ' . $this->translator->trans('profile', [], 'menu')]);
         $currentUserMenu->addChild('logout', ['route' => 'fos_user_security_logout', 'label' => '.icon-off ' . $this->translator->trans('logout', [], 'menu')]);
     }
     return $menu;
 }
开发者ID:puterakahfi,项目名称:certificationy-web-platform,代码行数:18,代码来源:UserBuilder.php

示例14: onSecurityInteractiveLogin

 /**
  * Do the magic.
  * 
  * @param InteractiveLoginEvent $event
  */
 public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
 {
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         // user has just logged in
     }
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         // user has logged in using remember_me cookie
     }
     // do some other magic here
     $user = $event->getAuthenticationToken()->getUser();
     // ...
     $this->getUserService()->markLoginInfo();
 }
开发者ID:ccq18,项目名称:EduSoho,代码行数:18,代码来源:LoginSuccessHandler.php

示例15: createMainMenu

 /**
  * @TODO: Move below to config
  *
  * @param Request $request
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function createMainMenu(Request $request)
 {
     $menu = $this->factory->createItem('root');
     $menu->setChildrenAttributes(array('class' => 'navbar-nav nav'));
     $menu->addChild('nav.home', array('route' => 'quickstart_app_homepage'));
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         $menu->addChild($this->securityContext->getToken()->getUser()->getEmail(), array('route' => 'quickstart_app_account'));
         $menu->addChild('nav.logout', array('route' => 'fos_user_security_logout'));
     } else {
         $menu->addChild('nav.register', array('route' => 'fos_user_registration_register'));
         $menu->addChild('nav.login', array('route' => 'fos_user_security_login'));
     }
     return $menu;
 }
开发者ID:mseshachalam,项目名称:quick-up,代码行数:21,代码来源:MenuBuilder.php


注:本文中的Symfony\Component\Security\Core\SecurityContext::isGranted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。