Skip to content

Commit bc3ad99

Browse files
committed
finalized refactoring of jwt services to leverage the cbSecurity service
1 parent cfecdad commit bc3ad99

File tree

1 file changed

+8
-61
lines changed

1 file changed

+8
-61
lines changed

models/jwt/JwtService.cfc

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,12 @@ component accessors="true" singleton {
1717
property name="interceptorService" inject="coldbox:interceptorService";
1818
property name="requestService" inject="coldbox:requestService";
1919
property name="log" inject="logbox:logger:{this}";
20+
property name="cbsecurity" inject="@cbSecurity";
2021

2122
/*********************************************************************************************/
2223
/** PROPERTIES **/
2324
/*********************************************************************************************/
2425

25-
/**
26-
* The auth service in use
27-
*/
28-
property name="authService";
29-
30-
/**
31-
* The user service in use
32-
*/
33-
property name="userService";
34-
3526
/**
3627
* The token storage provider
3728
*/
@@ -145,7 +136,7 @@ component accessors="true" singleton {
145136
required password,
146137
struct customClaims = {}
147138
){
148-
var auth = getAuthService();
139+
var auth = cbSecurity.getAuthService();
149140

150141
if ( auth.authenticate( arguments.username, arguments.password ) ) {
151142
// Create it
@@ -164,14 +155,14 @@ component accessors="true" singleton {
164155
*/
165156
function logout(){
166157
invalidate( this.getToken() );
167-
getAuthService().logout();
158+
cbSecurity.getAuthService().logout();
168159
}
169160

170161
/**
171162
* Shortcut function to our authentication services to check if we are logged in
172163
*/
173164
boolean function isLoggedIn(){
174-
return getAuthService().isLoggedIn();
165+
return cbSecurity.getAuthService().isLoggedIn();
175166
}
176167

177168
/**
@@ -253,7 +244,7 @@ component accessors="true" singleton {
253244
*/
254245
function authenticate(){
255246
// Get the User it represents
256-
var oUser = getUserService().retrieveUserById( getPayload().sub );
247+
var oUser = variables.cbSecurity.getUserService().retrieveUserById( getPayload().sub );
257248

258249
// Verify it
259250
if ( isNull( oUser ) || !len( oUser.getId() ) ) {
@@ -273,7 +264,7 @@ component accessors="true" singleton {
273264
}
274265

275266
// Log in the user
276-
getAuthService().login( oUser );
267+
variables.cbSecurity.getAuthService().login( oUser );
277268

278269
// Store in ColdBox data bus
279270
variables.requestService
@@ -669,50 +660,6 @@ component accessors="true" singleton {
669660
return variables.tokenStorage;
670661
}
671662

672-
/**
673-
* Get the user service defined in the settings
674-
*/
675-
any function getUserService(){
676-
// If loaded, use it!
677-
if ( !isNull( variables.userService ) ) {
678-
return variables.userService;
679-
}
680-
681-
// Check and Load Baby!
682-
if ( !len( variables.settings.userService ) ) {
683-
throw(
684-
message = "No [userService] provided in the settings. Please set in `config/ColdBox.cfc` under `moduleSettings.cbsecurity.userService`.",
685-
type = "IncompleteConfiguration"
686-
);
687-
}
688-
689-
variables.userService = variables.wirebox.getInstance( variables.settings.userService );
690-
691-
return variables.userService;
692-
}
693-
694-
/**
695-
* Get the authentication service defined in the settings
696-
*/
697-
any function getAuthService(){
698-
// If loaded, use it!
699-
if ( !isNull( variables.authService ) ) {
700-
return variables.authService;
701-
}
702-
703-
// Check and Load Baby!
704-
if ( !len( variables.settings.authenticationService ) ) {
705-
throw(
706-
message = "No [authService] provided in the settings. Please set in `config/ColdBox.cfc` under `moduleSettings.cbsecurity.authenticationService`.",
707-
type = "IncompleteConfiguration"
708-
);
709-
}
710-
711-
variables.authService = variables.wirebox.getInstance( variables.settings.authenticationService );
712-
713-
return variables.authService;
714-
}
715-
716663
/****************************** PRIVATE ******************************/
717664

718665
/**
@@ -761,14 +708,14 @@ component accessors="true" singleton {
761708
}
762709

763710
// Are we logged in?
764-
if ( getAuthService().isLoggedIn() ) {
711+
if ( variables.cbSecurity.getAuthService().isLoggedIn() ) {
765712
// Do we have any permissions to validate?
766713
if ( listLen( arguments.permissions ) ) {
767714
// Check if the user has the right permissions?
768715
results.allow = (
769716
tokenHasScopes( arguments.permissions, payload.scopes )
770717
||
771-
getAuthService().getUser().hasPermission( arguments.permissions )
718+
variables.cbSecurity.getAuthService().getUser().hasPermission( arguments.permissions )
772719
);
773720
results.type = "authorization";
774721
} else {

0 commit comments

Comments
 (0)