Skip to content

Commit 778cd73

Browse files
authored
feat: Added interception points and return user from authorize
Added `preLogout` and `postLogout` interception points. Also, return the user from `authorize`. Previously this returned `true`. BREAKING CHANGE: `authorize` returns a `user` instance, not a boolean. If the `authorize` call fails, it will throw an exception as before.
1 parent 16f6f47 commit 778cd73

13 files changed

+805
-491
lines changed

.cfformat.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"array.empty_padding": false,
3+
"array.padding": true,
4+
"array.multiline.min_length": 40,
5+
"array.multiline.element_count": 2,
6+
"array.multiline.leading_comma.padding": true,
7+
"array.multiline.leading_comma": false,
8+
"alignment.consecutive.assignments": true,
9+
"alignment.consecutive.properties": true,
10+
"alignment.consecutive.params": true,
11+
"brackets.padding": true,
12+
"comment.asterisks": "align",
13+
"binary_operators.padding": true,
14+
"for_loop_semicolons.padding": true,
15+
"function_call.empty_padding": false,
16+
"function_call.padding": true,
17+
"function_call.multiline.leading_comma.padding": true,
18+
"function_call.casing.builtin": "cfdocs",
19+
"function_call.casing.userdefined": "camel",
20+
"function_call.multiline.element_count": 3,
21+
"function_call.multiline.leading_comma": false,
22+
"function_call.multiline.min_length": 40,
23+
"function_declaration.padding": true,
24+
"function_declaration.empty_padding": false,
25+
"function_declaration.multiline.leading_comma": false,
26+
"function_declaration.multiline.leading_comma.padding": true,
27+
"function_declaration.multiline.element_count": 3,
28+
"function_declaration.multiline.min_length": 40,
29+
"function_declaration.group_to_block_spacing": "spaced",
30+
"function_anonymous.empty_padding": false,
31+
"function_anonymous.group_to_block_spacing": "spaced",
32+
"function_anonymous.multiline.element_count": 3,
33+
"function_anonymous.multiline.leading_comma": false,
34+
"function_anonymous.multiline.leading_comma.padding": true,
35+
"function_anonymous.multiline.min_length": 40,
36+
"function_anonymous.padding": true,
37+
"indent_size": 4,
38+
"keywords.block_to_keyword_spacing": "spaced",
39+
"keywords.group_to_block_spacing": "spaced",
40+
"keywords.padding_inside_group": true,
41+
"keywords.spacing_to_block": "spaced",
42+
"keywords.spacing_to_group": true,
43+
"keywords.empty_group_spacing": false,
44+
"max_columns": 120,
45+
"metadata.multiline.element_count": 3,
46+
"metadata.multiline.min_length": 40,
47+
"newline":"\n",
48+
"property.multiline.element_count": 3,
49+
"property.multiline.min_length": 40,
50+
"parentheses.padding": true,
51+
"strings.quote": "double",
52+
"strings.attributes.quote": "double",
53+
"struct.separator": ": ",
54+
"struct.padding": true,
55+
"struct.empty_padding": false,
56+
"struct.multiline.leading_comma": false,
57+
"struct.multiline.leading_comma.padding": true,
58+
"struct.multiline.element_count": 2,
59+
"struct.multiline.min_length": 40,
60+
"tab_indent": true
61+
}

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
indent_style = tab
11+
indent_size = 4
12+
tab_width = 4
13+
14+
[*.yml]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[*.{md,markdown}]
19+
trim_trailing_whitespace = false
20+
insert_final_newline = false

.travis.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,53 @@ language: java
22
sudo: required
33
jdk:
44
- openjdk8
5+
cache:
6+
directories:
7+
- "$HOME/.CommandBox/artifacts/"
8+
- "$HOME/.CommandBox/server/"
59
env:
6-
matrix:
7-
- ENGINE=adobe@2018
8-
- ENGINE=adobe@2016
9-
- ENGINE=lucee@5
10+
global:
11+
- MODULE_ID=cbauth
12+
jobs:
13+
- ENGINE=adobe@2018 COLDBOX_VERSION=stable
14+
- ENGINE=adobe@2016 COLDBOX_VERSION=stable
15+
- ENGINE=lucee@5 COLDBOX_VERSION=stable
16+
- ENGINE=adobe@2018 COLDBOX_VERSION=be
17+
- ENGINE=adobe@2016 COLDBOX_VERSION=be
18+
- ENGINE=lucee@5 COLDBOX_VERSION=be
1019
before_install:
1120
- curl -fsSl https://downloads.ortussolutions.com/debs/gpg | sudo apt-key add -
1221
- sudo echo "deb http://downloads.ortussolutions.com/debs/noarch /" | sudo tee -a /etc/apt/sources.list.d/commandbox.list
1322
install:
1423
- sudo apt-get update && sudo apt-get --assume-yes install commandbox
24+
- box install commandbox-cfconfig,commandbox-cfformat
1525
- box install
26+
- box install coldbox@${COLDBOX_VERSION} --force
1627
before_script:
1728
- box server start cfengine=$ENGINE port=8500
1829
script:
1930
- box testbox run runner='http://127.0.0.1:8500/tests/runner.cfm'
31+
- box run-script format:check
2032
after_success:
21-
- box install commandbox-semantic-release
33+
- box install commandbox-docbox,commandbox-semantic-release
2234
- box config set endpoints.forgebox.APIToken=${FORGEBOX_TOKEN}
2335
- box semantic-release
36+
before_deploy:
37+
- # Set Current Version
38+
- TARGET_VERSION=`cat $TRAVIS_BUILD_DIR/box.json | jq '.version' -r`
39+
- box run-script generateAPIDocs
40+
deploy:
41+
provider: s3
42+
on:
43+
branch: master
44+
condition: $ENGINE = adobe@2018
45+
skip_cleanup: true
46+
#AWS Credentials need to be set in Travis
47+
access_key_id: $AWS_ACCESS_KEY
48+
secret_access_key: $AWS_ACCESS_SECRET
49+
bucket: "apidocs.ortussolutions.com"
50+
local_dir: $TRAVIS_BUILD_DIR/.tmp/apidocs
51+
upload_dir: coldbox-modules/$MODULE_ID/$TARGET_VERSION
52+
acl: public_read
2453
notifications:
2554
email: false

ModuleConfig.cfc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
component {
22

33
this.title = "cbauth";
4+
// Don't map models, we will do it manually
45
this.autoMapModels = false;
6+
// Module Dependencies
57
this.dependencies = [ "cbstorages" ];
8+
// Helpers automatically loaded
9+
this.applicationHelper = [ "helpers/Mixins.cfm" ];
610

711
function configure() {
812
settings = {
@@ -11,31 +15,26 @@ component {
1115
requestStorage = "RequestStorage@cbstorages"
1216
};
1317

18+
// Custom Events
1419
interceptorSettings = {
15-
customInterceptionPoints = "preAuthentication,postAuthentication"
20+
customInterceptionPoints = [
21+
"preAuthentication",
22+
"postAuthentication",
23+
"preLogout",
24+
"postLogout",
25+
"preLogin",
26+
"postLogin"
27+
]
1628
};
1729
}
1830

1931
function onLoad() {
2032
binder.map( "SessionStorage@cbauth" ).toDSL( settings.sessionStorage );
2133
binder.map( "RequestStorage@cbauth" ).toDSL( settings.requestStorage );
2234
binder.map( "AuthenticationService@cbauth" ).to( "#moduleMapping#.models.AuthenticationService" );
23-
24-
var helpers = controller.getSetting( "applicationHelper" );
25-
arrayAppend(
26-
helpers,
27-
"#moduleMapping#/helpers/AuthenticationServiceHelpers.cfm"
28-
);
29-
controller.setSetting( "applicationHelper", helpers );
3035
}
3136

3237
function onUnload() {
33-
controller.setSetting(
34-
"applicationHelper",
35-
arrayFilter( controller.getSetting( "applicationHelper" ), function( helper ) {
36-
return helper != "#moduleMapping#/helpers/AuthenticationServiceHelpers.cfm";
37-
} )
38-
);
3938
}
4039

4140
}

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# cbauth
22

3-
Wrapper for authentication for ColdBox.
3+
Authentication services for ColdBox Applications.
4+
5+
## Requirements
6+
7+
- Lucee 5+
8+
- Adobe ColdFusion 2016+
49

510
## Installation
611

@@ -14,7 +19,9 @@ Specify a `userServiceClass` in your `config/ColdBox.cfc` inside `moduleSettings
1419
2. `retrieveUserByUsername( username )`
1520
3. `retrieveUserById( id )`
1621

17-
Additionally, the user component returned by the `retrieve` methods needs to respond to `getId()`.
22+
> We have provided an interface to implement and can be found at `cbauth.interfaces.IUserService`.
23+
24+
Additionally, the user component returned by the `retrieve` methods needs to respond to `getId()`. We have also provided a nice interface for you to follow: `cbauth.interfaces.IAuthUser`
1825

1926
You can also specify a `sessionStorage` and a `requestStorage` WireBox mapping.
2027
These will be used inside `AuthenticationService`. By default, these are
@@ -51,7 +58,7 @@ This is very useful in views. And since WireBox handles singleton management, y
5158
| user | any | true | | The user component to log in. The component must respond to the `getId()` method. |
5259

5360
Logs a user in to the system. The user component must respond to the `getId()` method. Additionally, the user is cached in the `request` scope. If a user is already in the session, this will replace it with the given user.
54-
61+
This method returns the passed in `user` object.
5562

5663
### `logout`
5764

@@ -61,7 +68,6 @@ Logs a user in to the system. The user component must respond to the `getId()`
6168

6269
Logs a user out of system. This method can be called regardless of if there is currently a logged in user.
6370

64-
6571
### `authenticate`
6672

6773
| name | type | required | default | description |
@@ -71,8 +77,7 @@ Logs a user out of system. This method can be called regardless of if there is
7177

7278
Attempts to log a user by calling the `isValidCredentials` and `retrieveUserByUsername` on the provided `userServiceClass`. If `isValidCredentials` returns `false`, it throws a `InvalidCredentials` exception.
7379

74-
If it succeeds, it returns `true`. If it succeeds, it also sets the user id (obtained by calling `getId()` on the returned user component) in the session and the returned user component in the request.
75-
80+
If it succeeds, it returns the logged in `user` object. If it succeeds, it also sets the user id (obtained by calling `getId()` on the returned user component) in the session and the returned user component in the request.
7681

7782
### `isLoggedIn`
7883

@@ -82,7 +87,6 @@ If it succeeds, it returns `true`. If it succeeds, it also sets the user id (ob
8287

8388
Returns whether a user is logged in to the system.
8489

85-
8690
### `check`
8791

8892
| name | type | required | default | description |
@@ -91,7 +95,6 @@ Returns whether a user is logged in to the system.
9195

9296
_Alias for [`isLoggedIn`](#isLoggedIn)_
9397

94-
9598
### `guest`
9699

97100
| name | type | required | default | description |
@@ -100,7 +103,6 @@ _Alias for [`isLoggedIn`](#isLoggedIn)_
100103

101104
Returns whether a user is logged out of the system.
102105

103-
104106
### `getUser`
105107

106108
| name | type | required | default | description |
@@ -113,7 +115,6 @@ If there is no logged in user, it throws a `NoUserLoggedIn` exception.
113115

114116
Additionally, it sets the user in the `request` scope so subsequent calls to `getUser` don't re-fetch the user from the database or other permanent storage.
115117

116-
117118
### `user`
118119

119120
| name | type | required | default | description |
@@ -122,7 +123,6 @@ Additionally, it sets the user in the `request` scope so subsequent calls to `ge
122123

123124
_Alias for [`getUser`](#getUser)_
124125

125-
126126
### `getUserId`
127127

128128
| name | type | required | default | description |
@@ -133,10 +133,9 @@ Returns the currently logged in user id.
133133

134134
If there is no logged in user, it throws a `NoUserLoggedIn` exception.
135135

136+
## Interception Points
136137

137-
## Interception Points — (preAuthentication & postAuthentication)
138-
139-
cbauth announces several custom interception points. You can use these interception points to change request data or add additional values to session or request scopes. The `preAuthentication` and `postAuthentication` events fire during the standard `authenticate()` method call with a username and password. The `preLogin` and `postLogin` events fire during the `login()` method call.
138+
cbauth announces several custom interception points. You can use these interception points to change request data or add additional values to session or request scopes. The `preAuthentication` and `postAuthentication` events fire during the standard `authenticate()` method call with a username and password. The `preLogin` and `postLogin` events fire during the `login()` method call. The `preLogout` and `postLogout` events fire during the `logout()` method call.
140139

141140
Note: the `preLogin` and `postLogin` interception points will be called during the course of `authenticate()`. The order of the calls then are `preAuthentication` -> `preLogin` -> `postLogin` -> `postAuthentication`.
142141

@@ -151,7 +150,6 @@ interceptData
151150

152151
Modifying the values in the `interceptData` will change what is passed to `isValidCredentials` and `retrieveUserByUsername`. This is the prime time to ignore certain requests or remove or pad usernames.
153152

154-
155153
### `postAuthentication`
156154

157155
interceptData
@@ -172,7 +170,6 @@ interceptData
172170
| --- | --- |
173171
| user | The user component to be logged in. |
174172

175-
176173
### `postLogin`
177174

178175
interceptData
@@ -183,5 +180,19 @@ interceptData
183180
| sessionStorage | The sessionStorage object to store additional values if needed. |
184181
| requestStorage | The requestStorage object to store additional values if needed. |
185182

186-
187183
This is a good opportunity to store additional data if your application logged the user in manually without authenticating via a username/password like a "remember me" system.
184+
185+
### `preLogout`
186+
187+
interceptData
188+
189+
| name | description |
190+
| --- | --- |
191+
| user | The user component that is logged in if you are logged in, else `null` |
192+
193+
### `postLogout`
194+
195+
interceptData
196+
197+
| name | description |
198+
| --- | --- |

box.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"location":"forgeboxStorage",
55
"author":[
66
"Eric Peterson",
7-
"Mike Burt"
7+
"Mike Burt",
8+
"Luis Majano"
89
],
910
"repository":{
1011
"type":"git",
1112
"URL":"https://github.com/coldbox-modules/cbauth"
1213
},
1314
"slug":"cbauth",
14-
"shortDescription":"Helpers for authentication in ColdBox",
15+
"shortDescription":"Authentication services for ColdBox Applications.",
1516
"type":"modules",
1617
"keywords":[
1718
"authentication",
@@ -34,10 +35,16 @@
3435
"testbox":"testbox/",
3536
"cbstorages":"modules/cbstorages/"
3637
},
37-
"scripts":{},
38+
"scripts":{
39+
"format": "cfformat run models/**/*.cfc,tests/specs/**/*.cfc --overwrite",
40+
"format:check": "cfformat check models/**/*.cfc,tests/specs/**/*.cfc --verbose",
41+
"generateAPIDocs":"rm .tmp --recurse --force && docbox generate mapping=cbauth excludes=tests|ModuleConfig strategy-outputDir=.tmp/apidocs strategy-projectTitle=cbauth"
42+
},
3843
"ignore":[
3944
"**/.*",
4045
"test",
41-
"tests"
46+
"tests",
47+
"docs/**/*.*",
48+
"server.json"
4249
]
4350
}
File renamed without changes.

interfaces/IAuthUser.cfc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright since 2016 by Ortus Solutions, Corp
3+
* www.ortussolutions.com
4+
* ---
5+
* If you use a user with a user service or authentication service, it must implement this interface
6+
*/
7+
interface{
8+
9+
/**
10+
* Return the unique identifier for the user
11+
*/
12+
function getId();
13+
14+
}

0 commit comments

Comments
 (0)