Esempio n. 1
0
        public async Task <Dictionary <string, object> > ValidateUnregisteredDevice(string deviceId)
        {
            Dictionary <string, object> deviceInfo = null;

            using (var client = openAmHttpClient(ClientType.Device))
            {
                var url = "auth/json/sessions/?_action=getProperty";

                var content = new StringContent(string.Empty, Encoding.UTF8, "application/json");
                content.Headers.Add("mgiSsoSession", deviceId);

                var response = await client.PostAsync(url, content);

                // This helps to see requests in Fiddler
                // Should not be uncommented for anything except debugging purposes
                //WebRequest.DefaultWebProxy = new WebProxy("127.0.0.1", 8888);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(null);
                }

                var responseData = await response.Content.ReadAsStringAsync();

                deviceInfo = JsonProcessor.DeserializeObject <Dictionary <string, object> >(responseData);
                deviceInfo = deviceInfo.Where(prop => !string.IsNullOrWhiteSpace((string)prop.Value))
                             .ToDictionary(prop => prop.Key,
                                           prop => prop.Value);
            }

            return(deviceInfo);
        }
        public MoAndLocationRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            MoAndLocations = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <MoAndLocationsData>(jsonData): new MoAndLocationsData();
        }
        public static TResponse GetTransactionLookupStatusResponse <TResponse>(string referenceNumber, Func <TrainingModeResponses, string> getFileName)
        {
            var instance = GetConfiguration();

            var scenario = instance.Scenarios.SingleOrDefault(x => x.ReferenceNumber == referenceNumber && getFileName(x.Responses) != null);


            if (scenario?.Responses == null)
            {
                throw new TrainingModeException("STRKEY_TRAINING_ERROR_EDIT_TRAN_REF_NUMBER");
            }

            var responseFilePath = Path.Combine(JsonFileHelper.ExecutingDir(), TrainingModeFolderName, scenario.SessionType.ToString(), referenceNumber ?? string.Empty, getFileName(scenario.Responses));

            if (!File.Exists(responseFilePath))
            {
                throw new FileNotFoundException($"Could not find Training Mode Transaction Lookup Status response file for referenceNumber:{referenceNumber}.");
            }
            try
            {
                return(JsonProcessor.DeserializeObject <TResponse>(JsonFileHelper.GetFileContents(responseFilePath), true));
            }
            catch (Exception exception)
            {
                throw new InvalidDataException($"Could not deserialize Training Mode Transaction Lookup Status response for sessionType:{scenario.SessionType}, referenceNumber:{referenceNumber}.", exception);
            }
        }
Esempio n. 4
0
        public EnvironmentAgentRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            Identities = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <Dictionary <string, List <EnvironmentAgent> > >(jsonData)
                : null;

            Identities = Identities ?? new Dictionary <string, List <EnvironmentAgent> >();
        }
        public SupportAuthPrincipalCreator()
        {
            var jsonFile = Path.Combine(JsonFileHelper.ExecutingDir(), ConfigurationManager.AppSettings["SupportAuthFileName"]);

            if (File.Exists(jsonFile))
            {
                var jsonData = File.ReadAllText(jsonFile);
                this.supportAuthAgents = JsonProcessor.DeserializeObject <Dictionary <string, AuthClaimsVm> >(jsonData);
            }
        }
Esempio n. 6
0
        public EnvironmentRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            Environments = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <AcEnvironment>(jsonData)?.Environments
                           .ToDictionary(x => x, x => x)
                : null;

            Environments = Environments ?? new Dictionary <string, string>();
        }
Esempio n. 7
0
        public CurrencyRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            Currencies = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <Dictionary <string, List <CurrencyInfo> > >(jsonData)
                         .FirstOrDefault().Value?
                         .ToDictionary(x => x.CurrencyCode, x => x)
                : null;

            Currencies = Currencies ?? new Dictionary <string, CurrencyInfo>();
        }
        public ServiceOptionRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            ServiceOptions = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <Dictionary <string, List <ServiceOption> > >(jsonData)
                             .FirstOrDefault().Value?
                             .ToDictionary(x => x.Code, x => x)
                : null;

            ServiceOptions = ServiceOptions ?? new Dictionary <string, ServiceOption>();
        }
Esempio n. 9
0
        public RefundReasonRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            RefundReasons = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <Dictionary <string, List <EnumeratedIdentifierInfo> > >(jsonData)
                            .FirstOrDefault().Value?
                            .ToDictionary(x => x.Identifier, x => x)
                : null;

            RefundReasons = RefundReasons ?? new Dictionary <string, EnumeratedIdentifierInfo>();
        }
        public ApiKeyPrincipalCreator(IAgentProfilePrincipalService agentConnectPrincipalService) :
            base(agentConnectPrincipalService)
        {
            var jsonFile = Path.Combine(JsonFileHelper.ExecutingDir(), ConfigurationManager.AppSettings["apiKeysFileName"]);

            if (File.Exists(jsonFile))
            {
                var jsonData = File.ReadAllText(jsonFile);
                this.apiKeyAgents = JsonProcessor.DeserializeObject <Dictionary <string, FakeAuthInfoVm> >(jsonData)
                                    .ToDictionary(x => x.Key, x => x.Value.ToAuthClaimsVm());
            }
        }
        public CountrySubdivisionRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            Subdivisions = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <Dictionary <string, List <CountrySubdivisionInfo> > >(jsonData)
                           .FirstOrDefault().Value?
                           .ToDictionary(x => x.CountryCode, x => x.Subdivisions)
                : null;

            Subdivisions = Subdivisions ?? new Dictionary <string, List <SubdivisionInfo> >();
        }
Esempio n. 12
0
        public AmountRangeRepository()
        {
            var jsonData = JsonFileHelper.GetFileContents(_configurationFilePath);

            AmountRanges = !string.IsNullOrEmpty(jsonData)
                ? JsonProcessor.DeserializeObject <Dictionary <string, List <AmountRange> > >(jsonData)
                           .FirstOrDefault().Value?
                           .ToDictionary(x => x.Code, x => x)
                : null;

            AmountRanges = AmountRanges ?? new Dictionary <string, AmountRange>();
        }
        /// <summary>
        /// Gets response for training mode scenario step specified by parameters
        /// </summary>
        /// <typeparam name="TResponse">Type of response to be deserialized</typeparam>
        /// <param name="sessionType">Type of session</param>
        /// <param name="referenceNumber">Reference number / MGI Session Id</param>
        /// <param name="getFileName">Expression to get required file name from TrainingModeResponses object</param>
        /// <returns>Response object if response is found, otherwise exception is thrown.</returns>
        public static TResponse GetResponse <TResponse>(SessionType?sessionType, string referenceNumber, Func <TrainingModeResponses, string> getFileName)
        {
            if ((sessionType == SessionType.SEND || sessionType == SessionType.BP) && referenceNumber != null && !IsStagedTransaction(sessionType, referenceNumber))
            {
                referenceNumber = null;
            }

            TrainingModeConfiguration instance = GetConfiguration();

            TrainingModeResponses responses = instance.Scenarios.SingleOrDefault(x =>
                                                                                 x.SessionType == sessionType && x.ReferenceNumber == referenceNumber)?.Responses;

            if (responses != null)
            {
                string sessionTypePath = sessionType != null?sessionType.ToString() : "AllTypes";

                string responseFilePath = Path.Combine(JsonFileHelper.ExecutingDir(), TrainingModeFolderName,
                                                       sessionTypePath, referenceNumber ?? string.Empty, getFileName(responses));

                if (File.Exists(responseFilePath))
                {
                    try
                    {
                        return(JsonProcessor.DeserializeObject <TResponse>(JsonFileHelper.GetFileContents(responseFilePath), true));
                    }
                    catch (Exception exception)
                    {
                        throw new InvalidDataException($"Could not deserialize Training Mode response for sessionType:{sessionType}, referenceNumber:{referenceNumber}.", exception);
                    }
                }
            }
            else
            {
                switch (sessionType)
                {
                case SessionType.AMD:
                    throw new TrainingModeException("STRKEY_TRAINING_ERROR_AMEND_REF_NUMBER");

                case SessionType.SREV:
                    throw new TrainingModeException("STRKEY_TRAINING_ERROR_SREV_REF_NUMBER");

                case SessionType.RCV:
                    throw new TrainingModeException("STRKEY_TRAINING_ERROR_RCV_REF_NUMBER");
                }
            }

            throw new FileNotFoundException($"Could not find Training Mode response file for sessionType:{sessionType}, referenceNumber:{referenceNumber}.");
        }
Esempio n. 14
0
        public async Task <Dictionary <string, object> > ValidateDevice(string deviceId)
        {
            // Mapping between properties received from OpenAM and their OAuth claim equivalents
            var sessionProperties = new Dictionary <string, string>
            {
                { "mgiMainOfficeId", "mgiMainOfficeId" },
                { "mgiDeviceAgentId", "mgiDeviceAgentLocationId" },
                { "mgiDevicePosNumber", "mgiDevicePosNumber" },
                { "mgiDeviceId", "mgiDeviceId" }
            };

            Dictionary <string, object> deviceInfo = null;

            using (var client = openAmHttpClient(ClientType.Device))
            {
                var url     = "auth/json/sessions/?_action=getProperty";
                var request = new
                {
                    properties = sessionProperties.Keys.ToList()
                };

                var content = new StringContent(JsonProcessor.SerializeObject(request), Encoding.UTF8,
                                                "application/json");
                content.Headers.Add("mgiSsoSession", deviceId);

                var response = await client.PostAsync(url, content);

                // This helps to see requests in Fiddler
                // Should not be uncommented for anything except debugging purposes
                //WebRequest.DefaultWebProxy = new WebProxy("127.0.0.1", 8888);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(null);
                }

                var responseData = await response.Content.ReadAsStringAsync();

                deviceInfo = JsonProcessor.DeserializeObject <Dictionary <string, object> >(responseData);

                // Convert to OAuth claim names
                deviceInfo = deviceInfo
                             .Select(x => new KeyValuePair <string, object>(sessionProperties[x.Key], x.Value))
                             .ToDictionary(x => x.Key, x => x.Value);
            }

            return(deviceInfo);
        }
        private static TrainingModeConfiguration GetConfiguration()
        {
            if (!File.Exists(ConfigurationPath))
            {
                throw new FileNotFoundException($"Could not find Training Mode configuration file under path: {ConfigurationPath}.");
            }

            try
            {
                return(JsonProcessor.DeserializeObject <TrainingModeConfiguration>(JsonFileHelper.GetFileContents(ConfigurationPath)));
            }
            catch (Exception exception)
            {
                throw new InvalidDataException($"Could not deserialize Training Mode configuration file under path: {ConfigurationPath}.", exception);
            }
        }
Esempio n. 16
0
        public async Task <Dictionary <string, object> > GetUserInfo(string token)
        {
            Dictionary <string, object> userInfo = null;

            using (var client = openAmHttpClient(ClientType.User))
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var realm    = !string.IsNullOrEmpty(openAmConfig.Realm) ? openAmConfig.Realm + "/" : string.Empty;
                var response =
                    await client.PostAsync("auth/oauth2/" + realm + "userinfo", new StringContent(string.Empty));

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    userInfo = JsonProcessor.DeserializeObject <Dictionary <string, object> >(content);
                }
            }

            return(userInfo);
        }
Esempio n. 17
0
        public async Task <PartnerHierarchyAgentResponse> GetPartnerHierarchyAgent(PartnerHierarchyAgentRequest request)
        {
            PartnerHierarchyAgentResponse result = null;

            using (var client = new HttpClient(new HttpClientHandler()))
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                string requestUrl            = $"{_partnerHierarchyConfig.PartnerHierarchyUrl}/mainoffices/{request.MainofficeId}/locations/{request.LocationId}";
                HttpResponseMessage response = await client.GetAsync(requestUrl).ConfigureAwait(false);

                string content = await response.Content.ReadAsStringAsync();

                try //try to deserialize response version with single Agent
                {
                    return(JsonProcessor.DeserializeObject <PartnerHierarchySingleAgentResponse>(content));
                }
                catch (JsonSerializationException) //if fails try deserialize response version where Agent is collection
                {
                    return(JsonProcessor.DeserializeObject <PartnerHierarchyMultiAgentResponse>(content));
                }
            }
        }