本文整理汇总了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;
}
示例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();
}
}
}
示例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());
}
}
示例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']);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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');
}
示例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);
}
示例11: isGranted
/**
* @param string $role
*
* @return bool
*/
protected function isGranted($role)
{
if (!$this->securityContext) {
$this->securityContext = $this->getSecurityContext();
}
return $this->securityContext->isGranted($role);
}
示例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;
}
示例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);
}
示例14: countImagesList
public function countImagesList($listParams)
{
if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
return $this->imgRepository->count($listParams);
} else {
return 0;
}
}
示例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'));
}
}