m6web / firewall-bundle
此包已被废弃,不再维护。没有建议的替代包。
提供控制器和操作IP过滤功能的包
v3.0.0
2019-11-18 14:08 UTC
Requires
- php: >=7.0.0
- ext-bcmath: *
- m6web/firewall: ~1.0
Requires (Dev)
- atoum/atoum: ^2.8|^3.0
- atoum/atoum-bundle: @stable
- symfony/symfony: ^2.2|^3.0|^4.0
This package is auto-updated.
Last update: 2022-03-18 19:02:26 UTC
README
此扩展包为您的Symfony应用程序提供IP过滤功能。
它使用Firewall组件并提供服务和注释配置。
要将此扩展包集成到Symfony 3或Symfony 4应用程序中,请使用至少v3.0.0
版本。
安装
在您的composer.json
中添加此行
{ "require": { "m6web/firewall-bundle": "dev-master" } }
更新您的供应商
composer update m6web/firewall-bundle
注册
class AppKernel extends \Symfony\Component\HttpKernel\Kernel { public function registerBundles() { $bundles = array( new M6Web\Bundle\FirewallBundle\M6WebFirewallBundle(), ); } }
使用
配置
m6web_firewall: lists: # Define some IP lists into the Firewall Provider self: # Define a list named "self" - '127.0.0.1' # IPV4 - '::1' # IPV6 short notation lan: # Define a list named "lan" - '192.168.0.*' # IPV4 with Wildcard (* = all) - '192.168.0.0/24' # IPV4 with CIDR Mask - '192.168.0.0/255.255.255.0' # IPV4 with Subnet Mask configs: # Define some pre-defined configurations into the Firewall Provider default: # Define a configuration named "default" default_state: true # Default returned value (default: true) throw_error: true # Throw an exception for rejected users (default: true) error_code: 403 # Exception status code (default: 403) error_message: 'Forbidden' # Exception message (default: Forbidden) lists: # Lists access state self: true # "self" list records will be allowed by the firewall lan: false # "lan" list records will be rejected by the firewall entries: # Define custom IP's access state '192.168.0.10': true # "192.168.0.10" will be allowed '192.168.0.20': false # "192.168.0.20" will be rejected
全局注释
use M6Web\Bundle\FirewallBundle\Annotation\Firewall; /** * @Firewall( * config="default", * actions={ * 'myFirstAction' * }, * default_state=true, * lists={ * 'default': true * }, * entries={ * '192.168.0.50': false * }, * throw_error: false, * callback="myFirewallResponseHandler", * error_message: 'Forbiden', * error_code: 403 * ) */
config
参数设置要使用哪些预定义配置actions
参数设置哪些控制器操作受保护(在类注释的情况下)
所有默认设置参数都可以通过注释覆盖。
类注释
use M6Web\Bundle\FirewallBundle\Annotation\Firewall; /** * @Firewall( * config="default", * actions={ * 'myFirstAction' * } * ) */ class MyBundleController extends Controller { public function myFirstAction() { } public function mySecondAction() { } }
myFirstAction
受default
预定义配置的保护。
在这种情况下,我们可以设置一个(或多个)用于许多操作的firewall。
方法注释
use M6Web\Bundle\FirewallBundle\Annotation\Firewall; class MyBundleController extends Controller { /** * @Firewall( * config="default" * ) */ public function myFirstAction() { } /** * @Firewall( * default_state=true, * lists={ * 'lan': false * }, * entries={ * '20.30.40.50': false * } * ) */ public function mySecondAction() { } }
myFirstAction
使用其自己的firewall和default
预定义配置mySecondAction
使用其自己的firewall和自定义配置
路径配置
m6web_firewall: patterns: # define some routing pattern to filter api: config: default # config associed to the path path: /api # path to filter
config
参数设置要使用哪些预定义配置path
参数设置哪些路径受保护。
运行测试
$ php composer.phar install --dev
$ ./vendor/bin/atoum -d Tests/
致谢
由Cytron团队开发,M6 Web。
与atoum进行测试。
许可
FirewallBundle遵循MIT许可证。