本文整理汇总了PHP中Symfony\Component\Security\Acl\Domain\ObjectIdentity::fromDomainObject方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectIdentity::fromDomainObject方法的具体用法?PHP ObjectIdentity::fromDomainObject怎么用?PHP ObjectIdentity::fromDomainObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Acl\Domain\ObjectIdentity
的用法示例。
在下文中一共展示了ObjectIdentity::fromDomainObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createAction
/**
* Creates a new Url entity.
*
*/
public function createAction(Request $request)
{
$entity = new Url();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
// sets the author field to session username
$entity->setAuthor($this->get('security.token_storage')->getToken()->getUser());
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
//check logged in user for acl creation
if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
// creating the ACL
$aclProvider = $this->get('security.acl.provider');
$objectIdentity = ObjectIdentity::fromDomainObject($entity);
$acl = $aclProvider->createAcl($objectIdentity);
// retrieving the security identity of the currently logged-in user
$tokenStorage = $this->get('security.token_storage');
$user = $tokenStorage->getToken()->getUser();
$securityIdentity = UserSecurityIdentity::fromAccount($user);
// grant owner access
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
$aclProvider->updateAcl($acl);
}
return $this->redirect($this->generateUrl('url_show', array('id' => $entity->getId())));
}
return $this->render('SurlUrlBundle:Url:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
}
示例2: postSave
/**
* This method is here to make your life better, so overwrite it
*
* @param \Symfony\Component\Form\Form $form the valid form
* @param \Taskeet\MainBundle\Entity\Event $Ticket your \Taskeet\MainBundle\Entity\Event object
*/
public function postSave(\Symfony\Component\Form\Form $form, \Taskeet\MainBundle\Entity\Event $Event)
{
$proveedor = $this->container->get('security.acl.provider');
$idObjeto = ObjectIdentity::fromDomainObject($Event);
//poniendo al usuario logueado como owner
$this->setPermissions($proveedor, $idObjeto, $this->getUser(), MaskBuilder::MASK_OWNER);
if ($data = $form->get('repeat')->getData()) {
$start = clone $form->get('startDate')->getData();
$end = clone $form->get('dueDate')->getData();
$ocurrences = $form->get('ocurrences')->getData();
$interval = new DateInterval($form->get('repeat')->getData());
$periodo = new \DatePeriod($start, $interval, $ocurrences, \DatePeriod::EXCLUDE_START_DATE);
foreach ($periodo as $key => $fecha) {
$event = clone $Event;
$event->setStartDate($fecha);
$event->setDueDate($end->add($interval));
$event->setTitle(sprintf('%s-%s', $Event->getTitle(), $key));
// $event->setSlug(sprintf('%s-%s', $Event->getSlug(), $key));
$this->preSave($form, $event);
$this->saveObject($event);
$idObjeto = ObjectIdentity::fromDomainObject($event);
$this->setPermissions($proveedor, $idObjeto, $this->getUser(), MaskBuilder::MASK_OWNER);
}
}
}
示例3: createTskAcl
public function createTskAcl(Contact $contact)
{
$aclProvider = $this->getContainer()->get('security.acl.provider');
$objectIdentity = ObjectIdentity::fromDomainObject($contact);
$orgIdentity = 'ROLE_ORG_' . $contact->getOrganization()->getId();
$orgSecurityIdentity = new RoleSecurityIdentity($orgIdentity);
$builder = new MaskBuilder();
$builder->add('VIEW');
$builder->add('EDIT');
$builder->add('CREATE');
$builder->add('MASTER');
try {
try {
$acl = $aclProvider->createAcl($objectIdentity);
$acl->insertObjectAce($orgSecurityIdentity, $builder->get());
foreach ($contact->getSchools() as $school) {
$schoolIdentity = 'ROLE_SCHOOL_' . $school->getId();
$schoolSecurityIdentity = new RoleSecurityIdentity($schoolIdentity);
$acl->insertObjectAce($schoolSecurityIdentity, $builder->get());
}
$aclProvider->updateAcl($acl);
} catch (AclAlreadyExistsException $e) {
// keep going ...
}
} catch (AclException $e) {
throw $e;
}
}
示例4: ofertaNuevaAction
/**
* Muestra el formulario para crear una nueva oferta y se encarga del
* procesamiento de la información recibida y la creación de las nuevas
* entidades de tipo Oferta
*/
public function ofertaNuevaAction()
{
$peticion = $this->getRequest();
$oferta = new Oferta();
$formulario = $this->createForm(new OfertaType(), $oferta);
if ($peticion->getMethod() == 'POST') {
$formulario->bindRequest($peticion);
if ($formulario->isValid()) {
// Completar las propiedades de la oferta que una tienda no puede establecer
$tienda = $this->get('security.context')->getToken()->getUser();
$oferta->setCompras(0);
$oferta->setRevisada(false);
$oferta->setTienda($tienda);
$oferta->setCiudad($tienda->getCiudad());
// Copiar la foto subida y guardar la ruta
$oferta->subirFoto($this->container->getParameter('cupon.directorio.imagenes'));
$em = $this->getDoctrine()->getEntityManager();
$em->persist($oferta);
$em->flush();
// Asignar el permiso necesario para que la tienda pueda modificar esta oferta
$idObjeto = ObjectIdentity::fromDomainObject($oferta);
$idUsuario = UserSecurityIdentity::fromAccount($tienda);
$acl = $this->get('security.acl.provider')->createAcl($idObjeto);
$acl->insertObjectAce($idUsuario, MaskBuilder::MASK_OPERATOR);
$this->get('security.acl.provider')->updateAcl($acl);
return $this->redirect($this->generateUrl('extranet_portada'));
}
}
return $this->render('TiendaBundle:Extranet:formulario.html.twig', array('accion' => 'crear', 'formulario' => $formulario->createView()));
}
示例5: createAction
/**
* @Route("/create", name="freedom_objective_dashboard_create", options={"expose"=true})
* @Template()
*/
public function createAction()
{
$objective = new Objective();
$form = $this->createForm(new ObjectiveCreateType(), $objective);
$request = $this->get('request');
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$objective->setUser($this->getUser());
$objective->setNbsteps(count($objective->getSteps()));
foreach ($objective->getSteps() as $key => $value) {
$value->setObjective($objective);
$objective->addStep($value);
}
$em = $this->getDoctrine()->getManager();
$em->persist($objective);
$em->flush();
//ACL
$aclProvider = $this->get('security.acl.provider');
$objectIdentity = ObjectIdentity::fromDomainObject($objective);
$acl = $aclProvider->createAcl($objectIdentity);
$securityContext = $this->get('security.context');
$user = $securityContext->getToken()->getUser();
$securityIdentity = UserSecurityIdentity::fromAccount($user);
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
$aclProvider->updateAcl($acl);
return $this->redirect($this->generateUrl('freedom_objective_dashboard_details', array('id' => $objective->getId())));
}
}
return array('form' => $form->createView());
}
示例6: setUp
protected function setUp()
{
$this->initAutoload();
$bbapp = $this->getBBApp();
$this->initDb($bbapp);
$this->getBBApp()->setIsStarted(true);
$this->initAcl();
$this->site = new Site();
$this->site->setLabel('Test Site')->setServerName('test_server');
$this->groupEditor = new Group();
$this->groupEditor->setName('groupName');
$this->groupEditor->setSite($this->site);
$bbapp->getEntityManager()->persist($this->site);
$bbapp->getEntityManager()->persist($this->groupEditor);
$bbapp->getEntityManager()->flush();
// setup ACE for site
$aclProvider = $this->getSecurityContext()->getACLProvider();
$objectIdentity = ObjectIdentity::fromDomainObject($this->site);
$acl = $aclProvider->createAcl($objectIdentity);
// retrieving the security identity of the currently logged-in user
$securityIdentity = new UserSecurityIdentity($this->groupEditor->getName(), 'BackBee\\Security\\Group');
// grant owner access
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_EDIT);
$aclProvider->updateAcl($acl);
// authenticate user , set up permissions
$token = $this->createAuthUser('api_user', array('ROLE_API_USER'));
}
示例7: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$stepOrg = new Organization();
$stepOrg->setName('Step Inventory');
$manager->persist($stepOrg);
$demoOrg = new Organization();
$demoOrg->setName('Acme Inc.');
$manager->persist($demoOrg);
$manager->flush();
$this->addReference('stepOrg', $stepOrg);
$this->addReference('demoOrg', $demoOrg);
$aclProvider = $this->container->get('security.acl.provider');
$devRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_DEV');
$adminRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_ADMIN');
$leadRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_LEAD');
$userRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_USER');
$objectIdentity = ObjectIdentity::fromDomainObject($stepOrg);
$acl = $aclProvider->createAcl($objectIdentity);
$acl->insertObjectAce($userRoleSecurityIdentity, MaskBuilder::MASK_VIEW);
$acl->insertObjectAce($devRoleSecurityIdentity, MaskBuilder::MASK_OPERATOR);
$aclProvider->updateAcl($acl);
$objectIdentity = ObjectIdentity::fromDomainObject($demoOrg);
$acl = $aclProvider->createAcl($objectIdentity);
$acl->insertObjectAce($userRoleSecurityIdentity, MaskBuilder::MASK_VIEW);
$acl->insertObjectAce($adminRoleSecurityIdentity, MaskBuilder::MASK_OPERATOR);
$aclProvider->updateAcl($acl);
}
示例8: newAction
/**
* New category page
* @return \Symfony\Component\HttpFoundation\Response
*/
public function newAction(Request $request)
{
$category = new Category();
$user = $this->getUser();
$category->setJeweler($user);
//j'associe mon jeweler 1 à mon produit
// je crée un formulaire de produit
$form = $this->createForm(new CategoryType($user), $category, array('validation_groups' => 'new', 'attr' => array('method' => 'post', 'novalidate' => 'novalidate', 'action' => $this->generateUrl('store_backend_category_new'))));
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
//je récupère le manager de Doctrine
// j'upload mon fichier en faisant appel a la methode upload()
$category->upload();
$em->persist($category);
//j'enregistre mon objet product dans doctrine
$em->flush();
//j'envoie ma requete d'insert à ma table product
// création de l'ACL
$aclProvider = $this->get('security.acl.provider');
$objectIdentity = ObjectIdentity::fromDomainObject($category);
$acl = $aclProvider->createAcl($objectIdentity);
// retrouve l'identifiant de sécurité de l'utilisateur actuellement connecté
$tokenStorage = $this->get('security.token_storage');
$user = $tokenStorage->getToken()->getUser();
$securityIdentity = UserSecurityIdentity::fromAccount($user);
// donne accès au propriétaire
$acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
$aclProvider->updateAcl($acl);
$this->get('session')->getFlashBag()->add('success', 'Votre catégorie a bien été crée');
return $this->redirectToRoute('store_backend_category_list');
//redirection selon la route
}
return $this->render('StoreBackendBundle:Category:new.html.twig', array('form' => $form->createView()));
}
示例9: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$tidLabel = new Label();
$tidLabel->setName('TravelerId Label');
$tidLabel->setDescription('ZPL TID Label');
$tidLabel->setTemplate('
^XA
^FO50,50^BY3
^BCN,100,Y,N,N
^FD{{tid}}
^XZ
');
$manager->persist($tidLabel);
$manager->flush();
//$this->addReference('dfwOffice', $dfwOffice);
$aclProvider = $this->container->get('security.acl.provider');
$devRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_DEV');
$adminRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_ADMIN');
$leadRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_LEAD');
$userRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_USER');
$objectIdentity = ObjectIdentity::fromDomainObject($tidLabel);
$acl = $aclProvider->createAcl($objectIdentity);
$acl->insertObjectAce($userRoleSecurityIdentity, MaskBuilder::MASK_VIEW);
$acl->insertObjectAce($adminRoleSecurityIdentity, MaskBuilder::MASK_OPERATOR);
$aclProvider->updateAcl($acl);
}
示例10: createForm
/**
* Gets the form
*
* @param \Sonata\AdminBundle\Util\AdminObjectAclData $data
* @return \Symfony\Component\Form\Form
*/
public function createForm(AdminObjectAclData $data)
{
// Retrieve object identity
$objectIdentity = ObjectIdentity::fromDomainObject($data->getObject());
$acl = $data->getSecurityHandler()->getObjectAcl($objectIdentity);
if (!$acl) {
$acl = $data->getSecurityHandler()->createAcl($objectIdentity);
}
$data->setAcl($acl);
$masks = $data->getMasks();
// Create a form to set ACL
$formBuilder = $this->formFactory->createBuilder('form');
foreach ($data->getAclUsers() as $aclUser) {
$securityIdentity = UserSecurityIdentity::fromAccount($aclUser);
foreach ($data->getUserPermissions() as $permission) {
try {
$checked = $acl->isGranted(array($masks[$permission]), array($securityIdentity));
} catch (NoAceFoundException $e) {
$checked = false;
}
$formBuilder->add($aclUser->getId() . $permission, 'checkbox', array('required' => false, 'data' => $checked));
}
}
$form = $formBuilder->getForm();
$data->setForm($form);
return $form;
}
示例11: updateAcl
/**
* Actualiza la acl del objeto en cuestión.
*
* @param $object
* @param array $applyTo
* @throws \Symfony\Component\Security\Acl\Exception\InvalidDomainObjectException
*/
public function updateAcl($object, $applyTo = array())
{
$objectIdentity = ObjectIdentity::fromDomainObject($object);
$aclProviderCallable = $this->aclProviderCallable;
$aclProviderCallable($objectIdentity, 'delete');
$acl = $aclProviderCallable($objectIdentity, 'create');
$this->applyAcl($acl, $applyTo);
}
示例12: getObjectIdentity
/**
* {@inheritDoc}
*/
public function getObjectIdentity($domainObject)
{
try {
return ObjectIdentity::fromDomainObject($domainObject);
} catch (InvalidDomainObjectException $failed) {
return null;
}
}
示例13: testFromDomainObjectWithoutInterfaceAllowsZeroAsIdentifier
public function testFromDomainObjectWithoutInterfaceAllowsZeroAsIdentifier()
{
$domainObject = new TestDomainObject();
$domainObject->id = '0';
$id = ObjectIdentity::fromDomainObject($domainObject);
$this->assertSame('0', $id->getIdentifier());
$this->assertEquals('Symfony\\Component\\Security\\Acl\\Tests\\Domain\\TestDomainObject', $id->getType());
}
示例14: test_vote_objectScope
public function test_vote_objectScope()
{
$aclManager = $this->getBBApp()->getContainer()->get('security.acl_manager');
$aclManager->insertOrUpdateClassAce(ObjectIdentity::fromDomainObject($this->user), new UserSecurityIdentity($this->group->getObjectIdentifier(), get_class($this->group)), MaskBuilder::MASK_EDIT);
$this->assertEquals(BBAclVoter::ACCESS_GRANTED, $this->aclVoter->vote($this->token, $this->user, ['EDIT']));
$this->assertEquals(BBAclVoter::ACCESS_DENIED, $this->aclVoter->vote($this->token, new ObjectIdentity('all', get_class($this->user)), ['EDIT']));
$this->assertEquals(BBAclVoter::ACCESS_DENIED, $this->aclVoter->vote($this->token, new ObjectIdentity(23545866754, get_class($this->user)), ['EDIT']));
}
示例15: postSave
/**
* This method is here to make your life better, so overwrite it
*
* @param \Symfony\Component\Form\Form $form the valid form
* @param \Taskeet\MainBundle\Entity\Ticket $Ticket your \Taskeet\MainBundle\Entity\Ticket object
*/
public function postSave(\Symfony\Component\Form\Form $form, \Taskeet\MainBundle\Entity\Ticket $Ticket)
{
$proveedor = $this->container->get('security.acl.provider');
$idObjeto = ObjectIdentity::fromDomainObject($Ticket);
//si la tarea tiene asignado un empleado se le asigna el perm operator
if ($assignedTo = $Ticket->getAssignedTo()) {
$this->setPermissions($proveedor, $idObjeto, $assignedTo, MaskBuilder::MASK_EDIT);
}
}