@@ -138,7 +138,7 @@ component accessors="true" singleton {
138
138
){
139
139
// Authenticate via the auth service wired up
140
140
// If it fails an exception is thrown
141
- var oUser = cbSecurity
141
+ var oUser = variables . cbSecurity
142
142
.getAuthService ()
143
143
.authenticate ( arguments .username , arguments .password );
144
144
@@ -159,14 +159,14 @@ component accessors="true" singleton {
159
159
*/
160
160
function logout (){
161
161
invalidate ( this .getToken () );
162
- cbSecurity .getAuthService ().logout ();
162
+ variables . cbSecurity .getAuthService ().logout ();
163
163
}
164
164
165
165
/**
166
166
* Shortcut function to our authentication services to check if we are logged in
167
167
*/
168
168
boolean function isLoggedIn (){
169
- return cbSecurity .getAuthService ().isLoggedIn ();
169
+ return variables . cbSecurity .getAuthService ().isLoggedIn ();
170
170
}
171
171
172
172
/**
@@ -313,6 +313,29 @@ component accessors="true" singleton {
313
313
return results ;
314
314
}
315
315
316
+ /**
317
+ * Invalidates all tokens in the connected storage provider
318
+ *
319
+ * @async Run the clearing asynchronously or not, default is false
320
+ */
321
+ JwtService function invalidateAll ( boolean async = false ){
322
+ if ( variables .log .canInfo () ) {
323
+ variables .log .info ( " Token invalidation request issued for all tokens" );
324
+ }
325
+
326
+ // Clear all via storage
327
+ getTokenStorage ().clearAll ( arguments .async );
328
+
329
+ // Announce the token invalidation
330
+ variables .interceptorService .processState ( " cbSecurity_onJWTInvalidateAllTokens" );
331
+
332
+ if ( variables .log .canInfo () ) {
333
+ variables .log .info ( " All tokens cleared via token storage clear all" );
334
+ }
335
+
336
+ return this ;
337
+ }
338
+
316
339
/**
317
340
* Verifies if the passed in token exists in the storage provider
318
341
*
@@ -328,33 +351,34 @@ component accessors="true" singleton {
328
351
329
352
/**
330
353
* Try's to get a jwt token from the authorization header or the custom header
331
- * defined in the configuration. If it is a valid token and it decodes we will then
332
- * continue to validat the subject it represents. Once those are satisfied, then it will
354
+ * defined in the configuration or passed in by you . If it is a valid token and it decodes we will then
355
+ * continue to validate the subject it represents. Once those are satisfied, then it will
333
356
* store it in the `prc` as `prc.jwt_token` and the payload as `prc.jwt_payload`.
334
357
*
358
+ * @token The token to parse and validate, if not passed we call the discoverToken() method for you.
359
+ *
335
360
* @throws TokenExpiredException If the token has expired or no longer in the storage (invalidated)
336
361
* @throws TokenInvalidException If the token doesn't verify decoding
337
362
* @throws TokenNotFoundException If the token cannot be found in the headers
338
363
*
339
364
* @return s The payload for convenience
340
365
*/
341
- struct function parseToken (){
342
- var jwtToken = discoverToken ();
366
+ struct function parseToken ( string token = discoverToken () ){
343
367
344
368
// Did we find an incoming token
345
- if ( ! len ( jwtToken ) ) {
369
+ if ( ! len ( arguments . token ) ) {
346
370
if ( variables .log .canDebug () ) {
347
- variables .log .debug ( " Token not found anywhere" );
371
+ variables .log .debug ( " Token empty or not found anywhere (headers, url, form) " );
348
372
}
349
373
350
374
throw (
351
- message = " Token not found in authorization header or the custom header or the request collection" ,
375
+ message = " Token not found in authorization header or the custom header or the request collection or not passed in " ,
352
376
type = " TokenNotFoundException"
353
377
);
354
378
}
355
379
356
380
// Decode it
357
- var decodedToken = decode ( jwtToken );
381
+ var decodedToken = decode ( arguments . token );
358
382
var decodedClaims = decodedToken .keyArray ();
359
383
360
384
// Verify the required claims
@@ -375,7 +399,7 @@ component accessors="true" singleton {
375
399
variables .interceptorService .processState (
376
400
" cbSecurity_onJWTInvalidClaims" ,
377
401
{
378
- token : jwtToken ,
402
+ token : arguments . token ,
379
403
payload : decodedToken
380
404
}
381
405
);
@@ -398,7 +422,7 @@ component accessors="true" singleton {
398
422
variables .interceptorService .processState (
399
423
" cbSecurity_onJWTExpiration" ,
400
424
{
401
- token : jwtToken ,
425
+ token : arguments . token ,
402
426
payload : decodedToken
403
427
}
404
428
);
@@ -416,7 +440,7 @@ component accessors="true" singleton {
416
440
variables .interceptorService .processState (
417
441
" cbSecurity_onJWTStorageRejection" ,
418
442
{
419
- token : jwtToken ,
443
+ token : arguments . token ,
420
444
payload : decodedToken
421
445
}
422
446
);
@@ -436,22 +460,22 @@ component accessors="true" singleton {
436
460
);
437
461
}
438
462
439
- // Store it
463
+ // Store it on the PRC scope values
440
464
variables .requestService
441
465
.getContext ()
442
- .setPrivateValue ( " jwt_token" , jwtToken )
466
+ .setPrivateValue ( " jwt_token" , arguments . token )
443
467
.setPrivateValue ( " jwt_payload" , decodedToken );
444
468
445
469
// Announce the valid parsing
446
470
variables .interceptorService .processState (
447
471
" cbSecurity_onJWTValidParsing" ,
448
472
{
449
- token : jwtToken ,
473
+ token : arguments . token ,
450
474
payload : decodedToken
451
475
}
452
476
);
453
477
454
- // Authenticate the payload
478
+ // Authenticate the payload, because a token MUST be valid before usage
455
479
authenticate ();
456
480
457
481
// Return it
@@ -669,7 +693,12 @@ component accessors="true" singleton {
669
693
/* ***************************** PRIVATE ******************************/
670
694
671
695
/**
672
- * Try to discover the jwt token from many incoming resources
696
+ * Try to discover the jwt token from many incoming resources:
697
+ * - The custom auth header: x-auth-token
698
+ * - URL/FORM: x-auth-token
699
+ * - Authorization Header
700
+ *
701
+ * @return The discovered token or an empty string
673
702
*/
674
703
private string function discoverToken (){
675
704
var event = variables .requestService .getContext ();
0 commit comments