In Symfony, how do you determine if the current user has access control by using routing placeholder?

Source: Internet
Author: User
Objective:

To enable one user to manage multiple stores

Example:

There is a user A, he is given the store ID 1 and 2 of the store's administrative rights.

Then he can manage the backstage when he accesses the ^/SHOP/1 and ^/SHOP/2 paths of the store. When he visited the ^/SHOP/3 store, he did not have background access functionality.

    • How should this function be implemented?
    • If you have the relevant English information, directly to my connection is OK.
    • Or recommend to me a few English search keywords

Thank you

Reply content:

Objective:

To enable one user to manage multiple stores

Example:

There is a user A, he is given the store ID 1 and 2 of the store's administrative rights.

Then he can manage the backstage when he accesses the ^/SHOP/1 and ^/SHOP/2 paths of the store. When he visited the ^/SHOP/3 store, he did not have background access functionality.

    • How should this function be implemented?
    • If you have the relevant English information, directly to my connection is OK.
    • Or recommend to me a few English search keywords

Thank you

Key words: Paramconverter,acl

Set: Your store is using a doctrine entity, such as

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

Code:

// 在你的Controller里,先引入你的Store类:use YourBundle\Entity\Store;// 再引入SensioFrameworkExtraBundle(Symfony 2默认包含)的ParamConverter注解:use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;// 再引入JMSSecurityExtraBundle(Symfony 2默认包含)的SecureParam注解:use JMS\SecurityExtraBundle\Annotation\SecureParam;class YourController{    /**     * 通过ParamConverter,将router里的id(或别的placeholder,注意,默认是取id)值作为主键来实例化为一个Store对象     * @ParamConverter("store", class="YourBundle:Store", options={"id"="id"})     * 这里指要求当前用户对$store参数,拥有OWNER权限     * @SecureParam(name="store", permissions="OWNER")     */    public function someAction(Store $store)    {        // ...    }}

How to enable users to have Owner permissions on $store objects, refer to: http://symfony.com/doc/current/cookbook/security/acl.html

  • 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.