@@ -125,12 +125,8 @@ component accessors="true" singleton{
125
125
// Append incoming custom claims with override, they take prescedence
126
126
structAppend ( payload , arguments .customClaims , true );
127
127
128
- // Create the token
129
- var jwtToken = jwt .encode (
130
- payload ,
131
- variables .settings .jwt .secretKey ,
132
- variables .settings .jwt .algorithm
133
- );
128
+ // Create the token for the user
129
+ var jwtToken = this .encode ( payload );
134
130
135
131
// Store it with the expiration as well if enabled
136
132
if ( variables .settings .jwt .tokenStorage .enabled ){
@@ -142,6 +138,13 @@ component accessors="true" singleton{
142
138
);
143
139
}
144
140
141
+ // Announce the creation
142
+ variables .interceptorService .processState ( " cbSecurity_onJWTCreation" , {
143
+ token : jwtToken ,
144
+ payload : arguments .payload ,
145
+ user : arguments .user
146
+ } );
147
+
145
148
// Return it
146
149
return jwtToken ;
147
150
}
@@ -158,6 +161,12 @@ component accessors="true" singleton{
158
161
159
162
// Verify it
160
163
if ( isNull ( oUser ) || ! len ( oUser .getId () ) ){
164
+ // Announce the creation
165
+ variables .interceptorService .processState ( " cbSecurity_onJWTInvalidUser" , {
166
+ token : this .getToken (),
167
+ payload : this .getPayload ()
168
+ } );
169
+
161
170
throw (
162
171
message = " The user (#getPayload ().sub #) was not found by the user service" ,
163
172
type = " InvalidTokenUser"
@@ -172,6 +181,13 @@ component accessors="true" singleton{
172
181
.getContext ()
173
182
.setPrivateValue ( variables .settings .prcUserVariable , oUser );
174
183
184
+ // Announce the creation
185
+ variables .interceptorService .processState ( " cbSecurity_onJWTValidAuthentication" , {
186
+ token : this .getToken (),
187
+ payload : this .getPayload (),
188
+ user : oUser
189
+ } );
190
+
175
191
// Return the user
176
192
return oUser ;
177
193
}
@@ -185,7 +201,13 @@ component accessors="true" singleton{
185
201
if ( variables .log .canInfo () ){
186
202
variables .log .info ( " Token invalidation request issued for :#arguments .token #" );
187
203
}
188
- return getTokenStorage ().clear ( arguments .token );
204
+
205
+ var results = getTokenStorage ().clear ( arguments .token );
206
+
207
+ // Announce the creation
208
+ variables .interceptorService .processState ( " cbSecurity_onJWTInvalidation" , {
209
+ token : arguments .token
210
+ } );
189
211
}
190
212
191
213
/* ***********************************************************************************/
@@ -236,6 +258,12 @@ component accessors="true" singleton{
236
258
variables .log .warn ( " Token is invalid as it does not contain the `#arguments .item #` claim" , decodedToken );
237
259
}
238
260
261
+ // Announce the creation
262
+ variables .interceptorService .processState ( " cbSecurity_onJWTInvalidClaims" , {
263
+ token : jwtToken ,
264
+ payload : decodedToken
265
+ } );
266
+
239
267
throw (
240
268
message = " Token is invalid as it does not contain the `#arguments .item #` claim" ,
241
269
type = " TokenInvalidException"
@@ -250,6 +278,12 @@ component accessors="true" singleton{
250
278
variables .log .warn ( " Token rejected, it has expired" , decodedToken );
251
279
}
252
280
281
+ // Announce the creation
282
+ variables .interceptorService .processState ( " cbSecurity_onJWTExpiration" , {
283
+ token : jwtToken ,
284
+ payload : decodedToken
285
+ } );
286
+
253
287
throw (
254
288
message = " Token has expired" ,
255
289
type = " TokenExpiredException"
@@ -262,6 +296,12 @@ component accessors="true" singleton{
262
296
variables .log .warn ( " Token rejected, it was not found in token storage" , decodedToken );
263
297
}
264
298
299
+ // Announce the creation
300
+ variables .interceptorService .processState ( " cbSecurity_onJWTStorageRejection" , {
301
+ token : jwtToken ,
302
+ payload : decodedToken
303
+ } );
304
+
265
305
throw (
266
306
message = " Token has expired, not found in storage" ,
267
307
detail = " Storage lookup failed" ,
@@ -280,6 +320,12 @@ component accessors="true" singleton{
280
320
.setPrivateValue ( " jwt_token" , jwtToken )
281
321
.setPrivateValue ( " jwt_payload" , decodedToken );
282
322
323
+ // Announce the creation
324
+ variables .interceptorService .processState ( " cbSecurity_onJWTValidParsing" , {
325
+ token : jwtToken ,
326
+ payload : decodedToken
327
+ } );
328
+
283
329
// Authenticate the payload
284
330
authenticate ();
285
331
0 commit comments