queueit_knownuserv3 3.6.1 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,399 +1,410 @@
1
- require 'cgi'
2
- require 'json'
3
-
4
- module QueueIt
5
- class KnownUser
6
- QUEUEIT_TOKEN_KEY = "queueittoken"
7
- QUEUEIT_DEBUG_KEY = "queueitdebug"
8
- QUEUEIT_AJAX_HEADER_KEY = "x-queueit-ajaxpageurl"
9
-
10
- @@userInQueueService = nil
11
- def self.getUserInQueueService(cookieJar)
12
- if (@@userInQueueService == nil)
13
- return UserInQueueService.new(UserInQueueStateCookieRepository.new(CookieManager.new(cookieJar)))
14
- end
15
-
16
- return @@userInQueueService
17
- end
18
- private_class_method :getUserInQueueService
19
-
20
- def self.isQueueAjaxCall(request)
21
- return request.headers[QUEUEIT_AJAX_HEADER_KEY] != nil
22
- end
23
- private_class_method :isQueueAjaxCall
24
-
25
- def self.generateTargetUrl(originalTargetUrl, request)
26
- unless isQueueAjaxCall(request)
27
- return originalTargetUrl
28
- end
29
- return CGI::unescape(request.headers[QUEUEIT_AJAX_HEADER_KEY])
30
- end
31
- private_class_method :generateTargetUrl
32
-
33
- def self.convertToInt(value)
34
- begin
35
- converted = Integer(value)
36
- rescue
37
- converted = 0
38
- end
39
- return converted
40
- end
41
- private_class_method :convertToInt
42
-
43
- def self.logMoreRequestDetails(debugEntries, request)
44
- debugEntries["ServerUtcTime"] = Time.now.utc.iso8601
45
- debugEntries["RequestIP"] = request.remote_ip
46
- debugEntries["RequestHttpHeader_Via"] = request.headers["via"]
47
- debugEntries["RequestHttpHeader_Forwarded"] = request.headers["forwarded"]
48
- debugEntries["RequestHttpHeader_XForwardedFor"] = request.headers["x-forwarded-for"]
49
- debugEntries["RequestHttpHeader_XForwardedHost"] = request.headers["x-forwarded-host"]
50
- debugEntries["RequestHttpHeader_XForwardedProto"] = request.headers["x-forwarded-proto"]
51
- end
52
- private_class_method :logMoreRequestDetails
53
-
54
- def self.setDebugCookie(debugEntries, cookieJar)
55
- if(debugEntries == nil || debugEntries.length == 0)
56
- return
57
- end
58
-
59
- cookieManager = CookieManager.new(cookieJar)
60
- cookieValue = ''
61
- debugEntries.each do |entry|
62
- cookieValue << (entry[0].to_s + '=' + entry[1].to_s + '|')
63
- end
64
- cookieValue = cookieValue.chop # remove trailing char
65
- cookieManager.setCookie(QUEUEIT_DEBUG_KEY, cookieValue, nil, nil)
66
- end
67
- private_class_method :setDebugCookie
68
-
69
- def self._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries, isDebug)
70
-
71
- if(isDebug)
72
- debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
73
- debugEntries["Runtime"] = getRuntime()
74
- debugEntries["TargetUrl"] = targetUrl
75
- debugEntries["QueueitToken"] = queueitToken
76
- debugEntries["OriginalUrl"] = getRealOriginalUrl(request)
77
- if(queueConfig == nil)
78
- debugEntries["QueueConfig"] = "NULL"
79
- else
80
- debugEntries["QueueConfig"] = queueConfig.toString()
81
- end
82
- logMoreRequestDetails(debugEntries, request)
83
- end
84
-
85
- if(Utils.isNilOrEmpty(customerId))
86
- raise KnownUserError, "customerId can not be nil or empty."
87
- end
88
-
89
- if(Utils.isNilOrEmpty(secretKey))
90
- raise KnownUserError, "secretKey can not be nil or empty."
91
- end
92
-
93
- if(queueConfig == nil)
94
- raise KnownUserError, "queueConfig can not be nil."
95
- end
96
-
97
- if(Utils.isNilOrEmpty(queueConfig.eventId))
98
- raise KnownUserError, "queueConfig.eventId can not be nil or empty."
99
- end
100
-
101
- if(Utils.isNilOrEmpty(queueConfig.queueDomain))
102
- raise KnownUserError, "queueConfig.queueDomain can not be nil or empty."
103
- end
104
-
105
- minutes = convertToInt(queueConfig.cookieValidityMinute)
106
- if(minutes <= 0)
107
- raise KnownUserError, "queueConfig.cookieValidityMinute should be integer greater than 0."
108
- end
109
-
110
- if(![true, false].include? queueConfig.extendCookieValidity)
111
- raise KnownUserError, "queueConfig.extendCookieValidity should be valid boolean."
112
- end
113
-
114
- userInQueueService = getUserInQueueService(request.cookie_jar)
115
- result = userInQueueService.validateQueueRequest(targetUrl, queueitToken, queueConfig, customerId, secretKey)
116
- result.isAjaxResult = isQueueAjaxCall(request)
117
-
118
- return result
119
- end
120
- private_class_method :_resolveQueueRequestByLocalConfig
121
-
122
- def self._cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries, isDebug)
123
- targetUrl = generateTargetUrl(targetUrl, request)
124
-
125
- if(isDebug)
126
- debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
127
- debugEntries["Runtime"] = getRuntime()
128
- debugEntries["TargetUrl"] = targetUrl
129
- debugEntries["QueueitToken"] = queueitToken
130
- debugEntries["OriginalUrl"] = getRealOriginalUrl(request)
131
- if(cancelConfig == nil)
132
- debugEntries["CancelConfig"] = "NULL"
133
- else
134
- debugEntries["CancelConfig"] = cancelConfig.toString()
135
- end
136
- logMoreRequestDetails(debugEntries, request)
137
- end
138
-
139
- if(Utils.isNilOrEmpty(targetUrl))
140
- raise KnownUserError, "targetUrl can not be nil or empty."
141
- end
142
-
143
- if(Utils.isNilOrEmpty(customerId))
144
- raise KnownUserError, "customerId can not be nil or empty."
145
- end
146
-
147
- if(Utils.isNilOrEmpty(secretKey))
148
- raise KnownUserError, "secretKey can not be nil or empty."
149
- end
150
-
151
- if(cancelConfig == nil)
152
- raise KnownUserError, "cancelConfig can not be nil."
153
- end
154
-
155
- if(Utils.isNilOrEmpty(cancelConfig.eventId))
156
- raise KnownUserError, "cancelConfig.eventId can not be nil or empty."
157
- end
158
-
159
- if(Utils.isNilOrEmpty(cancelConfig.queueDomain))
160
- raise KnownUserError, "cancelConfig.queueDomain can not be nil or empty."
161
- end
162
-
163
- userInQueueService = getUserInQueueService(request.cookie_jar)
164
- result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
165
- result.isAjaxResult = isQueueAjaxCall(request)
166
-
167
- return result
168
- end
169
- private_class_method :_cancelRequestByLocalConfig
170
-
171
- def self.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey, request)
172
- if(Utils.isNilOrEmpty(eventId))
173
- raise KnownUserError, "eventId can not be nil or empty."
174
- end
175
-
176
- if(Utils.isNilOrEmpty(secretKey))
177
- raise KnownUserError, "secretKey can not be nil or empty."
178
- end
179
-
180
- minutes = convertToInt(cookieValidityMinute)
181
- if(minutes <= 0)
182
- raise KnownUserError, "cookieValidityMinute should be integer greater than 0."
183
- end
184
-
185
- userInQueueService = getUserInQueueService(request.cookie_jar)
186
- userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey)
187
- end
188
-
189
- def self.resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request)
190
- debugEntries = Hash.new
191
- connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)
192
-
193
- if(connectorDiagnostics.hasError)
194
- return connectorDiagnostics.validationResult
195
- end
196
- begin
197
- targetUrl = generateTargetUrl(targetUrl, request)
198
- return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries, connectorDiagnostics.isEnabled)
199
- rescue Exception => e
200
- if(connectorDiagnostics.isEnabled)
201
- debugEntries["Exception"] = e.message
202
- end
203
- raise e
204
- ensure
205
- setDebugCookie(debugEntries, request.cookie_jar)
206
- end
207
- end
208
-
209
- def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationConfigJson, customerId, secretKey, request)
210
- debugEntries = Hash.new
211
- customerIntegration = Hash.new
212
- connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)
213
-
214
- if(connectorDiagnostics.hasError)
215
- return connectorDiagnostics.validationResult
216
- end
217
- begin
218
- if(connectorDiagnostics.isEnabled)
219
- debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
220
- debugEntries["Runtime"] = getRuntime()
221
- debugEntries["PureUrl"] = currentUrlWithoutQueueITToken
222
- debugEntries["QueueitToken"] = queueitToken
223
- debugEntries["OriginalUrl"] = getRealOriginalUrl(request)
224
- logMoreRequestDetails(debugEntries, request)
225
- end
226
-
227
- customerIntegration = JSON.parse(integrationConfigJson)
228
-
229
- if(connectorDiagnostics.isEnabled)
230
- if(customerIntegration.length != 0 and customerIntegration["Version"] != nil)
231
- debugEntries["ConfigVersion"] = customerIntegration["Version"]
232
- else
233
- debugEntries["ConfigVersion"] = "NULL"
234
- end
235
- end
236
-
237
- if(Utils.isNilOrEmpty(currentUrlWithoutQueueITToken))
238
- raise KnownUserError, "currentUrlWithoutQueueITToken can not be nil or empty."
239
- end
240
-
241
- if(customerIntegration.length == 0 || customerIntegration["Version"] == nil)
242
- raise KnownUserError, "integrationConfigJson is not valid json."
243
- end
244
-
245
- integrationEvaluator = IntegrationEvaluator.new
246
- matchedConfig = integrationEvaluator.getMatchedIntegrationConfig(customerIntegration, currentUrlWithoutQueueITToken, request)
247
-
248
- if(connectorDiagnostics.isEnabled)
249
- if(matchedConfig == nil)
250
- debugEntries["MatchedConfig"] = "NULL"
251
- else
252
- debugEntries["MatchedConfig"] = matchedConfig["Name"]
253
- end
254
- end
255
-
256
- if(matchedConfig == nil)
257
- return RequestValidationResult.new(nil, nil, nil, nil, nil, nil)
258
- end
259
-
260
- # unspecified or 'Queue' specified
261
- if(!matchedConfig.key?("ActionType") || Utils.isNilOrEmpty(matchedConfig["ActionType"]) || matchedConfig["ActionType"].eql?(ActionTypes::QUEUE))
262
- return handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
263
- customerId, secretKey, matchedConfig, request, debugEntries, connectorDiagnostics.isEnabled)
264
-
265
- elsif(matchedConfig["ActionType"].eql?(ActionTypes::CANCEL))
266
- return handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
267
- customerId, secretKey, matchedConfig, request, debugEntries, connectorDiagnostics.isEnabled)
268
-
269
- # for all unknown types default to 'Ignore'
270
- else
271
- userInQueueService = getUserInQueueService(request.cookie_jar)
272
- result = userInQueueService.getIgnoreActionResult(matchedConfig["Name"])
273
- result.isAjaxResult = isQueueAjaxCall(request)
274
-
275
- return result
276
- end
277
- rescue Exception => e
278
- if(connectorDiagnostics.isEnabled)
279
- debugEntries["Exception"] = e.message
280
- end
281
- raise e
282
- ensure
283
- setDebugCookie(debugEntries, request.cookie_jar)
284
- end
285
- end
286
-
287
- def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries, isDebug)
288
- queueConfig = QueueEventConfig.new
289
- queueConfig.eventId = matchedConfig["EventId"]
290
- queueConfig.queueDomain = matchedConfig["QueueDomain"]
291
- queueConfig.layoutName = matchedConfig["LayoutName"]
292
- queueConfig.culture = matchedConfig["Culture"]
293
- queueConfig.cookieDomain = matchedConfig["CookieDomain"]
294
- queueConfig.extendCookieValidity = matchedConfig["ExtendCookieValidity"]
295
- queueConfig.cookieValidityMinute = matchedConfig["CookieValidityMinute"]
296
- queueConfig.version = customerIntegration["Version"]
297
- queueConfig.actionName = matchedConfig["Name"]
298
-
299
- case matchedConfig["RedirectLogic"]
300
- when "ForcedTargetUrl"
301
- targetUrl = matchedConfig["ForcedTargetUrl"]
302
- when "EventTargetUrl"
303
- targetUrl = ''
304
- else
305
- targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken, request)
306
- end
307
-
308
- return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries, isDebug)
309
- end
310
-
311
- def self.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries, isDebug)
312
- cancelConfig = CancelEventConfig.new
313
- cancelConfig.eventId = matchedConfig["EventId"]
314
- cancelConfig.queueDomain = matchedConfig["QueueDomain"]
315
- cancelConfig.cookieDomain = matchedConfig["CookieDomain"]
316
- cancelConfig.version = customerIntegration["Version"]
317
- cancelConfig.actionName = matchedConfig["Name"]
318
-
319
- return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries, isDebug)
320
- end
321
-
322
- def self.cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request)
323
- debugEntries = Hash.new
324
- connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)
325
-
326
- if(connectorDiagnostics.hasError)
327
- return connectorDiagnostics.validationResult
328
- end
329
- begin
330
- return _cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries, connectorDiagnostics.isEnabled)
331
- rescue Exception => e
332
- if(connectorDiagnostics.isEnabled)
333
- debugEntries["Exception"] = e.message
334
- end
335
- raise e
336
- ensure
337
- setDebugCookie(debugEntries, request.cookie_jar)
338
- end
339
- end
340
-
341
- def self.getRealOriginalUrl(request)
342
- # RoR could modify request.original_url if request contains x-forwarded-host/proto http headers.
343
- # Therefore we need this method to be able to access the 'real' original url.
344
- return request.env["rack.url_scheme"] + "://" + request.env["HTTP_HOST"] + request.original_fullpath
345
- end
346
-
347
- def self.getRuntime()
348
- return RUBY_VERSION.to_s
349
- end
350
- end
351
-
352
- class CookieManager
353
- @cookies = {}
354
-
355
- def initialize(cookieJar)
356
- @cookies = cookieJar
357
- end
358
-
359
- def getCookie(name)
360
- key = name.to_sym
361
- if(!Utils.isNilOrEmpty(@cookies[key]))
362
- return @cookies[key]
363
- end
364
- return nil
365
- end
366
-
367
- def setCookie(name, value, expire, domain)
368
- key = name.to_sym
369
- noDomain = Utils.isNilOrEmpty(domain)
370
- deleteCookie = Utils.isNilOrEmpty(value)
371
- noExpire = Utils.isNilOrEmpty(expire)
372
-
373
- if(noDomain)
374
- if(deleteCookie)
375
- @cookies.delete(key)
376
- else
377
- if(noExpire)
378
- @cookies[key] = { :value => value, :httponly => false }
379
- else
380
- @cookies[key] = { :value => value, :expires => expire, :httponly => false }
381
- end
382
- end
383
- else
384
- if(deleteCookie)
385
- @cookies.delete(key, :domain => domain)
386
- else
387
- if(noExpire)
388
- @cookies[key] = { :value => value, :domain => domain, :httponly => false }
389
- else
390
- @cookies[key] = { :value => value, :expires => expire, :domain => domain, :httponly => false }
391
- end
392
- end
393
- end
394
- end
395
- end
396
- end
397
-
398
-
399
-
1
+ require 'cgi'
2
+ require 'json'
3
+
4
+ module QueueIt
5
+
6
+ class KnownUser
7
+ QUEUEIT_TOKEN_KEY = "queueittoken"
8
+ QUEUEIT_DEBUG_KEY = "queueitdebug"
9
+ QUEUEIT_AJAX_HEADER_KEY = "x-queueit-ajaxpageurl"
10
+
11
+ @@userInQueueService = nil
12
+ def self.getUserInQueueService()
13
+ if (@@userInQueueService == nil)
14
+ return UserInQueueService.new(UserInQueueStateCookieRepository.new(HttpContextProvider.httpContext.cookieManager))
15
+ end
16
+
17
+ return @@userInQueueService
18
+ end
19
+ private_class_method :getUserInQueueService
20
+
21
+ def self.isQueueAjaxCall
22
+ headers = HttpContextProvider.httpContext.headers
23
+ return headers[QUEUEIT_AJAX_HEADER_KEY] != nil
24
+ end
25
+ private_class_method :isQueueAjaxCall
26
+
27
+ def self.generateTargetUrl(originalTargetUrl)
28
+ unless isQueueAjaxCall()
29
+ return originalTargetUrl
30
+ end
31
+ headers = HttpContextProvider.httpContext.headers
32
+ return CGI::unescape(headers[QUEUEIT_AJAX_HEADER_KEY])
33
+ end
34
+ private_class_method :generateTargetUrl
35
+
36
+ def self.convertToInt(value)
37
+ begin
38
+ converted = Integer(value)
39
+ rescue
40
+ converted = 0
41
+ end
42
+ return converted
43
+ end
44
+ private_class_method :convertToInt
45
+
46
+ def self.logMoreRequestDetails(debugEntries)
47
+ httpContext = HttpContextProvider.httpContext
48
+ headers = httpContext.headers
49
+
50
+ debugEntries["ServerUtcTime"] = Time.now.utc.iso8601
51
+ debugEntries["RequestIP"] = httpContext.userHostAddress
52
+ debugEntries["RequestHttpHeader_Via"] = headers["via"]
53
+ debugEntries["RequestHttpHeader_Forwarded"] = headers["forwarded"]
54
+ debugEntries["RequestHttpHeader_XForwardedFor"] = headers["x-forwarded-for"]
55
+ debugEntries["RequestHttpHeader_XForwardedHost"] = headers["x-forwarded-host"]
56
+ debugEntries["RequestHttpHeader_XForwardedProto"] = headers["x-forwarded-proto"]
57
+ end
58
+ private_class_method :logMoreRequestDetails
59
+
60
+ def self.setDebugCookie(debugEntries)
61
+ if(debugEntries == nil || debugEntries.length == 0)
62
+ return
63
+ end
64
+
65
+ cookieManager = HttpContextProvider.httpContext.cookieManager
66
+ cookieValue = ''
67
+ debugEntries.each do |entry|
68
+ cookieValue << (entry[0].to_s + '=' + entry[1].to_s + '|')
69
+ end
70
+ cookieValue = cookieValue.chop # remove trailing char
71
+ cookieManager.setCookie(QUEUEIT_DEBUG_KEY, cookieValue, nil, nil, false, false)
72
+ end
73
+ private_class_method :setDebugCookie
74
+
75
+ def self._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries, isDebug)
76
+
77
+ if(isDebug)
78
+ debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
79
+ debugEntries["Runtime"] = getRuntime()
80
+ debugEntries["TargetUrl"] = targetUrl
81
+ debugEntries["QueueitToken"] = queueitToken
82
+ debugEntries["OriginalUrl"] = getRealOriginalUrl()
83
+ if(queueConfig == nil)
84
+ debugEntries["QueueConfig"] = "NULL"
85
+ else
86
+ debugEntries["QueueConfig"] = queueConfig.toString()
87
+ end
88
+ logMoreRequestDetails(debugEntries)
89
+ end
90
+
91
+ if(Utils.isNilOrEmpty(customerId))
92
+ raise KnownUserError, "customerId can not be nil or empty."
93
+ end
94
+
95
+ if(Utils.isNilOrEmpty(secretKey))
96
+ raise KnownUserError, "secretKey can not be nil or empty."
97
+ end
98
+
99
+ if(queueConfig == nil)
100
+ raise KnownUserError, "queueConfig can not be nil."
101
+ end
102
+
103
+ if(Utils.isNilOrEmpty(queueConfig.eventId))
104
+ raise KnownUserError, "queueConfig.eventId can not be nil or empty."
105
+ end
106
+
107
+ if(Utils.isNilOrEmpty(queueConfig.queueDomain))
108
+ raise KnownUserError, "queueConfig.queueDomain can not be nil or empty."
109
+ end
110
+
111
+ minutes = convertToInt(queueConfig.cookieValidityMinute)
112
+ if(minutes <= 0)
113
+ raise KnownUserError, "queueConfig.cookieValidityMinute should be integer greater than 0."
114
+ end
115
+
116
+ if(![true, false].include? queueConfig.extendCookieValidity)
117
+ raise KnownUserError, "queueConfig.extendCookieValidity should be valid boolean."
118
+ end
119
+
120
+ userInQueueService = getUserInQueueService()
121
+ result = userInQueueService.validateQueueRequest(targetUrl, queueitToken, queueConfig, customerId, secretKey)
122
+ result.isAjaxResult = isQueueAjaxCall()
123
+
124
+ return result
125
+ end
126
+ private_class_method :_resolveQueueRequestByLocalConfig
127
+
128
+ def self._cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, debugEntries, isDebug)
129
+ targetUrl = generateTargetUrl(targetUrl)
130
+
131
+ if(isDebug)
132
+ debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
133
+ debugEntries["Runtime"] = getRuntime()
134
+ debugEntries["TargetUrl"] = targetUrl
135
+ debugEntries["QueueitToken"] = queueitToken
136
+ debugEntries["OriginalUrl"] = getRealOriginalUrl()
137
+ if(cancelConfig == nil)
138
+ debugEntries["CancelConfig"] = "NULL"
139
+ else
140
+ debugEntries["CancelConfig"] = cancelConfig.toString()
141
+ end
142
+ logMoreRequestDetails(debugEntries)
143
+ end
144
+
145
+ if(Utils.isNilOrEmpty(targetUrl))
146
+ raise KnownUserError, "targetUrl can not be nil or empty."
147
+ end
148
+
149
+ if(Utils.isNilOrEmpty(customerId))
150
+ raise KnownUserError, "customerId can not be nil or empty."
151
+ end
152
+
153
+ if(Utils.isNilOrEmpty(secretKey))
154
+ raise KnownUserError, "secretKey can not be nil or empty."
155
+ end
156
+
157
+ if(cancelConfig == nil)
158
+ raise KnownUserError, "cancelConfig can not be nil."
159
+ end
160
+
161
+ if(Utils.isNilOrEmpty(cancelConfig.eventId))
162
+ raise KnownUserError, "cancelConfig.eventId can not be nil or empty."
163
+ end
164
+
165
+ if(Utils.isNilOrEmpty(cancelConfig.queueDomain))
166
+ raise KnownUserError, "cancelConfig.queueDomain can not be nil or empty."
167
+ end
168
+
169
+ userInQueueService = getUserInQueueService()
170
+ result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
171
+ result.isAjaxResult = isQueueAjaxCall()
172
+
173
+ return result
174
+ end
175
+ private_class_method :_cancelRequestByLocalConfig
176
+
177
+ def self.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
178
+ if(Utils.isNilOrEmpty(eventId))
179
+ raise KnownUserError, "eventId can not be nil or empty."
180
+ end
181
+
182
+ if(Utils.isNilOrEmpty(secretKey))
183
+ raise KnownUserError, "secretKey can not be nil or empty."
184
+ end
185
+
186
+ minutes = convertToInt(cookieValidityMinute)
187
+ if(minutes <= 0)
188
+ raise KnownUserError, "cookieValidityMinute should be integer greater than 0."
189
+ end
190
+
191
+ userInQueueService = getUserInQueueService()
192
+ userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
193
+ end
194
+
195
+ def self.resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey)
196
+ debugEntries = Hash.new
197
+ connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)
198
+
199
+ if(connectorDiagnostics.hasError)
200
+ return connectorDiagnostics.validationResult
201
+ end
202
+ begin
203
+ targetUrl = generateTargetUrl(targetUrl)
204
+ return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries, connectorDiagnostics.isEnabled)
205
+ rescue Exception => e
206
+ if(connectorDiagnostics.isEnabled)
207
+ debugEntries["Exception"] = e.message
208
+ end
209
+ raise e
210
+ ensure
211
+ setDebugCookie(debugEntries)
212
+ end
213
+ end
214
+
215
+ def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationConfigJson, customerId, secretKey)
216
+ debugEntries = Hash.new
217
+ customerIntegration = Hash.new
218
+ connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)
219
+
220
+ if(connectorDiagnostics.hasError)
221
+ return connectorDiagnostics.validationResult
222
+ end
223
+ begin
224
+ if(connectorDiagnostics.isEnabled)
225
+ debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
226
+ debugEntries["Runtime"] = getRuntime()
227
+ debugEntries["PureUrl"] = currentUrlWithoutQueueITToken
228
+ debugEntries["QueueitToken"] = queueitToken
229
+ debugEntries["OriginalUrl"] = getRealOriginalUrl()
230
+ logMoreRequestDetails(debugEntries)
231
+ end
232
+
233
+ customerIntegration = JSON.parse(integrationConfigJson)
234
+
235
+ if(connectorDiagnostics.isEnabled)
236
+ if(customerIntegration.length != 0 and customerIntegration["Version"] != nil)
237
+ debugEntries["ConfigVersion"] = customerIntegration["Version"]
238
+ else
239
+ debugEntries["ConfigVersion"] = "NULL"
240
+ end
241
+ end
242
+
243
+ if(Utils.isNilOrEmpty(currentUrlWithoutQueueITToken))
244
+ raise KnownUserError, "currentUrlWithoutQueueITToken can not be nil or empty."
245
+ end
246
+
247
+ if(customerIntegration.length == 0 || customerIntegration["Version"] == nil)
248
+ raise KnownUserError, "integrationConfigJson is not valid json."
249
+ end
250
+
251
+ integrationEvaluator = IntegrationEvaluator.new
252
+ matchedConfig = integrationEvaluator.getMatchedIntegrationConfig(customerIntegration, currentUrlWithoutQueueITToken, HttpContextProvider.httpContext)
253
+
254
+ if(connectorDiagnostics.isEnabled)
255
+ if(matchedConfig == nil)
256
+ debugEntries["MatchedConfig"] = "NULL"
257
+ else
258
+ debugEntries["MatchedConfig"] = matchedConfig["Name"]
259
+ end
260
+ end
261
+
262
+ if(matchedConfig == nil)
263
+ return RequestValidationResult.new(nil, nil, nil, nil, nil, nil)
264
+ end
265
+
266
+ # unspecified or 'Queue' specified
267
+ if(!matchedConfig.key?("ActionType") || Utils.isNilOrEmpty(matchedConfig["ActionType"]) || matchedConfig["ActionType"].eql?(ActionTypes::QUEUE))
268
+ return handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
269
+ customerId, secretKey, matchedConfig, debugEntries, connectorDiagnostics.isEnabled)
270
+
271
+ elsif(matchedConfig["ActionType"].eql?(ActionTypes::CANCEL))
272
+ return handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
273
+ customerId, secretKey, matchedConfig, debugEntries, connectorDiagnostics.isEnabled)
274
+
275
+ # for all unknown types default to 'Ignore'
276
+ else
277
+ userInQueueService = getUserInQueueService()
278
+ result = userInQueueService.getIgnoreActionResult(matchedConfig["Name"])
279
+ result.isAjaxResult = isQueueAjaxCall()
280
+
281
+ return result
282
+ end
283
+ rescue Exception => e
284
+ if(connectorDiagnostics.isEnabled)
285
+ debugEntries["Exception"] = e.message
286
+ end
287
+ raise e
288
+ ensure
289
+ setDebugCookie(debugEntries)
290
+ end
291
+ end
292
+
293
+ def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, debugEntries, isDebug)
294
+ queueConfig = QueueEventConfig.new
295
+ queueConfig.eventId = matchedConfig["EventId"]
296
+ queueConfig.layoutName = matchedConfig["LayoutName"]
297
+ queueConfig.culture = matchedConfig["Culture"]
298
+ queueConfig.queueDomain = matchedConfig["QueueDomain"]
299
+ queueConfig.extendCookieValidity = matchedConfig["ExtendCookieValidity"]
300
+ queueConfig.cookieValidityMinute = matchedConfig["CookieValidityMinute"]
301
+ queueConfig.cookieDomain = matchedConfig["CookieDomain"]
302
+ queueConfig.isCookieHttpOnly = matchedConfig["IsCookieHttpOnly"] || false
303
+ queueConfig.isCookieSecure = matchedConfig["IsCookieSecure"] || false
304
+ queueConfig.version = customerIntegration["Version"]
305
+ queueConfig.actionName = matchedConfig["Name"]
306
+
307
+ case matchedConfig["RedirectLogic"]
308
+ when "ForcedTargetUrl"
309
+ targetUrl = matchedConfig["ForcedTargetUrl"]
310
+ when "EventTargetUrl"
311
+ targetUrl = ''
312
+ else
313
+ targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken)
314
+ end
315
+
316
+ return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries, isDebug)
317
+ end
318
+
319
+ def self.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, debugEntries, isDebug)
320
+ cancelConfig = CancelEventConfig.new
321
+ cancelConfig.eventId = matchedConfig["EventId"]
322
+ cancelConfig.queueDomain = matchedConfig["QueueDomain"]
323
+ cancelConfig.cookieDomain = matchedConfig["CookieDomain"]
324
+ cancelConfig.isCookieHttpOnly = matchedConfig["IsCookieHttpOnly"] || false
325
+ cancelConfig.isCookieSecure = matchedConfig["IsCookieSecure"] || false
326
+ cancelConfig.version = customerIntegration["Version"]
327
+ cancelConfig.actionName = matchedConfig["Name"]
328
+
329
+ return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, debugEntries, isDebug)
330
+ end
331
+
332
+ def self.cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey)
333
+ debugEntries = Hash.new
334
+ connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)
335
+
336
+ if(connectorDiagnostics.hasError)
337
+ return connectorDiagnostics.validationResult
338
+ end
339
+ begin
340
+ return _cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, debugEntries, connectorDiagnostics.isEnabled)
341
+ rescue Exception => e
342
+ if(connectorDiagnostics.isEnabled)
343
+ debugEntries["Exception"] = e.message
344
+ end
345
+ raise e
346
+ ensure
347
+ setDebugCookie(debugEntries)
348
+ end
349
+ end
350
+
351
+ def self.getRealOriginalUrl()
352
+ return HttpContextProvider.httpContext.url
353
+ # RoR could modify request.original_url if request contains x-forwarded-host/proto http headers.
354
+ # Therefore we need this method to be able to access the 'real' original url.
355
+ #return request.env["rack.url_scheme"] + "://" + request.env["HTTP_HOST"] + request.original_fullpath
356
+ end
357
+
358
+ def self.getRuntime()
359
+ return RUBY_VERSION.to_s
360
+ end
361
+ end
362
+
363
+ class CookieManager
364
+ @cookies = {}
365
+
366
+ def initialize(cookieJar)
367
+ @cookies = cookieJar
368
+ end
369
+
370
+ def getCookie(name)
371
+ key = name.to_sym
372
+ if(!Utils.isNilOrEmpty(@cookies[key]))
373
+ return @cookies[key]
374
+ end
375
+ return nil
376
+ end
377
+
378
+ def setCookie(name, value, expire, domain, isHttpOnly, isSecure)
379
+ key = name.to_sym
380
+ noDomain = Utils.isNilOrEmpty(domain)
381
+ deleteCookie = Utils.isNilOrEmpty(value)
382
+ noExpire = Utils.isNilOrEmpty(expire)
383
+
384
+ if(noDomain)
385
+ if(deleteCookie)
386
+ @cookies.delete(key)
387
+ else
388
+ if(noExpire)
389
+ @cookies[key] = { :value => value, :httponly => isHttpOnly, :secure => isSecure }
390
+ else
391
+ @cookies[key] = { :value => value, :expires => expire, :httponly => isHttpOnly, :secure => isSecure }
392
+ end
393
+ end
394
+ else
395
+ if(deleteCookie)
396
+ @cookies.delete(key, :domain => domain)
397
+ else
398
+ if(noExpire)
399
+ @cookies[key] = { :value => value, :domain => domain, :httponly => isHttpOnly, :secure => isSecure }
400
+ else
401
+ @cookies[key] = { :value => value, :expires => expire, :domain => domain, :httponly => isHttpOnly, :secure => isSecure }
402
+ end
403
+ end
404
+ end
405
+ end
406
+ end
407
+ end
408
+
409
+
410
+