本文整理汇总了PHP中Oro\Bundle\SecurityBundle\SecurityFacade类的典型用法代码示例。如果您正苦于以下问题:PHP SecurityFacade类的具体用法?PHP SecurityFacade怎么用?PHP SecurityFacade使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SecurityFacade类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp()
{
$this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
$this->mailer = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Mailer\\DirectMailer')->disableOriginalConstructor()->getMock();
$this->mailerTransport = $this->getMockBuilder('\\Swift_Transport_EsmtpTransport')->disableOriginalConstructor()->getMock();
$this->mailer->expects($this->any())->method('getTransport')->will($this->returnValue($this->mailerTransport));
$this->emailEntityBuilder = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Builder\\EmailEntityBuilder')->disableOriginalConstructor()->getMock();
$this->emailOwnerProvider = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Provider\\EmailOwnerProvider')->disableOriginalConstructor()->getMock();
$this->dispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->disableOriginalConstructor()->getMock();
$this->emailActivityManager = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Manager\\EmailActivityManager')->disableOriginalConstructor()->getMock();
$this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->setMethods(['getLoggedUser', 'getOrganization'])->disableOriginalConstructor()->getMock();
$this->emailOriginHelper = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Tools\\EmailOriginHelper')->setMethods(['setEmailModel', 'findEmailOrigin'])->disableOriginalConstructor()->getMock();
$this->userEmailOrigin = $this->getMockBuilder('Oro\\Bundle\\ImapBundle\\Entity\\UserEmailOrigin')->disableOriginalConstructor()->getMock();
$this->userEmailOrigin->expects($this->any())->method('getSmtpHost')->will($this->returnValue('abc'));
$this->userEmailOrigin->expects($this->any())->method('getSmtpPort')->will($this->returnValue(25));
$this->securityFacadeLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->setMethods(['getService'])->disableOriginalConstructor()->getMock();
$this->securityFacadeLink->expects($this->any())->method('getService')->will($this->returnValue($this->securityFacade));
$this->securityFacade->expects($this->any())->method('getOrganization')->will($this->returnValue($this->getTestOrganization()));
$this->doctrineHelper->expects($this->any())->method('getEntityManager')->with('OroEmailBundle:Email')->will($this->returnValue($this->em));
$folder = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailFolder')->disableOriginalConstructor()->getMock();
$this->userEmailOrigin->expects($this->any())->method('getFolder')->with(FolderType::SENT)->will($this->returnValue($folder));
$emailOriginRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
$emailOriginRepo->expects($this->any())->method('findOneBy')->with(['internalName' => InternalEmailOrigin::BAP])->will($this->returnValue($this->userEmailOrigin));
$this->em->expects($this->any())->method('getRepository')->with('OroEmailBundle:InternalEmailOrigin')->will($this->returnValue($emailOriginRepo));
$this->emailProcessor = new Processor($this->doctrineHelper, $this->mailer, new EmailAddressHelper(), $this->emailEntityBuilder, $this->emailOwnerProvider, $this->emailActivityManager, $this->securityFacadeLink, $this->dispatcher, new Mcrypt(), $this->emailOriginHelper);
}
示例2: isApplicable
/**
* Checks if the entity can have comments
*
* @param object|null $entity
*
* @return bool
*/
public function isApplicable($entity)
{
if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || !$this->securityFacade->isGranted('oro_comment_view')) {
return false;
}
return $this->commentAssociationHelper->isCommentAssociationEnabled(ClassUtils::getClass($entity));
}
示例3: processAcl
/**
* Check ACL based on acl_resource_id, route or uri.
*
* @param array $options
*/
protected function processAcl(array &$options = array())
{
$needCheck = (!isset($options['check_access']) || $options['check_access'] === true) && $this->securityFacade->hasLoggedUser();
$isAllowed = self::DEFAULT_ACL_POLICY;
if (array_key_exists(self::ACL_RESOURCE_ID_KEY, $options)) {
if (array_key_exists($options[self::ACL_RESOURCE_ID_KEY], $this->aclCache)) {
$isAllowed = $this->aclCache[$options[self::ACL_RESOURCE_ID_KEY]];
} else {
if ($needCheck) {
$isAllowed = $this->securityFacade->isGranted($options[self::ACL_RESOURCE_ID_KEY]);
}
$this->aclCache[$options[self::ACL_RESOURCE_ID_KEY]] = $isAllowed;
}
} else {
$routeInfo = $this->getRouteInfo($options);
if ($routeInfo) {
if (array_key_exists($routeInfo['key'], $this->aclCache)) {
$isAllowed = $this->aclCache[$routeInfo['key']];
} else {
if ($needCheck) {
$isAllowed = $this->securityFacade->isClassMethodGranted($routeInfo['controller'], $routeInfo['action']);
}
$this->aclCache[$routeInfo['key']] = $isAllowed;
}
}
}
$options['extras']['isAllowed'] = $isAllowed;
}
示例4: onNavigationConfigure
/**
* @param ConfigureMenuEvent $event
*/
public function onNavigationConfigure(ConfigureMenuEvent $event)
{
$menu = $event->getMenu();
$children = array();
$entitiesMenuItem = $menu->getChild('system_tab')->getChild('entities_list');
if ($entitiesMenuItem) {
/** @var ConfigProvider $entityConfigProvider */
$entityConfigProvider = $this->configManager->getProvider('entity');
/** @var ConfigProvider $entityExtendProvider */
$entityExtendProvider = $this->configManager->getProvider('extend');
$extendConfigs = $entityExtendProvider->getConfigs();
foreach ($extendConfigs as $extendConfig) {
if ($this->checkAvailability($extendConfig)) {
$config = $entityConfigProvider->getConfig($extendConfig->getId()->getClassname());
if (!class_exists($config->getId()->getClassName()) || !$this->securityFacade->hasLoggedUser() || !$this->securityFacade->isGranted('VIEW', 'entity:' . $config->getId()->getClassName())) {
continue;
}
$children[$config->get('label')] = array('label' => $this->translator->trans($config->get('label')), 'options' => array('route' => 'oro_entity_index', 'routeParameters' => array('entityName' => str_replace('\\', '_', $config->getId()->getClassName())), 'extras' => array('safe_label' => true, 'routes' => array('oro_entity_*'))));
}
}
sort($children);
foreach ($children as $child) {
$entitiesMenuItem->addChild($child['label'], $child['options']);
}
}
}
示例5: getLastOperationsData
/**
* Get last operations data
*
* @param array $types
*
* @return array
*/
public function getLastOperationsData(array $types)
{
$types = array_filter($types, function ($type) {
return $this->securityFacade->isGranted(sprintf('pim_importexport_%s_execution_show', $type));
});
return $this->repository->getLastOperationsData($types);
}
示例6: beforeProcess
/**
* {@inheritdoc}
*/
public function beforeProcess($entity)
{
//check owner (Contact) entity with 'edit' permission
if (!$this->securityFacade->isGranted('EDIT', $entity->getOwner())) {
throw new AccessDeniedException();
}
}
示例7: process
/**
* Process form
*
* @param mixed $entity
*
* @return mixed|null The instance of saved entity on successful processing; otherwise, null
*/
public function process($entity)
{
if ($this->securityFacade->isGranted('EDIT', $entity)) {
return parent::process($entity);
}
return null;
}
示例8: checkPermissions
/**
* {@inheritdoc}
*/
public function checkPermissions($entity, ObjectManager $em)
{
$loggedUserId = $this->securityFacade->getLoggedUserId();
if ($loggedUserId && $loggedUserId == $entity->getId()) {
throw new ForbiddenException('self delete');
}
}
示例9: getRecipients
/**
* @param object $object
* @param int $depth
* @param bool $ignoreAcl
* @param Organization|null $organization
*
* @return Recipient[]
*/
public function getRecipients($object, $depth = 1, $ignoreAcl = false, Organization $organization = null)
{
$recipients = [];
if ($this->isAccessDenyForOrganization($object, $ignoreAcl, $organization)) {
return $recipients;
}
if (!$depth || ($ignoreAcl || !$this->securityFacade->isGranted('VIEW', $object))) {
if (!$depth || $this->securityFacade->getLoggedUser() !== $object) {
return $recipients;
}
}
$className = ClassUtils::getClass($object);
$metadata = $this->getMetadata($className);
$attributes = $this->initAttributes($className, $metadata);
foreach ($metadata->associationMappings as $name => $assoc) {
if (in_array('Oro\\Bundle\\EmailBundle\\Entity\\EmailInterface', class_implements($assoc['targetEntity']), true)) {
$attributes[] = new EmailAttribute($name, true);
} else {
if ($depth > 1) {
$assocObject = $this->getPropertyAccessor()->getValue($object, $name);
if (!$assocObject instanceof \Traversable && !is_array($assocObject)) {
if ($assocObject) {
$assocObject = [$assocObject];
} else {
$assocObject = [];
}
}
foreach ($assocObject as $obj) {
$recipients = array_merge($recipients, $this->getRecipients($obj, $depth - 1, false, $organization));
}
}
}
}
return array_merge($recipients, $this->createRecipientsFromEmails($this->createEmailsFromAttributes($attributes, $object), $object, $metadata));
}
示例10: onNavigationConfigure
/**
* @param ConfigureMenuEvent $event
*/
public function onNavigationConfigure(ConfigureMenuEvent $event)
{
/** @var ItemInterface $reportsMenuItem */
$reportsMenuItem = $event->getMenu()->getChild('reports_tab');
if ($reportsMenuItem && $this->securityFacade->hasLoggedUser()) {
$qb = $this->em->getRepository('OroReportBundle:Report')->createQueryBuilder('report')->orderBy('report.name', 'ASC');
$reports = $this->aclHelper->apply($qb)->execute();
if (!empty($reports)) {
$this->addDivider($reportsMenuItem);
$reportMenuData = [];
foreach ($reports as $report) {
$config = $this->entityConfigProvider->getConfig($report->getEntity());
if ($this->checkAvailability($config)) {
$entityLabel = $config->get('plural_label');
if (!isset($reportMenuData[$entityLabel])) {
$reportMenuData[$entityLabel] = [];
}
$reportMenuData[$entityLabel][$report->getId()] = $report->getName();
}
}
ksort($reportMenuData);
$this->buildReportMenu($reportsMenuItem, $reportMenuData);
}
}
}
示例11: setDefaultOptions
/**
* Options:
* - grid_name - name of grid that will be used for entity selection
* - grid_parameters - parameters need to be passed to grid request
* - grid_render_parameters - render parameters need to be set for grid rendering
* - existing_entity_grid_id - grid row field name used as entity identifier
* - create_enabled - enables new entity creation
* - create_acl - ACL resource used to determine that create is allowed, by default CREATE for entity used
* - create_form_route - route name for creation form
* - create_form_route_parameters - route parameters for create_form_route_parameters
*
* {@inheritDoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(['existing_entity_grid_id' => 'id', 'create_enabled' => true, 'create_acl' => null, 'create_form_route' => null, 'create_form_route_parameters' => [], 'grid_name' => null, 'grid_parameters' => [], 'grid_render_parameters' => []]);
$resolver->setNormalizers(['create_enabled' => function (Options $options, $createEnabled) {
$createRouteName = $options->get('create_form_route');
$createEnabled = $createEnabled && !empty($createRouteName);
if ($createEnabled) {
$aclName = $options->get('create_acl');
if (empty($aclName)) {
$aclObjectName = 'Entity:' . $options->get('entity_class');
$createEnabled = $this->securityFacade->isGranted('CREATE', $aclObjectName);
} else {
$createEnabled = $this->securityFacade->isGranted($aclName);
}
}
return $createEnabled;
}, 'grid_name' => function (Options $options, $gridName) {
if (!empty($gridName)) {
return $gridName;
}
$formConfig = $this->configManager->getProvider('form')->getConfig($options->get('entity_class'));
if ($formConfig->has('grid_name')) {
return $formConfig->get('grid_name');
}
throw new InvalidConfigurationException('The option "grid_name" must be set.');
}]);
}
示例12: postSet
/**
* Sets default data for create integrations form
*
* @param FormEvent $event
*/
public function postSet(FormEvent $event)
{
$data = $event->getData();
if ($data && !$data->getId() && !$data->getDefaultUserOwner() || null === $data) {
$event->getForm()->get('defaultUserOwner')->setData($this->securityFacade->getLoggedUser());
}
}
示例13: processConfigs
/**
* Validate configs nad fill default values
*
* @param DatagridConfiguration $config
*/
public function processConfigs(DatagridConfiguration $config)
{
$configItems = $config->offsetGetOr(Configuration::BASE_CONFIG_KEY, []);
$configuration = new Configuration(Configuration::BASE_CONFIG_KEY);
$normalizedConfigItems = $this->validateConfiguration($configuration, [Configuration::BASE_CONFIG_KEY => $configItems]);
$isGranted = $this->securityFacade->isGranted('EDIT', 'entity:' . $configItems['entity_name']);
//according to ACL disable inline editing for the whole grid
if (!$isGranted) {
$normalizedConfigItems[Configuration::CONFIG_KEY_ENABLE] = false;
}
// replace config values by normalized, extra keys passed directly
$resultConfigItems = array_replace_recursive($configItems, $normalizedConfigItems);
if (is_null($resultConfigItems['save_api_accessor']['default_route_parameters']['className'])) {
$resultConfigItems['save_api_accessor']['default_route_parameters']['className'] = $this->entityClassNameHelper->getUrlSafeClassName($configItems['entity_name']);
}
$config->offsetSet(Configuration::BASE_CONFIG_KEY, $resultConfigItems);
//add inline editing where it is possible, do not use ACL, because additional parameters for columns needed
$columns = $config->offsetGetOr(FormatterConfiguration::COLUMNS_KEY, []);
$blackList = $configuration->getBlackList();
foreach ($columns as $columnName => &$column) {
if (!in_array($columnName, $blackList)) {
$newColumn = $this->guesser->getColumnOptions($columnName, $configItems['entity_name'], $column);
//frontend type key must not be replaced with default value
$typeKey = PropertyInterface::FRONTEND_TYPE_KEY;
if (!empty($newColumn[$typeKey])) {
$column[$typeKey] = $newColumn[$typeKey];
}
$column = array_replace_recursive($newColumn, $column);
}
}
$config->offsetSet(FormatterConfiguration::COLUMNS_KEY, $columns);
}
示例14: onResultBefore
/**
* @param OrmResultBefore $event
*/
public function onResultBefore(OrmResultBefore $event)
{
// listener logic is applied only to frontend part of application
if ($this->securityFacade->getLoggedUser() instanceof User) {
return;
}
$config = $event->getDatagrid()->getConfig();
$query = $event->getQuery();
/** @var Subselect|SelectStatement $select */
$select = $query->getAST();
$fromClause = $select instanceof SelectStatement ? $select->fromClause : $select->subselectFromClause;
$skipAclCheck = true;
/** @var IdentificationVariableDeclaration $identificationVariableDeclaration */
foreach ($fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) {
$entityName = $identificationVariableDeclaration->rangeVariableDeclaration->abstractSchemaName;
$metadata = $this->metadataProvider->getMetadata($entityName);
if ($metadata->hasOwner()) {
$skipAclCheck = false;
break;
}
}
if ($skipAclCheck) {
$config->offsetSetByPath(Builder::DATASOURCE_SKIP_ACL_CHECK, true);
}
}
示例15: isAllowed
/**
* {@inheritdoc}
*/
public function isAllowed()
{
if (!$this->acl) {
return true;
}
return $this->securityFacade->hasLoggedUser() && $this->securityFacade->isGranted($this->acl);
}