def verify(customer_id, secret_key, queueit_token):
        diagnostics = ConnectorDiagnostics()
        q_params = QueueUrlParams.extractQueueParams(queueit_token)

        if q_params is None:
            return diagnostics

        if q_params.redirectType is None:
            return diagnostics

        if q_params.redirectType != "debug":
            return diagnostics

        if Utils.isNilOrEmpty(customer_id) or Utils.isNilOrEmpty(secret_key):
            diagnostics.__setStateWithSetupError()
            return diagnostics

        expected_hash = QueueitHelpers.hmacSha256Encode(
            q_params.queueITTokenWithoutHash, secret_key)
        if q_params.hashCode != expected_hash:
            diagnostics.__setStateWithTokenError(customer_id, "hash")
            return diagnostics

        if q_params.timeStamp < QueueitHelpers.getCurrentTime():
            diagnostics.__setStateWithTokenError(customer_id, "timestamp")
            return diagnostics

        diagnostics.isEnabled = True
        return diagnostics
    def __resolveQueueRequestByLocalConfig(target_url, queueit_token,
                                           queue_config, customer_id,
                                           secret_key, http_context_provider,
                                           debug_entries, is_debug):
        if is_debug:
            debug_entries["SdkVersion"] = UserInQueueService.SDK_VERSION
            debug_entries["Connector"] = http_context_provider.getProviderName(
            )
            debug_entries["Runtime"] = KnownUser.__getRunTime()
            debug_entries["TargetUrl"] = target_url
            debug_entries["QueueitToken"] = queueit_token
            debug_entries[
                "OriginalUrl"] = http_context_provider.getOriginalRequestUrl()
            if queue_config is None:
                debug_entries["QueueConfig"] = "NULL"
            else:
                debug_entries["QueueConfig"] = queue_config.toString()
            KnownUser.__logMoreRequestDetails(debug_entries,
                                              http_context_provider)

        if Utils.isNilOrEmpty(customer_id):
            raise KnownUserError("customerId can not be none or empty.")

        if Utils.isNilOrEmpty(secret_key):
            raise KnownUserError("secretKey can not be none or empty.")

        if queue_config is None:
            raise KnownUserError("queueConfig can not be none.")

        if Utils.isNilOrEmpty(queue_config.eventId):
            raise KnownUserError(
                "queueConfig.eventId can not be none or empty.")

        if Utils.isNilOrEmpty(queue_config.queueDomain):
            raise KnownUserError(
                "queueConfig.queueDomain can not be none or empty.")

        minutes = QueueitHelpers.convertToInt(
            queue_config.cookieValidityMinute)
        if minutes <= 0:
            raise KnownUserError(
                "queueConfig.cookieValidityMinute should be integer greater than 0."
            )

        if not isinstance(queue_config.extendCookieValidity, bool):
            raise KnownUserError(
                "queueConfig.extendCookieValidity should be valid boolean.")

        user_in_queue_service = KnownUser.__getUserInQueueService(
            http_context_provider)
        result = user_in_queue_service.validateQueueRequest(
            target_url, queueit_token, queue_config, customer_id, secret_key)
        result.isAjaxResult = KnownUser.__isQueueAjaxCall(
            http_context_provider)
        return result
    def __cancelRequestByLocalConfig(target_url, queueit_token, cancel_config,
                                     customer_id, secret_key,
                                     http_context_provider, debug_entries,
                                     is_debug):
        target_url = KnownUser.__generateTargetUrl(target_url,
                                                   http_context_provider)

        if is_debug:
            debug_entries["SdkVersion"] = UserInQueueService.SDK_VERSION
            debug_entries["Connector"] = http_context_provider.getProviderName(
            )
            debug_entries["Runtime"] = KnownUser.__getRunTime()
            debug_entries["TargetUrl"] = target_url
            debug_entries["QueueitToken"] = queueit_token
            debug_entries[
                "OriginalUrl"] = http_context_provider.getOriginalRequestUrl()
            if cancel_config is None:
                debug_entries["CancelConfig"] = "NULL"
            else:
                debug_entries["CancelConfig"] = cancel_config.toString()
            KnownUser.__logMoreRequestDetails(debug_entries,
                                              http_context_provider)

        if Utils.isNilOrEmpty(target_url):
            raise KnownUserError("targetUrl can not be none or empty.")

        if Utils.isNilOrEmpty(customer_id):
            raise KnownUserError("customerId can not be none or empty.")

        if Utils.isNilOrEmpty(secret_key):
            raise KnownUserError("secretKey can not be none or empty.")

        if cancel_config is None:
            raise KnownUserError("cancelConfig can not be none.")

        if Utils.isNilOrEmpty(cancel_config.eventId):
            raise KnownUserError(
                "cancelConfig.eventId can not be none or empty.")

        if Utils.isNilOrEmpty(cancel_config.queueDomain):
            raise KnownUserError(
                "cancelConfig.queueDomain can not be none or empty.")

        user_in_queue_service = KnownUser.__getUserInQueueService(
            http_context_provider)
        result = user_in_queue_service.validateCancelRequest(
            target_url, cancel_config, customer_id, secret_key)
        result.isAjaxResult = KnownUser.__isQueueAjaxCall(
            http_context_provider)

        return result
Example #4
0
    def __resolveQueueRequestByLocalConfig(targetUrl, queueitToken,
                                           queueConfig, customerId, secretKey,
                                           httpContextProvider, debugEntries):
        isDebug = KnownUser.__getIsDebug(queueitToken, secretKey)
        if (isDebug):
            debugEntries["TargetUrl"] = targetUrl
            debugEntries["QueueitToken"] = queueitToken
            debugEntries[
                "OriginalUrl"] = httpContextProvider.getOriginalRequestUrl()
            if (queueConfig == None):
                debugEntries["QueueConfig"] = "NULL"
            else:
                debugEntries["QueueConfig"] = queueConfig.toString()
            KnownUser.__logMoreRequestDetails(debugEntries,
                                              httpContextProvider)

        if (Utils.isNilOrEmpty(customerId)):
            raise KnownUserError("customerId can not be none or empty.")

        if (Utils.isNilOrEmpty(secretKey)):
            raise KnownUserError("secretKey can not be none or empty.")

        if (queueConfig == None):
            raise KnownUserError("queueConfig can not be none.")

        if (Utils.isNilOrEmpty(queueConfig.eventId)):
            raise KnownUserError(
                "queueConfig.eventId can not be none or empty.")

        if (Utils.isNilOrEmpty(queueConfig.queueDomain)):
            raise KnownUserError(
                "queueConfig.queueDomain can not be none or empty.")

        minutes = QueueitHelpers.convertToInt(queueConfig.cookieValidityMinute)
        if (minutes <= 0):
            raise KnownUserError(
                "queueConfig.cookieValidityMinute should be integer greater than 0."
            )

        if (queueConfig.extendCookieValidity != True
                and queueConfig.extendCookieValidity != False):
            raise KnownUserError(
                "queueConfig.extendCookieValidity should be valid boolean.")

        userInQueueService = KnownUser.__getUserInQueueService(
            httpContextProvider)
        result = userInQueueService.validateQueueRequest(
            targetUrl, queueitToken, queueConfig, customerId, secretKey)
        result.isAjaxResult = KnownUser.__isQueueAjaxCall(httpContextProvider)
        return result
    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)
Example #7
0
    def extendQueueCookie(eventId, cookieValidityMinute, cookieDomain,
                          secretKey, httpContextProvider):
        if (Utils.isNilOrEmpty(eventId)):
            raise KnownUserError("eventId can not be none or empty.")

        if (Utils.isNilOrEmpty(secretKey)):
            raise KnownUserError("secretKey can not be none or empty.")

        minutes = QueueitHelpers.convertToInt(cookieValidityMinute)
        if (minutes <= 0):
            raise KnownUserError(
                "cookieValidityMinute should be integer greater than 0.")

        userInQueueService = KnownUser.__getUserInQueueService(
            httpContextProvider)
        userInQueueService.extendQueueCookie(eventId, cookieValidityMinute,
                                             cookieDomain, secretKey)
Example #8
0
    def __cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig,
                                     customerId, secretKey,
                                     httpContextProvider, debugEntries):
        targetUrl = KnownUser.__generateTargetUrl(targetUrl,
                                                  httpContextProvider)
        isDebug = KnownUser.__getIsDebug(queueitToken, secretKey)
        if (isDebug):
            debugEntries["TargetUrl"] = targetUrl
            debugEntries["QueueitToken"] = queueitToken
            debugEntries[
                "OriginalUrl"] = httpContextProvider.getOriginalRequestUrl()
            if (cancelConfig == None):
                debugEntries["CancelConfig"] = "NULL"
            else:
                debugEntries["CancelConfig"] = cancelConfig.toString()
            KnownUser.__logMoreRequestDetails(debugEntries,
                                              httpContextProvider)

        if (Utils.isNilOrEmpty(targetUrl)):
            raise KnownUserError("targetUrl can not be none or empty.")

        if (Utils.isNilOrEmpty(customerId)):
            raise KnownUserError("customerId can not be none or empty.")

        if (Utils.isNilOrEmpty(secretKey)):
            raise KnownUserError("secretKey can not be none or empty.")

        if (cancelConfig == None):
            raise KnownUserError("cancelConfig can not be none.")

        if (Utils.isNilOrEmpty(cancelConfig.eventId)):
            raise KnownUserError(
                "cancelConfig.eventId can not be none or empty.")

        if (Utils.isNilOrEmpty(cancelConfig.queueDomain)):
            raise KnownUserError(
                "cancelConfig.queueDomain can not be none or empty.")

        userInQueueService = KnownUser.__getUserInQueueService(
            httpContextProvider)
        result = userInQueueService.validateCancelRequest(
            targetUrl, cancelConfig, customerId, secretKey)
        result.isAjaxResult = KnownUser.__isQueueAjaxCall(httpContextProvider)

        return result
    def __createCookieValue(eventId, queueId, fixedCookieValidityMinutes,
                            redirectType, secretKey):
        issueTime = Utils.toString(QueueitHelpers.getCurrentTime())
        hashValue = UserInQueueStateCookieRepository.__generateHash(
            eventId, queueId, fixedCookieValidityMinutes, redirectType,
            issueTime, secretKey)

        fixedCookieValidityMinutesPart = ""
        if (not Utils.isNilOrEmpty(fixedCookieValidityMinutes)):
            fixedCookieValidityMinutesPart = "&FixedValidityMins=" + fixedCookieValidityMinutes

        cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + fixedCookieValidityMinutesPart + "&RedirectType=" + redirectType + "&IssueTime=" + issueTime + "&Hash=" + hashValue
        return cookieValue
Example #10
0
    def extendQueueCookie(event_id, cookie_validity_minute, cookie_domain,
                          is_cookie_http_only, is_cookie_secure, secret_key,
                          http_context_provider):
        if Utils.isNilOrEmpty(event_id):
            raise KnownUserError("eventId can not be none or empty.")

        if Utils.isNilOrEmpty(secret_key):
            raise KnownUserError("secretKey can not be none or empty.")

        minutes = QueueitHelpers.convertToInt(cookie_validity_minute)
        if minutes <= 0:
            raise KnownUserError(
                "cookieValidityMinute should be integer greater than 0.")

        user_in_queue_service = KnownUser.__getUserInQueueService(
            http_context_provider)

        user_in_queue_service.extendQueueCookie(event_id,
                                                cookie_validity_minute,
                                                cookie_domain,
                                                is_cookie_http_only,
                                                is_cookie_secure, secret_key)
Example #11
0
    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)
Example #12
0
    def __getQueryString(self, customer_id, event_id, config_version,
                         action_name, culture, layout_name):
        query_string_list = [
            "c=" + QueueitHelpers.urlEncode(customer_id),
            "e=" + QueueitHelpers.urlEncode(event_id),
            "ver=" + self.SDK_VERSION, "kupver=" + QueueitHelpers.urlEncode(
                self.httpContextProvider.getProviderName())
        ]
        if config_version is None:
            config_version = "-1"
        query_string_list.append("cver=" + str(config_version))
        query_string_list.append("man=" +
                                 QueueitHelpers.urlEncode(action_name))

        if not Utils.isNilOrEmpty(culture):
            query_string_list.append("cid=" +
                                     QueueitHelpers.urlEncode(culture))

        if not Utils.isNilOrEmpty(layout_name):
            query_string_list.append("l=" +
                                     QueueitHelpers.urlEncode(layout_name))

        return "&".join(query_string_list)
    def __getQueryString(self, customerId, eventId, configVersion, culture,
                         layoutName):
        queryStringList = []
        queryStringList.append(
            "c=" + QueueitHelpers.urlEncode(customerId))
        queryStringList.append(
            "e=" + QueueitHelpers.urlEncode(eventId))
        queryStringList.append("ver=v3-py_" +
                               self.httpContextProvider.getProviderName() +
                               "-" + self.SDK_VERSION)

        if (configVersion is None):
            configVersion = "-1"
        queryStringList.append("cver=" + str(configVersion))

        if (not Utils.isNilOrEmpty(culture)):
            queryStringList.append(
                "cid=" + QueueitHelpers.urlEncode(culture))

        if (not Utils.isNilOrEmpty(layoutName)):
            queryStringList.append(
                "l=" + QueueitHelpers.urlEncode(layoutName))

        return "&".join(queryStringList)
Example #14
0
    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 extractQueueParams(queueitToken):
        try:
            if (Utils.isNilOrEmpty(queueitToken)):
                return None

            result = QueueUrlParams()
            result.queueITToken = queueitToken
            paramsNameValueList = result.queueITToken.split(
                QueueUrlParams.KEY_VALUE_SEPARATOR_GROUP_CHAR)

            for pNameValue in paramsNameValueList:
                paramNameValueArr = pNameValue.split(
                    QueueUrlParams.KEY_VALUE_SEPARATOR_CHAR)
                if (paramNameValueArr[0] == QueueUrlParams.TIMESTAMP_KEY):
                    try:
                        result.timeStamp = int(paramNameValueArr[1])
                    except:
                        result.timeStamp = 0
                elif (paramNameValueArr[0] ==
                      QueueUrlParams.COOKIE_VALIDITY_MINUTES_KEY):
                    try:
                        result.cookieValidityMinutes = int(
                            paramNameValueArr[1])
                    except:
                        result.cookieValidityMinutes = None
                elif (paramNameValueArr[0] == QueueUrlParams.EVENT_ID_KEY):
                    result.eventId = paramNameValueArr[1]
                elif (paramNameValueArr[0] ==
                      QueueUrlParams.EXTENDABLE_COOKIE_KEY):
                    if (paramNameValueArr[1].upper() == 'TRUE'):
                        result.extendableCookie = True
                elif (paramNameValueArr[0] == QueueUrlParams.HASH_KEY):
                    result.hashCode = paramNameValueArr[1]
                elif (paramNameValueArr[0] == QueueUrlParams.QUEUE_ID_KEY):
                    result.queueId = paramNameValueArr[1]
                elif (paramNameValueArr[0] == QueueUrlParams.REDIRECT_TYPE_KEY
                      ):
                    result.redirectType = paramNameValueArr[1]

            hashValue = QueueUrlParams.KEY_VALUE_SEPARATOR_GROUP_CHAR + QueueUrlParams.HASH_KEY \
            + QueueUrlParams.KEY_VALUE_SEPARATOR_CHAR \
            + result.hashCode
            result.queueITTokenWithoutHash = result.queueITToken.replace(
                hashValue, "")
            return result
        except:
            return None
    def __isCookieValid(secretKey, cookieNameValueMap, eventId,
                        cookieValidityMinutes, validateTime):
        try:
            if ("EventId" not in cookieNameValueMap):
                return False

            if ("QueueId" not in cookieNameValueMap):
                return False

            if ("RedirectType" not in cookieNameValueMap):
                return False

            if ("IssueTime" not in cookieNameValueMap):
                return False

            if ("Hash" not in cookieNameValueMap):
                return False

            fixedCookieValidityMinutes = ""
            if ("FixedValidityMins" in cookieNameValueMap):
                fixedCookieValidityMinutes = cookieNameValueMap[
                    "FixedValidityMins"]

            hashValue = UserInQueueStateCookieRepository.__generateHash(
                cookieNameValueMap["EventId"], cookieNameValueMap["QueueId"],
                fixedCookieValidityMinutes, cookieNameValueMap["RedirectType"],
                cookieNameValueMap["IssueTime"], secretKey)

            if (hashValue != cookieNameValueMap["Hash"]):
                return False

            if (eventId.upper() != cookieNameValueMap["EventId"].upper()):
                return False

            if (validateTime):
                validity = cookieValidityMinutes
                if (not Utils.isNilOrEmpty(fixedCookieValidityMinutes)):
                    validity = int(fixedCookieValidityMinutes)

                expirationTime = int(
                    cookieNameValueMap["IssueTime"]) + (validity * 60)
                if (expirationTime < QueueitHelpers.getCurrentTime()):
                    return False

            return True
        except:
            return False
Example #18
0
    def __isCookieValid(secret_key, cookie_name_value_map, event_id,
                        cookie_validity_minutes, validate_time):
        try:
            if "EventId" not in cookie_name_value_map:
                return False

            if "QueueId" not in cookie_name_value_map:
                return False

            if "RedirectType" not in cookie_name_value_map:
                return False

            if "IssueTime" not in cookie_name_value_map:
                return False

            if "Hash" not in cookie_name_value_map:
                return False

            fixed_cookie_validity_minutes = ""
            if "FixedValidityMins" in cookie_name_value_map:
                fixed_cookie_validity_minutes = cookie_name_value_map["FixedValidityMins"]

            hash_value = UserInQueueStateCookieRepository.__generateHash(
                cookie_name_value_map["EventId"], cookie_name_value_map["QueueId"],
                fixed_cookie_validity_minutes, cookie_name_value_map["RedirectType"],
                cookie_name_value_map["IssueTime"], secret_key)

            if hash_value != cookie_name_value_map["Hash"]:
                return False

            if event_id.upper() != cookie_name_value_map["EventId"].upper():
                return False

            if validate_time:
                validity = cookie_validity_minutes
                if not Utils.isNilOrEmpty(fixed_cookie_validity_minutes):
                    validity = int(fixed_cookie_validity_minutes)

                expiration_time = int(cookie_name_value_map["IssueTime"]) + (validity * 60)
                if expiration_time < QueueitHelpers.getCurrentTime():
                    return False

            return True
        except:
            return False
Example #19
0
    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 __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)
Example #21
0
    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 extractQueueParams(queueit_token):
        result = QueueUrlParams()
        if Utils.isNilOrEmpty(queueit_token):
            return None
        result.queueITToken = queueit_token
        params_name_value_list = result.queueITToken.split(
            QueueUrlParams.KEY_VALUE_SEPARATOR_GROUP_CHAR)
        for pNameValue in params_name_value_list:
            param_name_value_arr = pNameValue.split(
                QueueUrlParams.KEY_VALUE_SEPARATOR_CHAR)
            if len(param_name_value_arr) != 2:
                continue
            param_name = param_name_value_arr[0]
            param_value = param_name_value_arr[1]

            if param_name == QueueUrlParams.HASH_KEY:
                result.hashCode = param_value
            elif param_name == QueueUrlParams.TIMESTAMP_KEY:
                if not param_value.isdigit():
                    continue
                result.timeStamp = int(param_value)
            elif param_name == QueueUrlParams.COOKIE_VALIDITY_MINUTES_KEY:
                if not param_value.isdigit():
                    continue
                result.cookieValidityMinutes = int(param_value)
            elif param_name == QueueUrlParams.EVENT_ID_KEY:
                result.eventId = param_value
            elif param_name == QueueUrlParams.EXTENDABLE_COOKIE_KEY:
                if param_value.upper() == 'TRUE':
                    result.extendableCookie = True
            elif param_name == QueueUrlParams.QUEUE_ID_KEY:
                result.queueId = param_value
            elif param_name == QueueUrlParams.REDIRECT_TYPE_KEY:
                result.redirectType = param_value

        hash_value = QueueUrlParams.KEY_VALUE_SEPARATOR_GROUP_CHAR + QueueUrlParams.HASH_KEY \
                     + QueueUrlParams.KEY_VALUE_SEPARATOR_CHAR \
                     + result.hashCode
        result.queueITTokenWithoutHash = result.queueITToken.replace(
            hash_value, "")
        return result
Example #23
0
 def isStateExtendable(self):
     return self.isValid and Utils.isNilOrEmpty(
         self.fixedCookieValidityMinutes)
Example #24
0
    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
Example #25
0
    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