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


PHP Authorization\AuthorizationCheckerInterface类代码示例

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


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

示例1:

 function it_gets_customer_from_currently_logged_user(TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, TokenInterface $token, ShopUserInterface $user, CustomerInterface $customer)
 {
     $tokenStorage->getToken()->willReturn($token);
     $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
     $token->getUser()->willReturn($user);
     $user->getCustomer()->willReturn($customer);
     $this->getCustomer()->shouldReturn($customer);
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:8,代码来源:CustomerContextSpec.php

示例2: isGranted

 /**
  * {@inheritdoc}
  */
 public function isGranted(MediaInterface $media, Request $request)
 {
     try {
         return $this->security->isGranted($this->roles);
     } catch (AuthenticationCredentialsNotFoundException $e) {
         // The token is not set in an AuthorizationCheckerInterface object
         return false;
     }
 }
开发者ID:sidz,项目名称:SonataMediaBundle,代码行数:12,代码来源:RolesDownloadStrategy.php

示例3: onKernelResponse

 /**
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     try {
         if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
             return;
         }
     } catch (AuthenticationCredentialsNotFoundException $e) {
         return;
     }
     $request = $event->getRequest();
     if ($request->isXmlHttpRequest()) {
         return;
     }
     $response = $event->getResponse();
     if ($response->isRedirection() || false === strpos($response->headers->get('Content-Type', ''), 'text/html')) {
         return;
     }
     $html = $this->editor->renderEditor($response);
     if (!empty($html)) {
         $this->injectEditor($response, $html);
     }
 }
开发者ID:ivoaz,项目名称:content-editable-bundle,代码行数:28,代码来源:EditorResponseListener.php

示例4: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
         // don't do anything if it's not the master request
         return;
     }
     $token = $this->tokenStorage->getToken();
     if (is_null($token) || $token instanceof OAuthToken || $this->authChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') === false) {
         return;
     }
     if (!$token->getUser() instanceof PersonInterface) {
         // We don't have a PersonInterface... Nothing to do here.
         return;
     }
     try {
         $this->handleTargetPath($event);
         $tasks = $this->checkTasks($event, $dispatcher);
         if (!$tasks) {
             $this->checkIntent($event);
         }
         $this->checkUnconfirmedEmail();
     } catch (RedirectResponseException $e) {
         $event->setResponse($e->getResponse());
     }
 }
开发者ID:redelivre,项目名称:login-cidadao,代码行数:25,代码来源:LoggedInUserListener.php

示例5: filter

 /**
  * {@inheritdoc}
  */
 public function filter(QueryBuilder $qb, UserInterface $user = null)
 {
     if (!$this->isFilterable($qb)) {
         throw new UserException('Query builder is not filterable.');
     }
     if (empty($user)) {
         $user = $this->getUser();
         if (empty($user)) {
             return;
         }
     }
     $userIds = $this->extendedMetadataFactory->getDoctrineMetadata($user)->getIdentifierValues($user);
     $userId = reset($userIds);
     if (empty($userId)) {
         throw new UserException('User ID is empty.');
     }
     foreach (array_combine($qb->getRootAliases(), $qb->getRootEntities()) as $alias => $entity) {
         $meta = $this->extendedMetadataFactory->getExtendedMetadata($entity)['user'];
         if (empty($meta)) {
             continue;
         }
         $filter = false;
         foreach ($meta['roles'] as $role) {
             if ($this->authorizationChecker->isGranted($role)) {
                 $filter = true;
                 break;
             }
         }
         if (!$filter) {
             continue;
         }
         $key = $meta['property'] . '_id';
         $qb->innerJoin(sprintf('%s.%s', $alias, $meta['property']), $meta['property'])->andWhere(sprintf('%s = :%s', $meta['property'], $key))->setParameter($key, $userId);
     }
 }
开发者ID:darvinstudio,项目名称:darvin-utils,代码行数:38,代码来源:UserQueryBuilderFilterer.php

示例6: checkIfUserIsGranted

 public function checkIfUserIsGranted(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     foreach ($request->attributes->get('_security', array()) as $rule) {
         $roles = array();
         if (isset($rule['roles']) && !empty($rule['roles'])) {
             $roles = $rule['roles'];
         } else {
             throw new \RuntimeException('You should provide "roles" parameter.');
         }
         if (is_string($roles)) {
             $roles = array($roles);
         }
         $subject = null;
         $subjectName = isset($rule['subject']) ? $rule['subject'] : null;
         if (!empty($subjectName)) {
             if (!$request->attributes->has($subjectName)) {
                 throw new \RuntimeException(sprintf("Subject '%s' is not available in the request attributes.", $subjectName));
             }
             $subject = $request->attributes->get($subjectName);
         }
         if (!$this->checker->isGranted($roles, $subject)) {
             throw new AccessDeniedException();
         }
     }
 }
开发者ID:knplabs,项目名称:rad-security,代码行数:26,代码来源:AuthorizationListener.php

示例7: websiteToolbarAction

 /**
  * Renders the legacy website toolbar template.
  *
  * If the logged in user doesn't have the required permission, an empty response is returned
  *
  * @param mixed $locationId
  * @param Request $request
  *
  * @return Response
  */
 public function websiteToolbarAction($locationId, Request $request)
 {
     $response = new Response();
     if (isset($this->csrfProvider)) {
         $parameters['form_token'] = $this->csrfProvider->generateCsrfToken('legacy');
     }
     if ($this->previewHelper->isPreviewActive()) {
         $template = 'design:parts/website_toolbar_versionview.tpl';
         $previewedContent = $authValueObject = $this->previewHelper->getPreviewedContent();
         $previewedVersionInfo = $previewedContent->versionInfo;
         $parameters = array('object' => $previewedContent, 'version' => $previewedVersionInfo, 'language' => $previewedVersionInfo->initialLanguageCode, 'is_creator' => $previewedVersionInfo->creatorId === $this->getRepository()->getCurrentUser()->id);
     } elseif ($locationId === null) {
         return $response;
     } else {
         $authValueObject = $this->loadContentByLocationId($locationId);
         $template = 'design:parts/website_toolbar.tpl';
         $parameters = array('current_node_id' => $locationId, 'redirect_uri' => $request->attributes->get('semanticPathinfo'));
     }
     $authorizationAttribute = new AuthorizationAttribute('websitetoolbar', 'use', array('valueObject' => $authValueObject));
     if (!$this->authChecker->isGranted($authorizationAttribute)) {
         return $response;
     }
     $response->setContent($this->legacyTemplateEngine->render($template, $parameters));
     return $response;
 }
开发者ID:emodric,项目名称:LegacyBridge,代码行数:35,代码来源:WebsiteToolbarController.php

示例8: onCreateMenuItemFromNode

 /**
  * Determines if a node should be skipped from rendering based on the current
  * user's role
  *
  * @param CreateMenuItemFromNodeEvent $event
  */
 public function onCreateMenuItemFromNode(CreateMenuItemFromNodeEvent $event)
 {
     $node = $event->getNode();
     if ($node instanceof MenuNode) {
         $addRole = $node->getAddWhenGranted();
         $removeRole = $node->getRemoveWhenGranted();
         //This avoids issue when rendering error pages with menus
         //Defaults all menu items with any role requirements to no be displayed
         if ($this->token->getToken() === null) {
             if ($addRole !== null || $removeRole !== null) {
                 $event->setSkipNode(true);
             }
             return;
         }
         if ($addRole !== null) {
             if (!$this->security->isGranted($addRole)) {
                 $event->setSkipNode(true);
             }
         }
         if ($removeRole !== null) {
             if ($this->security->isGranted($removeRole)) {
                 $event->setSkipNode(true);
             }
         }
     }
 }
开发者ID:supercru,项目名称:extendedcmsbundle,代码行数:32,代码来源:MenuNodeListener.php

示例9: previewContentAction

 /**
  * @throws NotImplementedException If Content is missing location as this is not supported in current version
  */
 public function previewContentAction(Request $request, $contentId, $versionNo, $language, $siteAccessName = null)
 {
     $this->previewHelper->setPreviewActive(true);
     try {
         $content = $this->contentService->loadContent($contentId, array($language), $versionNo);
         $location = $this->locationProvider->loadMainLocation($contentId);
         if (!$location instanceof Location) {
             throw new NotImplementedException("Preview for content without locations");
         }
         $this->previewHelper->setPreviewedContent($content);
         $this->previewHelper->setPreviewedLocation($location);
     } catch (UnauthorizedException $e) {
         throw new AccessDeniedException();
     }
     if (!$this->authorizationChecker->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, $request), HttpKernelInterface::SUB_REQUEST);
     $response->headers->remove('cache-control');
     $response->headers->remove('expires');
     $this->previewHelper->restoreConfigScope();
     $this->previewHelper->setPreviewActive(false);
     return $response;
 }
开发者ID:nlescure,项目名称:ezpublish-kernel,代码行数:32,代码来源:PreviewController.php

示例10: isGranted

 /**
  * {@inheritdoc}
  */
 public function isGranted($action, $object)
 {
     if (!$this->parameterResolver->resolveVoter()) {
         return true;
     }
     return $this->authorizationChecker->isGranted('lug.' . $action, $object);
 }
开发者ID:php-lug,项目名称:lug,代码行数:10,代码来源:SecurityChecker.php

示例11: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $response = $event->getResponse();
     $request = $event->getRequest();
     // do not capture redirects or modify XML HTTP Requests
     if ($request->isXmlHttpRequest()) {
         return;
     }
     // do not capture admin cms urls
     if (preg_match('/.*\\/admin\\/.*/', $request->getRequestUri())) {
         return;
     }
     try {
         $isGranted = $this->authorizationChecker->isGranted('ROLE_ADMIN');
     } catch (AuthenticationCredentialsNotFoundException $e) {
         $isGranted = false;
     }
     if (self::DISABLED === $this->mode || $response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat()) {
         return;
     }
     $this->injectToolbar($response, $request);
 }
开发者ID:networking,项目名称:init-cms-bundle,代码行数:25,代码来源:AdminToolbarListener.php

示例12: getActionConfigurationClosure

 /**
  * Returns callback for configuration of grid/actions visibility per row
  *
  * @return callable
  */
 public function getActionConfigurationClosure()
 {
     return function (ResultRecordInterface $record) {
         $role = $record->getRootEntity();
         return ['update' => $this->authorizationChecker->isGranted('EDIT', $role), 'delete' => $this->authorizationChecker->isGranted('DELETE', $role)];
     };
 }
开发者ID:ramunasd,项目名称:platform,代码行数:12,代码来源:RoleGridHelper.php

示例13: can

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

示例14: getUser

 /**
  * @return mixed
  * @throws AccessDeniedException
  */
 private function getUser()
 {
     if (!$this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
         throw new AccessDeniedException();
     } else {
         return $this->tokenStorage->getToken()->getUser();
     }
 }
开发者ID:padedam,项目名称:padedam,代码行数:12,代码来源:ReviewManager.php

示例15: onPostLoad

 /**
  * @param \BackBee\Event\Event $event
  */
 public function onPostLoad(Event $event)
 {
     $page = $event->getTarget();
     if (!$page instanceof Page) {
         return;
     }
     $isBbSessionActive = $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') === false;
     $page->setUseUrlRedirect($isBbSessionActive);
 }
开发者ID:ReissClothing,项目名称:BackBee,代码行数:12,代码来源:PageListener.php


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