15
15
* - id : db identifier
16
16
* - cacheKey : varchar 255
17
17
* - token : text
18
- * - expiration : varchar 255 (unix timestamp)
18
+ * - expiration : (unix timestamp)
19
+ * - issued : (unix timestamp)
19
20
* - subject : varchar 255
20
21
*
21
22
*/
@@ -25,6 +26,7 @@ component accessors="true" singleton{
25
26
property name = " wirebox" inject = " wirebox" ;
26
27
property name = " cachebox" inject = " cachebox" ;
27
28
property name = " settings" inject = " coldbox:moduleSettings:cbSecurity" ;
29
+ property name = " jwtService" inject = " JwtService@cbSecurity" ;
28
30
29
31
/**
30
32
* Storage properties
@@ -41,7 +43,7 @@ component accessors="true" singleton{
41
43
*/
42
44
property name = " keyPrefix" ;
43
45
44
- variables .COLUMNS = " id,cacheKey,token,expiration,created ,subject" ;
46
+ variables .COLUMNS = " id,cacheKey,token,expiration,issued ,subject" ;
45
47
46
48
/**
47
49
* Constructor
@@ -111,16 +113,16 @@ component accessors="true" singleton{
111
113
:cacheKey,
112
114
:token,
113
115
:expiration,
114
- :created ,
116
+ :issued ,
115
117
:subject
116
118
)
117
119
" ,
118
120
{
119
121
uuid = { cfsqltype = " varchar" , value = " #variables .uuid .randomUUID ().toString () #" },
120
122
cacheKey = { cfsqltype = " varchar" , value = arguments .key },
121
123
token = { cfsqltype = " longvarchar" ,value = arguments .token },
122
- expiration = { cfsqltype = " varchar " , value = arguments .expiration },
123
- created = { cfsqltype = " timestamp" , value = now ( ) },
124
+ expiration = { cfsqltype = " timestamp " , value = jwtService . fromEpoch ( arguments .payload . exp ) },
125
+ issued = { cfsqltype = " timestamp" , value = jwtService . fromEpoch ( arguments . payload . iat ) },
124
126
subject = { cfsqltype = " varchar" , value = arguments .payload .sub },
125
127
},
126
128
{
@@ -136,27 +138,16 @@ component accessors="true" singleton{
136
138
* @key The cache key
137
139
*/
138
140
boolean function exists ( required key ){
139
- queryExecute (
140
- " INSERT INTO #getTable () # (#variables .COLUMNS #)
141
- VALUES (
142
- :uuid,
143
- :cacheKey,
144
- :token,
145
- :expiration,
146
- :created
147
- )
148
- " ,
141
+ var qResults = queryExecute (
142
+ " SELECT cacheKey FROM #getTable () # WHERE cacheKey = :cacheKey" ,
149
143
{
150
- uuid = { cfsqltype = " varchar" , value = " #variables .uuid .randomUUID ().toString () #" },
151
- cacheKey = { cfsqltype = " varchar" , value = arguments .key },
152
- token = { cfsqltype = " varchar" , value = arguments .token },
153
- expiration = { cfsqltype = " timestamp" , value = arguments .expiration },
154
- created = { cfsqltype = " timestamp" , value = now () }
144
+ cacheKey : arguments .key
155
145
},
156
146
{
157
- datasource = variables .properties .dsn
147
+ datsource = variables .properties .dsn
158
148
}
159
149
);
150
+ return qResults .recordcount > 0 ;
160
151
}
161
152
162
153
/**
@@ -170,7 +161,7 @@ component accessors="true" singleton{
170
161
struct function get ( required key , struct defaultValue ){
171
162
// select entry
172
163
var q = queryExecute (
173
- " SELECT cacheKey, token, expiration, created
164
+ " SELECT cacheKey, token, expiration, issued
174
165
FROM #getTable () #
175
166
WHERE cacheKey = ?
176
167
" ,
@@ -183,10 +174,10 @@ component accessors="true" singleton{
183
174
// Just return if records found, else null
184
175
if ( q .recordCount ){
185
176
return {
186
- " token" : q .token ,
187
- " cacheKey" : q .cacheKey ,
188
- " expiration" : q .expiration ,
189
- " created " : q .created
177
+ " token" : q .token ,
178
+ " cacheKey" : q .cacheKey ,
179
+ " expiration" : q .expiration ,
180
+ " issued " : q .issued
190
181
};
191
182
}
192
183
@@ -333,8 +324,8 @@ component accessors="true" singleton{
333
324
" CREATE TABLE #getTable () # (
334
325
id VARCHAR(36) NOT NULL,
335
326
cacheKey VARCHAR(255) NOT NULL,
336
- expiration VARCHAR(255) NOT NULL,
337
- created #getDateTimeColumnType () # NOT NULL,
327
+ expiration # getDateTimeColumnType () # NOT NULL,
328
+ issued #getDateTimeColumnType () # NOT NULL,
338
329
token #getTextColumnType () # NOT NULL,
339
330
subject VARCHAR(255) NOT NULL,
340
331
PRIMARY KEY (id)
0 commit comments