简体   繁体   English

使用access_control在security.yml中管理路由

[英]Manage route in security.yml with access_control

I want : 我想要 :

/p/{name} ==> in public access / p / {name} ==>公开访问
/profile ==> in loggin access / profile ==>登录中

I did this in security.yml 我在security.yml中做到了

access_control:
    - { path: ^/[p]/* , role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/*, role: ROLE_CONNECT }

But, when I browse : 但是,当我浏览时:

/profile => accessible in public ==> KO / profile =>可以公共访问==> KO
/p/name-here => accessible in public ==> OK / p / name-此处 =>可在公共位置访问==> 确定

I'm pretty sure that ^/[p]/* is going to match any path that starts with /p , and you have it as the first rule, so it matches first and allows access. 我非常确定^/[p]/*将匹配以/p开头的任何路径,并且您将其作为第一条规则,因此它首先匹配并允许访问。

The square brackets [] are defining a set of characters to match, you only want to match one so you don't need them. 方括号[]定义了一组要匹配的字符,您只想匹配一个字符就不需要了。 The * says to match zero or more / characters at the end, you know there will be one / after p so omit the star. *表示末尾匹配零个或多个/字符,您知道p后面将有一个/ ,因此省略星号。 The path is a prefix so you don't need to worry about the variable part of the path. 路径是前缀,因此您不必担心路径的可变部分。

Try this: 尝试这个:

- { path: ^/p/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/profile, role: ROLE_CONNECT }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM