作者:ReissClothin
项目:Syliu
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);
}
作者:sid
项目:SonataMediaBundl
/**
* {@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;
}
}
作者:zyxis
项目:cantig
public static function fetchByRole(AuthorizationCheckerInterface $authCheck)
{
$result = array();
foreach (self::$workspaces as $workspace) {
if ($authCheck->isGranted($workspace['role'])) {
$result[] = $workspace;
}
}
return $result;
}
作者:upenn-da
项目:patient-repositor
/**
* {@inheritdoc}
*/
public function initialize(Request $request, AuthorizationCheckerInterface $authChecker)
{
$settings = $this->get('dag.settings.manager')->load('activity');
if ($authChecker->isGranted('ROLE_ADMIN')) {
return;
}
if (!$settings['enabled']) {
throw $this->createNotFoundException('Activities have been disabled. Please contact your administrator to turn them back on.');
}
}
作者:ivoa
项目:content-editable-bundl
/**
* @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);
}
}
作者:redelivr
项目:login-cidada
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());
}
}
作者:darvinstudi
项目:darvin-util
/**
* {@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);
}
}
作者:knplab
项目:rad-securit
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();
}
}
}
作者:emodri
项目:LegacyBridg
/**
* 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;
}
作者:supercr
项目:extendedcmsbundl
/**
* 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);
}
}
}
}
作者:nlescur
项目:ezpublish-kerne
/**
* @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;
}
作者:php-lu
项目:lu
/**
* {@inheritdoc}
*/
public function isGranted($action, $object)
{
if (!$this->parameterResolver->resolveVoter()) {
return true;
}
return $this->authorizationChecker->isGranted('lug.' . $action, $object);
}
作者:networkin
项目:init-cms-bundl
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);
}
作者:ramunas
项目:platfor
/**
* 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)];
};
}
作者:Rioj
项目:Finit
/**
* {@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);
}
作者:padeda
项目:padeda
/**
* @return mixed
* @throws AccessDeniedException
*/
private function getUser()
{
if (!$this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
throw new AccessDeniedException();
} else {
return $this->tokenStorage->getToken()->getUser();
}
}
作者:ReissClothin
项目:BackBe
/**
* @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);
}
作者:CPASimUSant
项目:Simupol
/**
* To know if an user is the creator of Simupoll.
*
*
* @param \CPASimUSante\SimupollBundle\Entity\Simupoll $simupoll
*
* @return bool
*/
public function isGrantedAccess($simupoll, $access)
{
$collection = new ResourceCollection(array($simupoll->getResourceNode()));
if ($this->securityAuth->isGranted($access, $collection)) {
return true;
} else {
return false;
}
}
作者:breta-ionu
项目:php-sanitize
/**
* The event listener, which handles all the logic of the service.
*
* @param GetResponseEvent $getResponseEvent
*/
public function onRequest(GetResponseEvent $getResponseEvent)
{
$route = $getResponseEvent->getRequest()->get('_route');
if (in_array($route, array('php_sanitizer_user_login', 'php_sanitizer_user_register')) && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
// If the current request takes place on the login or on the register pages, redirect the user
// to the configured route.
$getResponseEvent->setResponse(new RedirectResponse($this->router->generate($this->redirectRoute)));
}
}
作者:dstansb
项目:camdra
public function isGranted($attributes, $object = null, $fully_authenticated = true)
{
if ($fully_authenticated) {
if (!$this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
return false;
}
}
return $this->authorizationChecker->isGranted($attributes, $object);
}