本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::isGranted方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenStorageInterface::isGranted方法的具体用法?PHP TokenStorageInterface::isGranted怎么用?PHP TokenStorageInterface::isGranted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
的用法示例。
在下文中一共展示了TokenStorageInterface::isGranted方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserData
/**
* Get current user info.
*
* @return null|array
*/
private function getUserData()
{
if (null === $this->tokenStorage) {
return null;
}
if ($this->tokenStorage->getToken() && $this->tokenStorage->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$userData = array();
$user = $this->tokenStorage->getToken()->getUser();
if (!$user) {
return null;
}
if (method_exists($user, 'getId')) {
$userData['id'] = $user->getId();
} else {
// id is required
$userData['id'] = $user->getUsername();
}
$userData['username'] = $user->getUsername();
if (method_exists($user, 'getEmail')) {
$userData['email'] = $user->getEmail();
}
return $userData;
}
return null;
}
示例2: getResourceIfAllowed
/**
* Gets the resource if the current user is granted and if the resource exists.
*
* @param string $resourceId The resource id
* @param string $grant The grant, by default is view
*
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
*
* @return Object
*/
protected function getResourceIfAllowed($resourceId, $grant = 'view')
{
$resource = $this->repository->find($resourceId, false);
if (!$this->context->isGranted($grant, $resource)) {
throw new AccessDeniedException();
}
return $resource;
}
示例3: configureOptions
public function configureOptions(OptionsResolver $resolver)
{
if ($this->authorizationChecker instanceof AuthorizationCheckerInterface) {
if (!$this->tokenStorage->getToken()) {
return;
}
if (!$this->authorizationChecker->isGranted($this->role)) {
return;
}
} else {
if (!$this->tokenStorage->getToken()) {
return;
}
if (!$this->tokenStorage->isGranted($this->role)) {
return;
}
}
$resolver->setDefaults(array('csrf_protection' => false));
}
示例4: isViewable
/**
* isViewable
*
* @param mixed $entity
*
* @return bool
*/
public function isViewable($entity)
{
$editPermission = $entity instanceof Document ? 'DOCUMENT_EDIT' : 'NODE_EDIT';
return $this->securityContext->isGranted('VIEW', $entity) && ($this->securityContext->isGranted($editPermission, $entity) || $entity->isEnabled());
}