我正在尝试对 Symfony2 中的特定路由应用 IP 限制,如Symfony2 book中所述。我没有用户身份验证,我只想让我的服务回答来自特定 IP 的请求。
但我没有成功应用限制(我在测试期间总是通过)。
这是我的security.yml
jms_security_extra:
secure_all_services: false
expressions: true
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
firewalls:
secured_area:
pattern: ^/wsoa/tests
anonymous: ~
# http_basic:
# realm: "Secured Demo Area"
access_control:
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
#- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
# THE RESTRICTION I'D LIKE (FOR EXEMPLE 127.0.0.1)
- { path: ^/wsoa_products_tests, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
这是我从 routing.yml 出发的路线:
wsoa_products_tests:
pattern: /wsoa/tests
defaults: { _controller: WsoaProductsBundle:Test:display }
任何人都知道如何使它工作?我应该忘记在 Symfony2 中执行此操作并使用 htaccess 执行此操作吗?