Skip to content

Commit b22bc74

Browse files
committed
enough for the readme, the rest move to the docs
1 parent 8b1e448 commit b22bc74

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

readme.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ This module will enhance your ColdBox applications by providing out of the box s
77
- A security rule engine for incoming requests
88
- Annotation driven security for handlers and actions
99
- JWT (Json Web Tokens) generator, decoder and authentication services
10-
- Pluggable with any Authentication service or can leverage [cbauth](https://github.com/elpete/cbauth)
10+
- Pluggable with any Authentication service or can leverage [cbauth](https://github.com/elpete/cbauth) by default
11+
- Capability to distinguish between invalid authentication and invalid authorization and determine an outcome of the process.
12+
- Ability to load/unload security rules from contributing modules. So you can create a nice HMVC hierarchy of security.
13+
- Ability for each module to define it's own `validator`
1114

12-
The module also has the capability to distinguish between invalid authentication and invalid authorization and determine an outcome of the process. The module also supports the ability to load/unload security rules from contributing modules. So you can create a nice HMVC hierarchy of security.
15+
Welcome to SecureLand!
1316

1417
## License
1518

@@ -85,14 +88,11 @@ cbsecurity = {
8588
// JWT Settings
8689
"jwt" : {
8790
// The jwt secret encoding key, defaults to getSystemEnv( "JWT_SECRET", "" )
88-
"secretKey" : "",
89-
91+
"secretKey" : getSystemSetting( "JWT_SECRET", "" ),
9092
// by default it uses the authorization bearer header, but you can also pass a custom one as well.
9193
"customAuthHeader" : "x-auth-token",
92-
9394
// The expiration in minutes for the jwt tokens
9495
"expiration" : 60,
95-
9696
// If true, enables refresh tokens, longer lived tokens (not implemented yet)
9797
"enableRefreshTokens" : false,
9898
// The default expiration for refresh tokens, defaults to 30 days
@@ -122,11 +122,11 @@ cbsecurity = {
122122

123123
## Usage
124124

125-
Using the default configuration, this module will register the `Security` interceptor automatically for you according to the settings (`cbsecurity.interceptor.Security`).
125+
Using the default configuration, this module will register the `Security` interceptor automatically for you according to the settings shown above and using the interceptor => (`cbsecurity.interceptor.Security`).
126126

127127
> **Info** You can deactivate this and load as a manual interceptor via the `autoLoadFirewall` setting.
128128
129-
The interceptor will intercept all calls to your application via the `preProcess()` interception point. Each request will then be validated against any registered security rules and then validated against any handler/action security annotations (if active).
129+
The interceptor will intercept all calls to your application via the `preProcess()` interception point. Each request will then be validated against any registered security rules and then validated against any handler/action security annotations (if active) via a Security Validator. Also, if the request is made to a module, each module has the capability to have it's own separate validator apart from the global one.
130130

131131
> **Info** You can deactive annotation driven security via the `handlerAnnotationSecurity` setting.
132132
@@ -136,7 +136,7 @@ How does the interceptor know a user doesn't have access? Well, here is where yo
136136

137137
> **Info** You can find an interface for these methods in `cbsecurity.interfaces.ISecurityValidator`
138138
139-
The validator's job is to tell back to the firewall if they are allowed access and if they don't, what type of validation they broke: authentication or authorization.
139+
The validator's job is to tell back to the firewall if they are allowed access and if they don't, what type of validation they broke: **authentication** or **authorization**.
140140

141141
> `Authentication` is when a user is NOT logged in
142142
@@ -191,7 +191,7 @@ rules = [
191191

192192
### Global Rules
193193

194-
The global rules come from the `config/Coldbox.cfc`
194+
The global rules come from the `config/Coldbox.cfc` and they are defined within the `cbsecurity` module setting.
195195

196196
```js
197197
// Module Settings
@@ -261,8 +261,14 @@ settings = {
261261
cbsecurity = {
262262
// Module Relocation when an invalid access is detected, instead of each rule declaring one.
263263
"invalidAuthenticationEvent" : "mod1:secure.index",
264+
// Default Auhtentication Action: override or redirect when a user has not logged in
265+
"defaultAuthenticationAction" : "override",
264266
// Module override event when an invalid access is detected, instead of each rule declaring one.
265267
"invalidAuthorizationEvent" : "mod1:secure.auth",
268+
// Default Authorization Action: override or redirect when a user does not have enough permissions to access something
269+
"defaultAuthorizationAction" : "override",
270+
// Custom validator for the module.
271+
"validator" : "jwtService@cbsecurity"
266272
// You can define your security rules here or externally via a source
267273
"rules" : [
268274
{
@@ -345,23 +351,25 @@ Now that we have seen security rules and also security annotations let's see how
345351
* This function is called once an incoming event matches a security rule.
346352
* You will receive the security rule that matched and an instance of the ColdBox controller.
347353
*
348-
* You must return a struct with two keys:
354+
* You must return a struct with the following keys:
349355
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
350356
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
357+
* - messages:string Any messages for debugging
351358
*
352-
* @return { allow:boolean, type:string(authentication|authorization) }
359+
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
353360
*/
354361
struct function ruleValidator( required rule, required controller );
355362

356363
/**
357364
* This function is called once access to a handler/action is detected.
358365
* You will receive the secured annotation value and an instance of the ColdBox Controller
359366
*
360-
* You must return a struct with two keys:
367+
* You must return a struct with the following keys:
361368
* - allow:boolean True, user can continue access, false, invalid access actions will ensue
362369
* - type:string(authentication|authorization) The type of block that ocurred. Either an authentication or an authorization issue.
370+
* - messages:string Any messages for debugging
363371
*
364-
* @return { allow:boolean, type:string(authentication|authorization) }
372+
* @return { allow:boolean, type:string(authentication|authorization), messages:string }
365373
*/
366374
struct function annotationValidator( required securedValue, required controller );
367375
```
@@ -370,6 +378,7 @@ Each validator must return a struct with the following keys:
370378

371379
- `allow:boolean` A boolean indicator if authentication or authorization was violated
372380
- `type:stringOf(authentication|authorization)` A string that indicates the type of violation: authentication or authorization.
381+
- `messages:string` A string of messages used for debugging
373382

374383
Here is a sample validator using permission based security in both rules and annotation context
375384

@@ -382,7 +391,7 @@ struct function annotationValidator( required securedValue, required controller
382391
return permissionValidator( securedValue, controller );
383392
}
384393
private function permissionValidator( permissions, controller, rule ){
385-
var results = { "allow" : false, "type" : "authentication" };
394+
var results = { "allow" : false, "type" : "authentication", "messages" : "" };
386395
var user = security.getCurrentUser();
387396

388397
// First check if user has been authenticated.
@@ -416,7 +425,6 @@ You will receive the following data in the `interceptData` struct:
416425
- `annotationType` : The annotation type intercepted, `handler` or `action` or empty if rule driven
417426
- `processActions` : A boolean indicator that defaults to true. If you change this to false, then the interceptor won't fire the invalid actions. Usually this means, you manually will do them.
418427

419-
420428
## Security Visualizer
421429

422430
This module also ships with a security visualizer that will document all your security rules and your settings in a nice panel. In order to activate it you must add the `enableSecurityVisualizer` setting to your config and mark it as `true`. Once enabled you can navigate to: `/cbsecurity` and you will be presentd with the visualizer.
@@ -425,7 +433,6 @@ This module also ships with a security visualizer that will document all your se
425433
426434
<img src="https://raw.githubusercontent.com/coldbox-modules/cbsecurity/development/test-harness/visualizer.png" class="img-responsive">
427435

428-
429436
********************************************************************************
430437
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
431438
www.coldbox.org | www.luismajano.com | www.ortussolutions.com

0 commit comments

Comments
 (0)