duanrong5167 2017-03-15 16:32
浏览 26
已采纳

Symfony2.4.2限制对特定页面的访问

this is a website in production made with symfony 2.4.2 which has one page (downloads) who is restricted and you need a user and password to access it.

The thing is that back in the day they wanted different urls for different languages, not only changing the locale but also the "slug".

So, if you go like a normal person and access the page through clicking the button it ask you for the user and password but, if you enter the url in one of the supported languages with the locale in a different supported language it let you pass without asking you the access.

This is my routing.yml:

     frontend_descarregues_ca:
         path: /descarregues.html
         defaults: {_controller: FrontendBundle:Default:descarregues, _locale: ca }

    frontend_descarregues_es:
        path: /descargas.html
        defaults: { _controller: FrontendBundle:Default:descarregues, _locale: es }

    frontend_descarregues_fr:
        path: /telechargements.html
        defaults: { _controller: FrontendBundle:Default:descarregues, _locale: fr }

this my security.yml:

    security:
        firewalls:
            dev:
                pattern:  ^/(_(profiler|wdt)|css|images|js)/
                security: false
        default:
            pattern:        ^/ca/descarregues.html
            provider:       in_memory
            http_basic: ~
            anonymous:      ~
        default_fr:
            pattern:        ^/fr/telechargements.html
            provider:       in_memory
            http_basic: ~
            anonymous:      ~
        default_es:
            pattern:        ^/es/descargas.html
            provider:       in_memory
            http_basic: ~
            anonymous:      ~

        access_control:
            - { path: ^/ca/descarregues.html, roles: ROLE_DOWN }
            - { path: ^/es/descargas.html, roles: ROLE_DOWN }
            - { path: ^/fr/telechargements.html, roles: ROLE_DOWN }

        providers:
            in_memory:
                memory:
                    users:
                        someuser:
                            password: somepassword
                            roles: 'ROLE_DOWN'

I repeat, this is symfony 2.4.2

I tried to use requirements to only allow the locale with the specified "slug" to be valid and enter the page but doing that it happened that it won't ask me the access.

Is there someone who knows how can i fix this? (Just as a reminder this is symfony 2.4.2)

  • 写回答

1条回答 默认 最新

  • duanlao1552 2017-03-15 16:47
    关注

    Try this :

    security:
        firewalls:
            dev:
                pattern:  ^/(_(profiler|wdt)|css|images|js)/
                security: false
        default:
            pattern:        ^/[a-zA-Z]+/descarregues.html
            provider:       in_memory
            http_basic: ~
            anonymous:      ~
        default_fr:
            pattern:        ^/[a-zA-Z]+/telechargements.html
            provider:       in_memory
            http_basic: ~
            anonymous:      ~
        default_es:
            pattern:        ^/[a-zA-Z]+/descargas.html
            provider:       in_memory
            http_basic: ~
            anonymous:      ~
    
        access_control:
            - { path: ^/[a-zA-Z]+/descarregues.html, roles: ROLE_DOWN }
            - { path: ^/[a-zA-Z]+/descargas.html, roles: ROLE_DOWN }
            - { path: ^/[a-zA-Z]+/telechargements.html, roles: ROLE_DOWN }
    
        providers:
            in_memory:
                memory:
                    users:
                        someuser:
                            password: somepassword
                            roles: 'ROLE_DOWN'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效