doushangan3690
2017-07-23 16:52
浏览 258
已采纳

symfony - IS_AUTHENTICATED_ANONYMOUSLY无效

I'm starting with journey with Symfony.
At this I trying to secure my auth routes (I'm using FOSUserBundle) so I do:

access_control:
    - { path: ^/logowanie$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/rejestracja, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetowanie-hasla, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/backstage/, role: ROLE_ADMIN }
    - { path: ^/profile/, role: ROLE_USER }

However, I can always go to these routes whether I'm logged in or not.
Where is my bad?

# To get started with security, check out the documentation:
# https://symfony.com/doc/current/security.html
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
                check_path: fos_user_security_check
                login_path: fos_user_security_login
            logout:
                path: fos_user_security_logout
                target: website.home
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/logowanie$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/rejestracja, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetowanie-hasla, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/backstage/, role: ROLE_ADMIN }
        - { path: ^/profile/, role: ROLE_USER }

图片转代码服务由CSDN问答提供 功能建议

我开始与Symfony一起旅行。
这是我试图保护我的身份验证路线(我 我正在使用FOSUserBundle,所以我这样做:

  access_control:
  -  {path:^ / logowanie $,role:IS_AUTHENTICATED_ANONYMOUSLY} 
  -  {path:^ / rejestracja, 角色:IS_AUTHENTICATED_ANONYMOUSLY} 
  -  {path:^ / resetowanie-hasla,role:IS_AUTHENTICATED_ANONYMOUSLY} 
  -  {path:^ / backstage /,role:ROLE_ADMIN} 
  -  {path:^ / profile /,role:ROLE_USER}  
   
 
 

然而,无论我是否登录,我都可以随时前往这些路线。
我的不好?

 #要开始使用安全性,请查看文档:
#https://symfony.com/doc/current/security.html
security:
 encoders:
 FOS \ UserBundle  \ Model \ UserInterface:bcrypt 
 
 role_hierarchy:
 ROLE_ADMIN:ROLE_USER 
 ROLE_SUPER_ADMIN:ROLE_ADMIN 
 
提供者:
 fos_userbundle:
 id:fos_user.user_p  rovider.username 
 
防火墙:
 main:
模式:^ / 
 form_login:
提供者:fos_userbundle 
 csrf_token_generator:security.csrf.token_manager 
 check_path:fos_user_security_check 
 login_path:fos_user_security_login 
 logout  :
 path:fos_user_security_logout 
 target:website.home 
 logout:true 
 anonymous:true 
 
 access_control:
  -  {path:^ / logowanie $,role:IS_AUTHENTICATED_ANONYMOUSLY} 
  -  {path:  ^ / rejestracja,角色:IS_AUTHENTICATED_ANONYMOUSLY} 
  -  {path:^ / resetowanie-hasla,role:IS_AUTHENTICATED_ANONYMOUSLY} 
  -  {path:^ / backstage /,role:ROLE_ADMIN} 
  -  {path:^ / profile /, 角色:ROLE_USER} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题