Skip to content

Commit 5fcff02

Browse files
committed
cfformat on all
1 parent c86bc2f commit 5fcff02

File tree

20 files changed

+327
-380
lines changed

20 files changed

+327
-380
lines changed

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This module will enhance your ColdBox applications by providing out of the box s
66

77
- A security rule engine for incoming requests
88
- Annotation driven security for handlers and actions
9+
- JWT (Json Web Tokens) generator, decoder and authentication services
10+
- Pluggable with any Authentication service or can leverage [cbauth](https://github.com/elpete/cbauth)
911

1012
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.
1113

test-harness/box.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@
2424
},
2525
"testbox":{
2626
"runner":"http://localhost:60299/tests/runner.cfm"
27-
}
27+
},
28+
"scripts" : {
29+
"format": "cfformat config/**.cfc,handlers/**.cfc,models/**.cfc,modules_app/**.cfc,tests/specs/**/*.cfc --overwrite",
30+
"format:watch": "cfformat config/**.cfc,handlers/**.cfc,models/**.cfc,modules_app/**.cfc,tests/specs/**/*.cfc --watch",
31+
"format:check": "cfformat config/**.cfc,handlers/**.cfc,models/**.cfc,modules_app/**.cfc,tests/specs/**/*.cfc --check"
32+
}
2833
}

test-harness/config/Coldbox.cfc

Lines changed: 60 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
// coldbox directives
55
coldbox = {
66
// Application Setup
7-
appName : "Module Tester",
7+
appName : "Module Tester",
88
// Development Settings
9-
reinitPassword : "",
9+
reinitPassword : "",
1010
handlersIndexAutoReload : true,
1111
modulesExternalLocation : [],
1212
// Implicit Events
13-
defaultEvent : "",
14-
requestStartHandler : "",
15-
requestEndHandler : "",
13+
defaultEvent : "",
14+
requestStartHandler : "",
15+
requestEndHandler : "",
1616
applicationStartHandler : "",
17-
applicationEndHandler : "",
18-
sessionStartHandler : "",
19-
sessionEndHandler : "",
20-
missingTemplateHandler : "",
17+
applicationEndHandler : "",
18+
sessionStartHandler : "",
19+
sessionEndHandler : "",
20+
missingTemplateHandler : "",
2121
// Error/Exception Handling
22-
exceptionHandler : "",
23-
onInvalidEvent : "",
24-
customErrorTemplate : "/coldbox/system/includes/BugReport.cfm",
22+
exceptionHandler : "",
23+
onInvalidEvent : "",
24+
customErrorTemplate : "/coldbox/system/includes/BugReport.cfm",
2525
// Application Aspects
26-
handlerCaching : false,
27-
eventCaching : false
26+
handlerCaching : false,
27+
eventCaching : false,
28+
autoMapModels : true
2829
};
2930

3031
// environment settings, create a detectEnvironment() method to detect it yourself.
@@ -41,107 +42,90 @@
4142
};
4243

4344
// Register interceptors as an array, we need order
44-
interceptors = [
45-
// SES
46-
{ class : "coldbox.system.interceptors.SES" }
47-
];
45+
interceptors = [];
4846

4947
// LogBox DSL
5048
logBox = {
5149
// Define Appenders
5250
appenders : {
5351
files : {
54-
class : "coldbox.system.logging.appenders.RollingFileAppender",
52+
class : "coldbox.system.logging.appenders.RollingFileAppender",
5553
properties : { filename : "tester", filePath : "/#appMapping#/logs" }
5654
},
57-
console : {
58-
class : "coldbox.system.logging.appenders.ConsoleAppender"
59-
}
55+
console : { class : "coldbox.system.logging.appenders.ConsoleAppender" }
6056
},
6157
// Root Logger
62-
root : { levelmax : "DEBUG", appenders : "*" },
58+
root : { levelmax : "DEBUG", appenders : "*" },
6359
// Implicit Level Categories
64-
info : [ "coldbox.system" ],
60+
info : [ "coldbox.system" ],
6561
debug : [ "cbsecurity" ]
6662
};
6763

6864
// Module Settings
6965
moduleSettings = {
7066
// CB Auth
71-
cbAuth : {
72-
userServiceClass : "UserService"
73-
},
67+
cbAuth : { userServiceClass : "UserService" },
7468
// CB Security
7569
cbSecurity : {
7670
// Global Relocation when an invalid access is detected, instead of each rule declaring one.
77-
"invalidAuthenticationEvent" : "main.index",
71+
"invalidAuthenticationEvent" : "main.index",
7872
// Global override event when an invalid access is detected, instead of each rule declaring one.
79-
"invalidAuthorizationEvent" : "main.index",
73+
"invalidAuthorizationEvent" : "main.index",
8074
// Default invalid action: override or redirect when an invalid access is detected, default is to redirect
81-
"defaultAuthorizationAction" : "redirect",
75+
"defaultAuthorizationAction" : "redirect",
8276
// The WireBox ID of the authentication service to use in cbSecurity which must adhere to the cbsecurity.interfaces.IAuthService interface.
83-
"authenticationService" : "authenticationService@cbauth",
77+
"authenticationService" : "authenticationService@cbauth",
8478
// WireBox ID of the user service to use
85-
"userService" : "UserService",
79+
"userService" : "UserService",
8680
// Enable Visualizer
87-
"enableSecurityVisualizer" : true,
81+
"enableSecurityVisualizer" : true,
8882
// The global security rules
89-
"rules" : [
83+
"rules" : [
9084
// should use direct action and do a global redirect
9185
{
92-
"whitelist": "",
93-
"securelist": "admin",
94-
"match": "event",
95-
"roles": "admin",
96-
"permissions": "",
97-
"action" : "redirect"
86+
"whitelist" : "",
87+
"securelist" : "admin",
88+
"match" : "event",
89+
"roles" : "admin",
90+
"permissions" : "",
91+
"action" : "redirect"
9892
},
9993
// no action, use global default action
10094
{
101-
"whitelist": "",
102-
"securelist": "noAction",
103-
"match": "url",
104-
"roles": "admin",
105-
"permissions": ""
95+
"whitelist" : "",
96+
"securelist" : "noAction",
97+
"match" : "url",
98+
"roles" : "admin",
99+
"permissions" : ""
106100
},
107101
// Using overrideEvent only, so use an explicit override
108-
{
109-
"securelist": "ruleActionOverride",
110-
"match": "url",
111-
"overrideEvent": "main.login"
112-
},
102+
{ "securelist" : "ruleActionOverride", "match" : "url", "overrideEvent" : "main.login" },
113103
// direct action, use global override
114104
{
115-
"whitelist": "",
116-
"securelist": "override",
117-
"match": "url",
118-
"roles": "",
119-
"permissions": "",
120-
"action" : "override"
105+
"whitelist" : "",
106+
"securelist" : "override",
107+
"match" : "url",
108+
"roles" : "",
109+
"permissions" : "",
110+
"action" : "override"
121111
},
122112
// Using redirect only, so use an explicit redirect
123-
{
124-
"securelist": "ruleActionRedirect",
125-
"match": "url",
126-
"redirect": "main.login"
127-
}
113+
{ "securelist" : "ruleActionRedirect", "match" : "url", "redirect" : "main.login" }
128114
],
129115
// JWT Settings
130-
"jwt" : {
131-
"secretKey" : "C3D4AF35-8FCD-49AB-943A39AEFFB584EE",
132-
"customAuthHeader" : "x-auth-token",
133-
"expiration" : 60,
134-
"enableRefreshTokens" : false,
135-
"refreshExpiration" : 43200,
136-
"algorithm" : "HS512",
137-
"requiredClaims" : [ "role" ],
138-
"tokenStorage" : {
139-
"enabled" : true,
140-
"keyPrefix" : "cbjwt_",
141-
"driver" : "cachebox",
142-
"properties" : {
143-
"cacheName" : "default"
144-
}
116+
"jwt" : {
117+
"secretKey" : "C3D4AF35-8FCD-49AB-943A39AEFFB584EE",
118+
"customAuthHeader" : "x-auth-token",
119+
"expiration" : 60,
120+
"enableRefreshTokens" : false,
121+
"refreshExpiration" : 43200,
122+
"algorithm" : "HS512",
123+
"requiredClaims" : [ "role" ],
124+
"tokenStorage" : {
125+
"enabled" : true,
126+
"keyPrefix" : "cbjwt_",
127+
"driver" : "cachebox",
128+
"properties" : { "cacheName" : "default" }
145129
}
146130
}
147131
}

test-harness/config/WireBox.cfc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
// By default it registeres itself on application scope
1010
scopeRegistration : {
1111
enabled : true,
12-
scope : "application", // server, cluster, session, application
13-
key : "wireBox"
12+
scope : "application", // server, cluster, session, application
13+
key : "wireBox"
1414
},
1515
// DSL Namespace registrations
16-
customDSL : {},
16+
customDSL : {},
1717
// Custom Storage Scopes
18-
customScopes : {},
18+
customScopes : {},
1919
// Package scan locations
20-
scanLocations : [],
20+
scanLocations : [],
2121
// Stop Recursions
2222
stopRecursions : [],
2323
// Parent Injector to assign to the configured injector, this must be an object reference
2424
parentInjector : "",
2525
// Register all event listeners here, they are created in the specified order
26-
listeners : []
26+
listeners : []
2727
};
2828

2929
// Map Bindings below
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* I am a new secured handler
33
*/
4-
component secured{
4+
component secured {
55

66
function index( event, rc, prc ){
77
return "secured handler";
88
}
99

1010
/**
11-
* secret
12-
*/
11+
* secret
12+
*/
1313
function secret( event, rc, prc ) secured="awesome-admin"{
1414
return "Mega secured action!";
1515
}
1616

17-
}
17+
}

test-harness/handlers/Main.cfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ component {
1414
}
1515

1616
/**
17-
* login
18-
*/
17+
* login
18+
*/
1919
function login( event, rc, prc ){
2020
event.setView( "main/login" );
2121
}
2222

2323
/**
24-
* doLogin
25-
*/
24+
* doLogin
25+
*/
2626
function doLogin( event, rc, prc ){
2727
return "login";
2828
}

test-harness/handlers/Public.cfc

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
component{
1+
component {
22

33
property name="jwt" inject="provider:JWTService@jwt";
44
property name="bcrypt" inject="@BCrypt";
@@ -13,40 +13,35 @@ component{
1313
}
1414

1515
/**
16-
* pass
17-
*/
16+
* pass
17+
*/
1818
function pass( event, rc, prc ){
1919
return variables.bcrypt.hashPassword( "test" );
2020
}
2121

2222
/**
23-
* gen
24-
*/
23+
* gen
24+
*/
2525
function gen( event, rc, prc ){
2626
var start = now();
27-
return jwt.encode( {
28-
"iss" : event.buildLink(),
29-
"iat" : toEpoch( start ),
30-
"sub" : 0,
31-
"exp" : toEpoch( dateAdd( "n", 60, start ) ),
32-
"jti" : hash( start & 0 )
33-
}, variables.secretKey );
27+
return jwt.encode(
28+
{
29+
"iss" : event.buildLink(),
30+
"iat" : toEpoch( start ),
31+
"sub" : 0,
32+
"exp" : toEpoch( dateAdd( "n", 60, start ) ),
33+
"jti" : hash( start & 0 )
34+
},
35+
variables.secretKey
36+
);
3437
}
3538

3639
function toEpoch( required target ){
37-
return dateDiff(
38-
's',
39-
dateConvert( "utc2local", "January 1 1970 00:00" ),
40-
arguments.target
41-
);
40+
return dateDiff( "s", dateConvert( "utc2local", "January 1 1970 00:00" ), arguments.target );
4241
}
4342

4443
function fromEpoch( required target ){
45-
return DateAdd(
46-
"s",
47-
arguments.target, // should be in utc
48-
dateConvert( "utc2local", "January 1 1970 00:00" )
49-
);
44+
return dateAdd( "s", arguments.target, dateConvert( "utc2local", "January 1 1970 00:00" ) );
5045
}
5146

52-
}
47+
}

test-harness/handlers/admin.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ component {
77
event.setView( "admin/index" );
88
}
99

10-
}
10+
}

test-harness/handlers/jwt.cfc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/**
2-
* My Event Handler Hint
3-
*/
4-
component extends="coldbox.system.EventHandler"{
2+
* My Event Handler Hint
3+
*/
4+
component extends="coldbox.system.EventHandler" {
55

66
property name="jwtService" inject="JwtService@cbSecurity";
77

88
/**
9-
* Index
10-
*/
9+
* Index
10+
*/
1111
any function index( event, rc, prc ){
12-
1312
}
1413

1514
}

0 commit comments

Comments
 (0)