Skip to content

Commit b97a8ad

Browse files
authored
feat(Storages): Allow customizing of storages
cbauth now exposes a `sessionStorage` and a `requestStorage` setting. These expect WireBox mappings and will use them inside inside of `authenticationService.` The defaults provided are `SessionStorage@cbstorages` and `RequestStorage@cbstorages` respectively. BREAKING CHANGE: The default `sessionStorage@cbauth` is now `SessionStorage@cbstorages`. Previously it was `CacheStorage@cbstorages`.
1 parent 50d27f5 commit b97a8ad

File tree

7 files changed

+33
-11
lines changed

7 files changed

+33
-11
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ language: java
22
sudo: required
33
jdk:
44
- oraclejdk8
5-
cache:
6-
directories:
7-
- "$HOME/.CommandBox/artifacts/"
8-
- "$HOME/.CommandBox/server/"
95
env:
106
matrix:
117
- ENGINE=adobe@2018

ModuleConfig.cfc

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

33
this.title = "cbauth";
4+
this.autoMapModels = false;
5+
this.dependencies = [ "cbstorages" ];
46

57
function configure() {
68
settings = {
7-
userServiceClass = ""
9+
userServiceClass = "",
10+
sessionStorage = "SessionStorage@cbstorages",
11+
requestStorage = "RequestStorage@cbstorages"
812
};
913

1014
interceptorSettings = {
@@ -13,6 +17,10 @@ component {
1317
}
1418

1519
function onLoad() {
20+
binder.map( "SessionStorage@cbauth" ).toDSL( settings.sessionStorage );
21+
binder.map( "RequestStorage@cbauth" ).toDSL( settings.requestStorage );
22+
binder.map( "AuthenticationService@cbauth" ).to( "#moduleMapping#.models.AuthenticationService" );
23+
1624
var helpers = controller.getSetting( "applicationHelper" );
1725
arrayAppend(
1826
helpers,
@@ -25,7 +33,7 @@ component {
2533
controller.setSetting(
2634
"applicationHelper",
2735
arrayFilter( controller.getSetting( "applicationHelper" ), function( helper ) {
28-
return helper != "#moduleMapping#/helpers/AuthenticationServiceHelpers.cfm";
36+
return helper != "#moduleMapping#/helpers/AuthenticationServiceHelpers.cfm";
2937
} )
3038
);
3139
}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Specify a `userServiceClass` in your `config/ColdBox.cfc` inside `moduleSettings
1616

1717
Additionally, the user component returned by the `retrieve` methods needs to respond to `getId()`.
1818

19+
You can also specify a `sessionStorage` and a `requestStorage` WireBox mapping.
20+
These will be used inside `AuthenticationService`. By default, these are
21+
`SessionStorage@cbstorages` and `RequestStorage@cbstorages` respectively.
22+
Interfaces are provided in the `models` folder for reference when building
23+
your own. (Your storage classes do not need to formally implement the interface.)
24+
1925
## Usage
2026

2127
You can inject the `authenticationService` using WireBox.
@@ -154,4 +160,4 @@ interceptData
154160
| sessionStorage | The sessionStorage object to store additional values if needed. |
155161
| requestStorage | The requestStorage object to store additional values if needed. |
156162

157-
This is the prime time to store additional values based on the user returned.
163+
This is the prime time to store additional values based on the user returned.

box.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"testbox":"^2.3.0+00044"
3232
},
3333
"installPaths":{
34-
"testbox":"testbox",
35-
"cbstorages":"modules/cbstorages"
34+
"testbox":"testbox/",
35+
"cbstorages":"modules/cbstorages/"
3636
},
3737
"scripts":{
3838
"postVersion":"package set location='elpete/cbauth#v`package version`'"

models/AuthenticationService.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ component singleton {
22

33
property name="wirebox" inject="wirebox";
44
property name="interceptorService" inject="coldbox:interceptorService";
5-
property name="sessionStorage" inject="CacheStorage@cbstorages";
6-
property name="requestStorage" inject="RequestStorage@cbstorages";
5+
property name="sessionStorage" inject="SessionStorage@cbauth";
6+
property name="requestStorage" inject="RequestStorage@cbauth";
77
property name="userServiceClass" inject="coldbox:setting:userServiceClass@cbauth";
88

99
variables.USER_ID_KEY = "cbauth__userId";

models/RequestStorageInterface.cfc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface name="RequestStorageInterface" {
2+
public any function getVar( required string name, any defaultValue );
3+
public void function setVar( required string name, required any value );
4+
public boolean function deleteVar( required string name );
5+
public boolean function exists( required string name );
6+
}

models/SessionStorageInterface.cfc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface name="SessionStorageInterface" {
2+
public any function getVar( required string name, any defaultValue );
3+
public void function setVar( required string name, required any value );
4+
public boolean function deleteVar( required string name );
5+
public boolean function exists( required string name );
6+
}

0 commit comments

Comments
 (0)