Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The security firewall can be configured with rules that can come from many different sources:
Declared inline in your config/Coldbox.cfc
A JSON file
An XML file
From a model object via a method call
From a database
Declared inline in ANY module's ModuleConfig.cfc
When defining your rules source, you ALWAYS have to define the rules
property. You specify an array of rules for inline, or
rules = "(db|json|xml|model)"
if you define your rules externally.
If you have external rules you probably have to specify additional properties as explained in the next pages.
Let's start exploring these sources.
Inline rules will be used by declaring them in your configuration for cbsecurity in the config/ColdBox.cfc.
This is done by making the rules
key an array of rule structures.
Every module in ColdBox has the capability to contribute their own rules to cbsecurity
by registering them in the ModuleConfig.cfc
within the settings
struct. Just create another struct called cbsecurity
with the following allowed keys:
As you can see each module can have it's own overrides for authentication and authorization events as well as their own rules.
Please note that these security rules will be PREPENDED to the global rules
As with the global rules defined in config/Coldbox.cfc
, the module cbsecurity.rules
setting supports multiple rule sources:
For example, you can load security rules specific to a module from a JSON file stored in your module:
Also note that if modules are loaded dynamically, it will still inspect them and register them if cbsecurity settings are found. The same goes for unloading, the entire security rules for that module will cease to exist.
If you have already a JSON file with your rules, then all you need to do is add the path (relative or absolute) to that file in the rules
configuration key. However, the path MUST include the keyword json
in it.
Then your file can be something like this:
If you prefer to store your rules your way, then that's perfectly fine. Just make your rules
setting point to model
and then provide us with the object to get the rules from.
If you have your security rules in a database, then cbsecurity can read the rules from the database for you. Just make the rules
key equal to db
and fill out the extra configuration keys shown below:
Property
Type
Required
Default
Description
rulesModel
string
true
---
The WireBox ID of the object that we will use to retrieve the rules from
rulesModelMethod
string
false
getSecurityRules
The name of the method to call on the object.
Property
Type
Required
Default
Description
rulesDSN
string
true
---
The dsn to use if the rules are coming from a database
rulesTable
string
true
---
The table where the rules are
rulesSQL
string
false
select* from rulesTable
The custom SQL statement to use to retrieve the rules according to the rulesTable property. If not set, the default of select* from rulesTable will be used.
rulesOrderBy
string
false
---
The column to order the rules by. If not chosen, the interceptor will not order the query, just select it.
If you have already an XML file with your rules, then all you need to do is add the path (relative or absolute) to that file in the rules
configuration key. However, the path MUST include the keyword XML
in it.
Then your xml file can look like this: