In Symfony, how does one determine whether the current user has accesscontrol Based on routingplaceholder?

Source: Internet
Author: User
Purpose: To enable A user to manage multiple stores, for example, A user A is granted the management permissions of stores with store ID 1 and store ID 2. Then, you can manage the background when accessing the store on the ^ shop1 and ^ shop2 paths. When he accesses the ^ shop3 store, he does not have the background purpose:

To allow a user to manage multiple stores

Example:

There is A user A who is granted the management permissions of the store with store IDs of 1 and 2.

Then, you can manage the background when accessing the shops in the ^/shop/1 and ^/shop/2 paths. When he accesses the ^/shop/3 store, he does not have the background access function.

  • How can this function be implemented?
  • If you have any relevant information in English, just connect to me.
  • Or I recommend several English search keywords.

Thank you.

Reply content:

Purpose:

To allow a user to manage multiple stores

Example:

There is A user A who is granted the management permissions of the store with store IDs of 1 and 2.

Then, you can manage the background when accessing the shops in the ^/shop/1 and ^/shop/2 paths. When he accesses the ^/shop/3 store, he does not have the background access function.

  • How can this function be implemented?
  • If you have any relevant information in English, just connect to me.
  • Or I recommend several English search keywords.

Thank you.

Key words: ParamConverter ACL

Set: Your store uses a Doctrine Entity, such

namespace YourBundle\Entity;class Store{    // ...}

Code:

// In your Controller, first introduce your Store class: use YourBundle \ Entity \ Store; // then introduce the ParamConverter annotation of SensioFrameworkExtraBundle (which is included by Symfony 2 by default: use Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ ParamConverter; // introduce the SecureParam Annotation of fuse (which is included by Symfony 2 by default): use JMS \ SecurityExtraBundle \ Annotation \ SecureParam; class YourController {/*** uses ParamConverter to set the id (or other placeholder) in the router. Note that the default value is id) value is instantiated as the primary key as a Store object * @ ParamConverter ("store", class = "YourBundle: Store", options = {"id" = "id "}) * The current user is required to have the OWNER permission for the $ store parameter * @ SecureParam (name = "store", permissions = "OWNER") */public function someAction (Store $ store) {//...}}

See http://symfony.com/doc/current/cookbook/security/acl.html for how to give users OWNER permissions on $ store objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.