1

使用 symfony2.3.​​4。

当我在地址字段中输入时,我总是使用以下 security.yml 和 routing.yml 重定向:或者www.example.com/我不知道为什么。access_controls 是否有任何设置错误?还是安全性:假/真?www.example.com/unsecured/startwww.example.com/getlocale

在 security.yml 之后:

firewalls:
dev:
    pattern:  ^/(_(profiler|wdt)|css|images|js)/
    security: false

login:
    pattern:  ^/(en|de)/login
    security: false

secured_area:
    pattern:    ^/
    #anonymous: ~
    http_basic:
        realm: "Secured Area"
    form_login:
        check_path: frontend_account_security_check
        login_path: frontend_account_login
        use_referer:        true
        #default_target_path: frontend_account_my_account
        #target_path_parameter: frontend_account_my_account
    logout: 
        path:   /en/secured/logout
        target: /getlocale
        #anonymous: ~
    #http_basic:
    #    realm: "Secured Demo Area"

access_control:
- { path: ^/en/unsecured/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/de/unsecured/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/en/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/de/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

我的路由.yml:

frontend_account_login:
  pattern:  /{_locale}/login
  defaults: { _controller: FrontendAccountBundle:Secured:login }
  requirements:
    _locale: en|de

frontend_main_index:
  pattern:  /
  defaults: { _controller: FrontendMainBundle:Main:index }

frontend_main_getlocale:
  pattern:  /getlocale
  defaults: { _controller: FrontendMainBundle:Main:getlocale }

frontend_main_inlocale:
  pattern: /unsecured/start
  defaults: { _controller: FrontendMainBundle:Main:start }
4

1 回答 1

1

哦,废话,我错过了一个非常小的东西。正确答案是:

secured_area:
pattern:    ^/
anonymous: ~    //activate the anonymous

access_control:
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/de/secured/, roles: ROLES_USER }
于 2013-10-24T12:28:39.070 回答