def validateCancelRequest(self, targetUrl, cancelConfig, customerId, secretKey): state = self.userInQueueStateRepository.getState( cancelConfig.eventId, -1, secretKey, False) if (state.isValid): self.userInQueueStateRepository.cancelQueueCookie( cancelConfig.eventId, cancelConfig.cookieDomain) targetUrlParam = "" if (not Utils.isNilOrEmpty(targetUrl)): targetUrlParam = "&r=" + QueueitHelpers.urlEncode( targetUrl) query = self.__getQueryString(customerId, cancelConfig.eventId, cancelConfig.version, None, None) + targetUrlParam domainAlias = cancelConfig.queueDomain if (not domainAlias.endswith("/")): domainAlias = domainAlias + "/" redirectUrl = "https://" + domainAlias + "cancel/" + customerId + "/" + cancelConfig.eventId + "/?" + query return RequestValidationResult(ActionTypes.CANCEL, cancelConfig.eventId, state.queueId, redirectUrl, state.redirectType) else: return RequestValidationResult( ActionTypes.CANCEL, cancelConfig.eventId, None, None, None)
def __getQueueITTokenValidationResult(self, targetUrl, eventId, config, queueParams, customerId, secretKey): calculatedHash = QueueitHelpers.hmacSha256Encode( queueParams.queueITTokenWithoutHash, secretKey) if (calculatedHash.upper() != queueParams.hashCode.upper()): return self.__getVaidationErrorResult(customerId, targetUrl, config, queueParams, "hash") if (queueParams.eventId.upper() != eventId.upper()): return self.__getVaidationErrorResult( customerId, targetUrl, config, queueParams, "eventid") if (queueParams.timeStamp < QueueitHelpers.getCurrentTime()): return self.__getVaidationErrorResult( customerId, targetUrl, config, queueParams, "timestamp") cookieDomain = "" if (not Utils.isNilOrEmpty(config.cookieDomain)): cookieDomain = config.cookieDomain self.userInQueueStateRepository.store( config.eventId, queueParams.queueId, queueParams.cookieValidityMinutes, cookieDomain, queueParams.redirectType, secretKey) return RequestValidationResult(ActionTypes.QUEUE, config.eventId, queueParams.queueId, None, queueParams.redirectType)
def __setStateWithTokenError(self, customer_id, error_code): self.hasError = True redirect_url_template = "https://{0}.api2.queue-it.net/{0}/diagnostics/connector/error/?code={1}" redirect_url = redirect_url_template.format(customer_id, error_code) self.validationResult = RequestValidationResult( "ConnectorDiagnosticsRedirect", None, None, redirect_url, None, None)
def validateQueueRequest(self, target_url, queueit_token, config, customer_id, secret_key): state = self.userInQueueStateRepository.getState( config.eventId, config.cookieValidityMinute, secret_key, True) if state.isValid: if state.isStateExtendable() and config.extendCookieValidity: self.userInQueueStateRepository.store( config.eventId, state.queueId, None, Utils.toString(config.cookieDomain), config.isCookieHttpOnly, config.isCookieSecure, state.redirectType, secret_key) result = RequestValidationResult(ActionTypes.QUEUE, config.eventId, state.queueId, None, state.redirectType, config.actionName) return result queue_params = QueueUrlParams.extractQueueParams(queueit_token) request_validation_result = RequestValidationResult( None, None, None, None, None, None) is_token_valid = False if queue_params is not None: token_validation_result = self.__validateToken( config, queue_params, secret_key) is_token_valid = token_validation_result.isValid if is_token_valid: request_validation_result = self.__getValidTokenResult( config, queue_params, secret_key) else: request_validation_result = self.__getErrorResult( customer_id, target_url, config, queue_params, token_validation_result.errorCode) else: request_validation_result = self.__getQueueResult( target_url, config, customer_id) if state.isFound and not is_token_valid: self.userInQueueStateRepository.cancelQueueCookie( config.eventId, config.cookieDomain, config.isCookieHttpOnly, config.isCookieSecure) return request_validation_result
def validateCancelRequest(self, target_url, cancel_config, customer_id, secret_key): state = self.userInQueueStateRepository.getState( cancel_config.eventId, -1, secret_key, False) if state.isValid: self.userInQueueStateRepository.cancelQueueCookie( cancel_config.eventId, cancel_config.cookieDomain, cancel_config.isCookieHttpOnly, cancel_config.isCookieSecure) target_url_param = "" if not Utils.isNilOrEmpty(target_url): target_url_param = "&r={}".format( QueueitHelpers.urlEncode(target_url)) query_string = self.__getQueryString(customer_id, cancel_config.eventId, cancel_config.version, cancel_config.actionName, None, None) query = "{}{}".format(query_string, target_url_param) uri_path = "cancel/{}/{}".format(customer_id, cancel_config.eventId) if state.queueId: uri_path = "{}/{}".format(uri_path, state.queueId) redirect_url = self.__generateRedirectUrl( cancel_config.queueDomain, uri_path, query) return RequestValidationResult(ActionTypes.CANCEL, cancel_config.eventId, state.queueId, redirect_url, state.redirectType, cancel_config.actionName) else: return RequestValidationResult(ActionTypes.CANCEL, cancel_config.eventId, None, None, None, cancel_config.actionName)
def __getQueueResult(self, target_url, config, customer_id): target_url_param = "" if not Utils.isNilOrEmpty(target_url): target_url_param = "&t={}".format( QueueitHelpers.urlEncode(target_url)) query_string = self.__getQueryString(customer_id, config.eventId, config.version, config.actionName, config.culture, config.layoutName) query = "{}{}".format(query_string, target_url_param) redirect_url = self.__generateRedirectUrl(config.queueDomain, "", query) return RequestValidationResult(ActionTypes.QUEUE, config.eventId, None, redirect_url, None, config.actionName)
def __getValidTokenResult(self, config, queue_params, secret_key): cookie_domain = "" if not Utils.isNilOrEmpty(config.cookieDomain): cookie_domain = config.cookieDomain self.userInQueueStateRepository.store( config.eventId, queue_params.queueId, queue_params.cookieValidityMinutes, cookie_domain, config.isCookieHttpOnly, config.isCookieSecure, queue_params.redirectType, secret_key) return RequestValidationResult(ActionTypes.QUEUE, config.eventId, queue_params.queueId, None, queue_params.redirectType, config.actionName)
def __getInQueueRedirectResult(self, targetUrl, config, customerId): targetUrlParam = "" if (not Utils.isNilOrEmpty(targetUrl)): targetUrlParam = "&t=" + QueueitHelpers.urlEncode( targetUrl) domainAlias = config.queueDomain if (not domainAlias.endswith("/")): domainAlias = domainAlias + "/" qs = self.__getQueryString(customerId, config.eventId, config.version, config.culture, config.layoutName) redirectUrl = "https://" + domainAlias + "?" + qs + targetUrlParam return RequestValidationResult(ActionTypes.QUEUE, config.eventId, None, redirectUrl, None)
def __getErrorResult(self, customer_id, target_url, config, q_params, error_code): time_stamp = str(QueueitHelpers.getCurrentTime()) target_url_param = "" if not Utils.isNilOrEmpty(target_url): target_url_param = "&t={}".format( QueueitHelpers.urlEncode(target_url)) query_string = self.__getQueryString(customer_id, config.eventId, config.version, config.actionName, config.culture, config.layoutName) query = "{}&queueittoken={}&ts={}{}".format(query_string, q_params.queueITToken, time_stamp, target_url_param) redirect_url = self.__generateRedirectUrl( config.queueDomain, "error/{}/".format(error_code), query) return RequestValidationResult(ActionTypes.QUEUE, config.eventId, None, redirect_url, None, config.actionName)
def __getVaidationErrorResult(self, customerId, targetUrl, config, qParams, errorCode): targetUrlParam = "" if (not Utils.isNilOrEmpty(targetUrl)): targetUrlParam = "&t=" + QueueitHelpers.urlEncode( targetUrl) query = self.__getQueryString( customerId, config.eventId, config.version, config.culture, config.layoutName ) + "&queueittoken=" + qParams.queueITToken + "&ts=" + str( QueueitHelpers.getCurrentTime()) + targetUrlParam domainAlias = config.queueDomain if (not domainAlias.endswith("/")): domainAlias = domainAlias + "/" redirectUrl = "https://" + domainAlias + "error/" + errorCode + "/?" + query return RequestValidationResult(ActionTypes.QUEUE, config.eventId, None, redirectUrl, None)
def validateQueueRequest(self, targetUrl, queueitToken, config, customerId, secretKey): state = self.userInQueueStateRepository.getState( config.eventId, config.cookieValidityMinute, secretKey, True) if (state.isValid): if (state.isStateExtendable() and config.extendCookieValidity): self.userInQueueStateRepository.store( config.eventId, state.queueId, None, Utils.toString(config.cookieDomain), state.redirectType, secretKey) result = RequestValidationResult(ActionTypes.QUEUE, config.eventId, state.queueId, None, state.redirectType) return result queueParams = QueueUrlParams.extractQueueParams(queueitToken) if (queueParams is not None): return self.__getQueueITTokenValidationResult( targetUrl, config.eventId, config, queueParams, customerId, secretKey) else: return self.__getInQueueRedirectResult(targetUrl, config, customerId)
def getIgnoreActionResult(self, action_name): return RequestValidationResult(ActionTypes.IGNORE, None, None, None, None, action_name)
def validateRequestByIntegrationConfig(current_url_without_queueit_token, queueit_token, integration_config_string, customer_id, secret_key, http_context_provider): debug_entries = {} connector_diagnostics = ConnectorDiagnostics.verify( customer_id, secret_key, queueit_token) if connector_diagnostics.hasError: return connector_diagnostics.validationResult try: if connector_diagnostics.isEnabled: debug_entries["SdkVersion"] = UserInQueueService.SDK_VERSION debug_entries[ "Connector"] = http_context_provider.getProviderName() debug_entries["Runtime"] = KnownUser.__getRunTime() debug_entries["PureUrl"] = current_url_without_queueit_token debug_entries["QueueitToken"] = queueit_token debug_entries[ "OriginalUrl"] = http_context_provider.getOriginalRequestUrl( ) KnownUser.__logMoreRequestDetails(debug_entries, http_context_provider) customer_integration = json.loads(integration_config_string) if connector_diagnostics.isEnabled: debug_entries["ConfigVersion"] = "NULL" if customer_integration and "Version" in customer_integration: debug_entries["ConfigVersion"] = customer_integration[ "Version"] if Utils.isNilOrEmpty(current_url_without_queueit_token): raise KnownUserError( "currentUrlWithoutQueueITToken can not be none or empty.") if not customer_integration or not customer_integration["Version"]: raise KnownUserError( "integrationsConfigString can not be none or empty.") matched_config = IntegrationEvaluator( ).getMatchedIntegrationConfig(customer_integration, current_url_without_queueit_token, http_context_provider) if connector_diagnostics.isEnabled: if matched_config is None: debug_entries["MatchedConfig"] = "NULL" else: debug_entries["MatchedConfig"] = matched_config["Name"] if matched_config is None: return RequestValidationResult(None, None, None, None, None, None) if matched_config["ActionType"] == ActionTypes.QUEUE: return KnownUser.__handleQueueAction( current_url_without_queueit_token, queueit_token, customer_integration, customer_id, secret_key, matched_config, http_context_provider, debug_entries, connector_diagnostics.isEnabled) elif matched_config["ActionType"] == ActionTypes.CANCEL: return KnownUser.__handleCancelAction( current_url_without_queueit_token, queueit_token, customer_integration, customer_id, secret_key, matched_config, http_context_provider, debug_entries, connector_diagnostics.isEnabled) else: # for all unknown types default to 'Ignore' user_in_queue_service = KnownUser.__getUserInQueueService( http_context_provider) result = user_in_queue_service.getIgnoreActionResult( matched_config['Name']) result.isAjaxResult = KnownUser.__isQueueAjaxCall( http_context_provider) return result except Exception as e: if connector_diagnostics.isEnabled: debug_entries["Exception"] = e.message raise e finally: KnownUser.__setDebugCookie(debug_entries, http_context_provider) pass
def validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationsConfigString, customerId, secretKey, httpContextProvider): if (Utils.isNilOrEmpty(currentUrlWithoutQueueITToken)): raise KnownUserError( "currentUrlWithoutQueueITToken can not be none or empty.") if (Utils.isNilOrEmpty(integrationsConfigString)): raise KnownUserError( "integrationsConfigString can not be none or empty.") debugEntries = {} try: customerIntegration = QueueitHelpers.jsonParse( integrationsConfigString) isDebug = KnownUser.__getIsDebug(queueitToken, secretKey) if (isDebug): debugEntries["ConfigVersion"] = customerIntegration["Version"] debugEntries["PureUrl"] = currentUrlWithoutQueueITToken debugEntries["QueueitToken"] = queueitToken debugEntries[ "OriginalUrl"] = httpContextProvider.getOriginalRequestUrl( ) KnownUser.__logMoreRequestDetails(debugEntries, httpContextProvider) matchedConfig = IntegrationEvaluator().getMatchedIntegrationConfig( customerIntegration, currentUrlWithoutQueueITToken, httpContextProvider) if (isDebug): if (matchedConfig == None): debugEntries["MatchedConfig"] = "NULL" else: debugEntries["MatchedConfig"] = matchedConfig["Name"] if (matchedConfig is None): return RequestValidationResult(None, None, None, None, None) if (matchedConfig["ActionType"] == ActionTypes.QUEUE): return KnownUser.__handleQueueAction( currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, httpContextProvider, debugEntries) elif (matchedConfig["ActionType"] == ActionTypes.CANCEL): return KnownUser.__handleCancelAction( currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, httpContextProvider, debugEntries) else: # for all unknown types default to 'Ignore' userInQueueService = KnownUser.__getUserInQueueService( httpContextProvider) result = userInQueueService.getIgnoreActionResult() result.isAjaxResult = KnownUser.__isQueueAjaxCall( httpContextProvider) return result except StandardError as stdErr: raise KnownUserError( "integrationConfiguration text was not valid: " + stdErr.message) finally: KnownUser.__setDebugCookie(debugEntries, httpContextProvider) pass
def __init__(self): self.isEnabled = False self.hasError = False self.validationResult = RequestValidationResult( None, None, None, None, None, None)
def __setStateWithSetupError(self): self.hasError = True redirect_url = "https://api2.queue-it.net/diagnostics/connector/error/?code=setup" self.validationResult = RequestValidationResult( "ConnectorDiagnosticsRedirect", None, None, redirect_url, None, None)