Loading...
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.
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:
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:
By Default, the security module will register itself for you using the module configuration settings you define in theconfig/ColdBox.cfc.
Below you can find all the settings with their default value and description.
The invalidAuthenticationEvent
and invalidAuthorizationEvent
keys can be used to provide default events when Authentication or Authorization failed. The defaultAuthenticationAction and defaultAuthorizationAction determine whether there will be a redirection or override. The default action is redirect
, but especially for API's an override
will be more appropriate. When using rule-based security you can override these keys for any individual rule.
You can place a global validator in the configuration settings, but you can also override the validator on a module by module basis as well. The default validator is using the CBAuth Validator.
cbsecurity ships with the cbauth module that can provide you with a nice interface for authentication services. If you use the default authenticationService
authenticationService@cbauth, you have to define the UserServiceClass in the cbauth module.
However, you can plug in any WireBox ID and select your own authentication services.
If you are using cbauth as your authenticationService
(the default), you also need to configure cbauth.
cbsecurity will also require a user service if you will be dealing with any JWT security tokens. Just add your WireBox ID to the user service of your choice. If you are using cbauth, you have to define the UserServiceClass in the cbauth module.
Please note that by default, the security firewall will be auto-registered for you. If you do NOT want the firewall to be automatically registered for you, then use the autoLoadFirewall
setting and make it false. Then you can use the Custom Firewall approach below to register the firewall manually in the order of the interceptors that you would like.
By default, annotation security is enabled. This will inspect ALL incoming event executions for the security annotations. If you do not want to use annotation security we recommend you turn it off to avoid the inspection of events.
ColdBox security comes with a nice graphical visualizer for all the registered security rules and settings in your global firewall. You can enable it by using the enableSecurityVisualizer setting.
You can then visit the /cbsecurity
URL and you will be presented with this magical tool:
Important The visualizer is disabled by default and if it detects an environment of production, it will disable itself.
Each module can override some settings for cbsecurity according to its needs. You will create a cbsecurity
struct within the module's settings
struct in the ModuleConfig.cfc
The settings you see above are the only ones that module's support as of now.
You can also register multiple instances of the cbsecurity
module using different configurations by just adding them to your app's config or even your module's configuration. This will register a NEW firewall apart from the global security firewall registered using the global settings as defined above.
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.