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


PHP SecurityContextInterface::isGranted方法代码示例

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


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

示例1: isGranted

    public function isGranted($route = "ibrows_simple_cms_content", $parameters=array()) {
        
        
    
        
   
        try {
            if (false === $this->securityContext->isGranted($this->globalRole)) {
                return false;
            }
        }  catch (AuthenticationCredentialsNotFoundException $e){
            return true;
        }
        if(isset($parameters['type']) && key_exists($parameters['type'], $this->securityMap)){
            $roles = $this->securityMap[$parameters['type']];             
            foreach($roles as $roletype => $role){              
                if(stripos($route, $roletype) !== false || $roletype == 'general') {                    
                    if(false === $this->securityContext->isGranted($role)){
                        return false;
                    }
                    
                }
            }            
        }
        

        
        
        return true;
        
    }
开发者ID:JackJones,项目名称:IbrowsSimpleCMSBundle,代码行数:31,代码来源:SecurityHandler.php

示例2: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
         // don't do anything if it's not the master request
         return;
     }
     $token = $this->context->getToken();
     if (is_null($token)) {
         return;
     }
     $_route = $event->getRequest()->attributes->get('_route');
     if ($this->context->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         if (!$token->getUser() instanceof PersonInterface) {
             // We don't have a PersonInterface... Nothing to do here.
             return;
         }
         if ($_route == 'lc_home' || $_route == 'fos_user_security_login') {
             $key = '_security.main.target_path';
             #where "main" is your firewall name
             //check if the referer session key has been set
             if ($this->session->has($key)) {
                 //set the url based on the link they were trying to access before being authenticated
                 $url = $this->session->get($key);
                 //remove the session key
                 $this->session->remove($key);
             } else {
                 $url = $this->router->generate('lc_dashboard');
             }
             $event->setResponse(new RedirectResponse($url));
         } else {
             $this->checkUnconfirmedEmail();
         }
     }
 }
开发者ID:hacklabr,项目名称:login-cidadao,代码行数:34,代码来源:LoggedInUserListener.php

示例3: blame

 /**
  * Assigns the Security token's user to the vote.
  *
  * @param  VoteEvent $vote
  * @return void
  */
 public function blame(VoteEvent $event)
 {
     $vote = $event->getVote();
     if (null === $this->securityContext) {
         if ($this->logger) {
             $this->logger->debug("Vote Blamer did not receive the security.context service.");
         }
         return;
     }
     if (!$vote instanceof SignedVoteInterface) {
         if ($this->logger) {
             $this->logger->debug("Vote does not implement SignedVoteInterface, 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 ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $vote->setVoter($this->securityContext->getToken()->getUser());
     }
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:31,代码来源:VoteBlamerListener.php

示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('gridName', 'hidden', ['required' => false])->add('entityClass', 'hidden', ['required' => false])->add('entityId', 'hidden', ['required' => false])->add('from', 'oro_email_email_address_from', ['required' => true, 'label' => 'oro.email.from_email_address.label', 'attr' => ['class' => 'from taggable-field']])->add('to', 'oro_email_email_address_recipients', ['required' => false, 'attr' => ['class' => 'taggable-field forged-required']])->add('cc', 'oro_email_email_address_recipients', ['required' => false, 'attr' => ['class' => 'taggable-field']])->add('bcc', 'oro_email_email_address_recipients', ['required' => false, 'attr' => ['class' => 'taggable-field']])->add('subject', 'text', ['required' => true, 'label' => 'oro.email.subject.label'])->add('body', 'oro_resizeable_rich_text', ['required' => false, 'label' => 'oro.email.email_body.label'])->add('template', 'oro_email_template_list', ['label' => 'oro.email.template.label', 'required' => false, 'depends_on_parent_field' => 'entityClass', 'configs' => ['allowClear' => true]])->add('type', 'choice', ['label' => 'oro.email.type.label', 'required' => true, 'data' => 'html', 'choices' => ['html' => 'oro.email.datagrid.emailtemplate.filter.type.html', 'txt' => 'oro.email.datagrid.emailtemplate.filter.type.txt'], 'expanded' => true])->add('attachments', 'oro_email_attachments', ['type' => 'oro_email_attachment', 'required' => false, 'allow_add' => true, 'prototype' => false, 'options' => ['required' => false]])->add('bodyFooter', 'hidden')->add('parentEmailId', 'hidden')->add('signature', 'hidden')->add('contexts', 'oro_activity_contexts_select', ['tooltip' => 'oro.email.contexts.tooltip', 'read_only' => !$this->securityContext->isGranted('EDIT', 'entity:Oro\\Bundle\\EmailBundle\\Entity\\EmailUser'), 'configs' => ['containerCssClass' => 'taggable-email', 'route_name' => 'oro_activity_form_autocomplete_search', 'route_parameters' => ['activity' => 'emails', 'name' => 'emails']]]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'initChoicesByEntityName']);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'fillFormByTemplate']);
     $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'initChoicesByEntityName']);
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:EmailType.php

示例5: includeJSFilesAction

 /**
  * Render js inclusion for create.js and dependencies and bootstrap code.
  *
  * THe hallo editor is bundled with create.js and available automatically.
  * To use aloha, you need to download the zip, as explained in step 8 of
  * the README.
  *
  * @param string $editor the name of the editor to load, currently hallo and aloha are supported
  */
 public function includeJSFilesAction($editor = 'hallo')
 {
     if ($this->securityContext && false === $this->securityContext->isGranted($this->requiredRole)) {
         return new Response('');
     }
     // We could inject a list of names to template mapping for this
     // to allow adding other editors without changing this bundle
     $view = new View();
     switch ($editor) {
         case 'hallo':
             if ($this->coffee) {
                 $view->setTemplate('SymfonyCmfCreateBundle::includecoffeefiles-hallo.html.twig');
             } else {
                 $view->setTemplate('SymfonyCmfCreateBundle::includejsfiles-hallo.html.twig');
             }
             break;
         case 'aloha':
             $view->setTemplate('SymfonyCmfCreateBundle::includejsfiles-aloha.html.twig');
             break;
         default:
             throw new \InvalidArgumentException("Unknown editor '{$editor}' requested");
     }
     $view->setData(array('cmfCreateStanbolUrl' => $this->stanbolUrl, 'cmfCreateImageUploadEnabled' => (bool) $this->imageClass));
     return $this->viewHandler->handle($view);
 }
开发者ID:notsentient,项目名称:CreateBundle,代码行数:34,代码来源:JsloaderController.php

示例6: get

 /**
  * Get the customer.
  *
  * @throws \RuntimeException
  *
  * @return \Sonata\Component\Customer\CustomerInterface
  */
 public function get()
 {
     $customer = null;
     $user = null;
     if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         // user is authenticated
         $user = $this->securityContext->getToken()->getUser();
         if (!$user instanceof UserInterface) {
             throw new \RuntimeException('User must be an instance of FOS\\UserBundle\\Model\\UserInterface');
         }
         $customer = $this->customerManager->findOneBy(array('user' => $user->getId()));
     }
     if (!$customer) {
         $basket = $this->getBasket();
         if ($basket && $basket->getCustomer()) {
             $customer = $basket->getCustomer();
         }
     }
     if (!$customer) {
         $customer = $this->customerManager->create();
     }
     if (!$customer->getLocale()) {
         $customer->setLocale($this->locale);
     }
     if ($user && $customer) {
         $customer->setUser($user);
     }
     return $customer;
 }
开发者ID:kinkinweb,项目名称:lhvb,代码行数:36,代码来源:CustomerSelector.php

示例7: previewContentAction

    public function previewContentAction( $contentId, $versionNo, $language, $siteAccessName = null )
    {
        try
        {
            $content = $this->contentService->loadContent( $contentId, array( $language ), $versionNo );
            $location = $this->previewHelper->getPreviewLocation( $contentId );
        }
        catch ( UnauthorizedException $e )
        {
            throw new AccessDeniedException();
        }

        if ( !$this->securityContext->isGranted( new AuthorizationAttribute( 'content', 'versionread', array( 'valueObject' => $content ) ) ) )
        {
            throw new AccessDeniedException();
        }

        $siteAccess = $this->previewHelper->getOriginalSiteAccess();
        // Only switch if $siteAccessName is set and different from original
        if ( $siteAccessName !== null && $siteAccessName !== $siteAccess->name )
        {
            $siteAccess = $this->previewHelper->changeConfigScope( $siteAccessName );
        }

        $response = $this->kernel->handle(
            $this->getForwardRequest( $location, $content, $siteAccess ),
            HttpKernelInterface::SUB_REQUEST
        );
        $response->headers->remove( 'cache-control' );
        $response->headers->remove( 'expires' );

        $this->previewHelper->restoreConfigScope();

        return $response;
    }
开发者ID:ataxel,项目名称:tp,代码行数:35,代码来源:PreviewController.php

示例8: onCreateMenuItemFromNode

 /**
  * Check if the node on the event is published, otherwise skip it.
  *
  * @param CreateMenuItemFromNodeEvent $event
  */
 public function onCreateMenuItemFromNode(CreateMenuItemFromNodeEvent $event)
 {
     $node = $event->getNode();
     if (!$this->publishWorkflowChecker->isGranted($this->publishWorkflowPermission, $node)) {
         $event->setSkipNode(true);
     }
 }
开发者ID:frogriotcom,项目名称:MenuBundle,代码行数:12,代码来源:CreateMenuItemFromNodeListener.php

示例9: isUserAuthenticated

 /**
  * @return bool
  */
 private function isUserAuthenticated()
 {
     // IS_AUTHENTICATED_FULLY inherits from IS_AUTHENTICATED_REMEMBERED.
     // User can be either authenticated by providing credentials during current session
     // or by "remember me" if available.
     return $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED');
 }
开发者ID:dfritschy,项目名称:ezpublish-kernel,代码行数:10,代码来源:Security.php

示例10: consume

 /**
  * @inheritdoc
  */
 public function consume(TokenInterface $token, Request $request)
 {
     if (!$this->security->isGranted(AbstractTokenVoter::CONSUME, $token)) {
         throw new AccessDeniedException();
     }
     return parent::consume($token, $request);
 }
开发者ID:piotrminkina,项目名称:state-machine-bundle,代码行数:10,代码来源:GuardCoordinatorDecorator.php

示例11: isGranted

 /**
  * @param string $role
  *
  * @return bool
  */
 protected function isGranted($role)
 {
     if (!$this->securityContext) {
         $this->securityContext = $this->getSecurityContext();
     }
     return $this->securityContext->isGranted($role);
 }
开发者ID:peterAK,项目名称:pgs-sts,代码行数:12,代码来源:BaseController.php

示例12: getCustomer

 /**
  * Gets customer based on currently logged user.
  *
  * @return CustomerInterface|null
  */
 public function getCustomer()
 {
     if ($this->securityContext->getToken() && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') && $this->securityContext->getToken()->getUser() instanceof UserInterface) {
         return $this->securityContext->getToken()->getUser()->getCustomer();
     }
     return null;
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:12,代码来源:CustomerContext.php

示例13: can

 /**
  * @{inheritDoc}
  */
 public function can($transition)
 {
     $transition = $transition instanceof TransitionInterface ? $transition : $this->getTransition($transition);
     if (!$this->securityContext->isGranted($transition->getName(), $this->getObject())) {
         return false;
     }
     return parent::can($transition);
 }
开发者ID:karmelak,项目名称:Finite,代码行数:11,代码来源:SecurityAwareStateMachine.php

示例14: countImagesList

 public function countImagesList($listParams)
 {
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         return $this->imgRepository->count($listParams);
     } else {
         return 0;
     }
 }
开发者ID:wieloming,项目名称:PictureGallery,代码行数:8,代码来源:Image.php

示例15: addConfiguration

 private function addConfiguration()
 {
     if ($this->securityContext->isGranted("ROLE_SUPER_ADMIN")) {
         $configuration = $this->menu->addChild($this->translator->trans('Configuration'), array('route' => 'HexMediaConfigurationDisplay'))->setAttribute('icon', 'fa fa-cogs');
         //			$configuration->addChild($this->translator->trans("List"), array('route' => 'HexMediaConfigurationDisplay'));
         $configuration->addChild($this->translator->trans("Add"), array('route' => 'HexMediaConfigurationAdd'));
     }
 }
开发者ID:hexmedia,项目名称:administrator-bundle,代码行数:8,代码来源:Builder.php


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