Exemplo n.º 1
0
        public async Task <UserPaper> GetUserPaper(String document, string phone)
        {
            string url = String.Format(String.Concat(DataConstants.Endpoint, DataConstants.SecurityManualURL), document);

            if (phone != null && phone.Length > 0)
            {
                url = String.Concat(url, "&telefonoEmpleado=", HttpUtility.UrlEncode(phone));
            }

            var response = await MakeApiKeyHttpCall <BaseResponse <UserPaperData>, string>(url, HttpVerbMethod.Get, null)
                           .ConfigureAwait(false);

            if (response.HasError)
            {
                if (response.info != null && response.info.Count() > 0)
                {
                    response.Message = String.Join("\n", response.info.Select(x => x.message));
                }
                throw new ApiException()
                      {
                          Code  = response.status,
                          Error = response.Message
                      };
            }
            return(SecurityMapper.MapUser(response.data.ElementAt(0)));
        }
Exemplo n.º 2
0
 public SecurityService(ISecurityRepository repository, IConfiguration config, IList <Token> tokens)
 {
     this.Repository    = repository;
     this.TokenStore    = tokens;
     this.Configuration = config;
     SecurityMapper.Map();
 }
Exemplo n.º 3
0
        public async Task <IEnumerable <Location> > GetLocations()
        {
            string url = String.Concat(DataConstants.Endpoint, DataConstants.SecurityLocationsURL);

            var response = await MakeApiKeyHttpCall <BaseResponse <LocationData>, string>(url, HttpVerbMethod.Get, null)
                           .ConfigureAwait(false);

            if (response.HasError)
            {
                if (response.info != null && response.info.Count() > 0)
                {
                    response.Message = String.Join("\n", response.info.Select(x => x.message));
                }
                throw new ApiException()
                      {
                          Code  = response.status,
                          Error = response.Message
                      };
            }
            return(SecurityMapper.MapLocationList(response.data));
        }
Exemplo n.º 4
0
        public ICollection <GeneratedFile> FromStream(Stream stream, GeneratorSettings settings, out OpenApiDiagnostic diagnostic)
        {
            var reader          = new OpenApiStreamReader();
            var openApiDocument = reader.Read(stream, out diagnostic);

            var models     = new ModelsMapper(settings, diagnostic.SpecificationVersion).Map(openApiDocument.Components.Schemas).ToList();
            var @interface = new InterfaceMapper(settings).Map(openApiDocument);
            var security   = new SecurityMapper(settings).Map(openApiDocument);

            var files = new List <GeneratedFile>
            {
                // Add Interface
                new GeneratedFile
                {
                    Path    = settings.ApiNamespace,
                    Name    = $"{@interface.Name}.cs",
                    Content = new InterfaceBuilder(settings).Build(@interface, security, models.Any())
                }
            };

            var extensions = new ExtensionMethodsBuilder(settings).Build(@interface, @interface.Name);

            if (extensions != null)
            {
                // Add ApiExtension
                files.Add(new GeneratedFile
                {
                    Path    = settings.ApiNamespace,
                    Name    = $"{new string(@interface.Name.Skip(1).ToArray())}Extensions.cs",
                    Content = extensions
                });
            }

            // Add Models
            var modelBuilder = new ModelBuilder(settings);

            files.AddRange(models.Select(model => new GeneratedFile
            {
                Path    = settings.ModelsNamespace,
                Name    = $"{model.ClassName}.cs",
                Content = modelBuilder.Build(model)
            }));

            // Add Inline Models
            files.AddRange(@interface.InlineModels.Select(model => new GeneratedFile
            {
                Path    = settings.ModelsNamespace,
                Name    = $"{model.ClassName}.cs",
                Content = modelBuilder.Build(model)
            }));

            if (settings.SingleFile)
            {
                return(new[] { new GeneratedFile
                               {
                                   Path = string.Empty,
                                   Name = $"{@interface.Name}.cs",
                                   Content = string.Join("\r\n", files.Select(f => f.Content))
                               } });
            }

            return(files);
        }
Exemplo n.º 5
0
        //private static TextWriterTraceListener listener;

        /// <summary>
        /// Performs login operation using specified credentials and reads user's permission.
        /// </summary>
        /// <param name="username">Username.</param>
        /// <param name="password">Password (SHA 256 hash).</param>
        /// <param name="language">User's language version.</param>
        /// <param name="hostAddress">Client's ip address or host name.</param>
        /// <returns>
        /// Created sessionId if successful; otherwise, <see cref="ClientException"/> is thrown.
        /// </returns>
        /// <exception cref="ClientException">InvalidLanguageVersion if supplied language is not supported.</exception>
        /// <exception cref="ClientException">AuthenticationError if supplied username or password is incorrect.</exception>
        public Guid LogOn(string username, string password, string language, string hostAddress)
        {
            /*if (listener != null)
             * {
             *  listener.Flush();
             *  listener.Close();
             *  listener = null;
             * }
             * listener = new TextWriterTraceListener("C:\\Inetpub\\wwwroot\\KernelServices\\Log\\Debug.xml");
             * Debug.Listeners.Add(listener);*/
            if (!this.allowedLanguages.Contains(language))
            {
                throw new ClientException(ClientExceptionId.InvalidLanguageVersion);
            }

            SqlConnectionManager.Instance.InitializeConnection();

            try
            {
                SecurityMapper mapper = DependencyContainerManager.Container.Get <SecurityMapper>();

                XDocument doc = mapper.GetApplicationUserData(username);

                XElement userElement = doc.Root.Element("applicationUser").Element("entry");

                if (userElement == null || userElement.Element("password") == null || userElement.Element("password").Value.ToUpperInvariant() != password.ToUpperInvariant()) //incorrect username
                {
                    throw new ClientException(ClientExceptionId.AuthenticationError);
                }

                User user = new User(new Guid(userElement.Element("contractorId").Value));

                //generate SessionID
                Guid sessionId = Guid.NewGuid();

                //set sessionId
                SessionManager.SessionId = sessionId;

                //create a new session
                SessionManager.CreateSession();

                //store User object in session
                SessionManager.User = user;

                //set user's language
                SessionManager.Language = language;

                if (hostAddress == null)
                {
                    hostAddress = String.Empty;
                }

                this.LoadUserData(user, userElement);

                var permissions = auth.CreatePrincipal(user.UserId.ToUpperString(), username, AuthenticationMethods.Password);
                user.Principal = permissions;
                System.Threading.Thread.CurrentPrincipal = permissions;

                XDocument xml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture,
                                                              "<root><host>{0}</host><sessionId>{1}</sessionId></root>", hostAddress, sessionId.ToUpperString()));

                //log the operation
                JournalManager.Instance.LogToJournal(JournalAction.User_LogOn, null, null, null, xml);

                return(sessionId);
            }
            finally
            {
                SqlConnectionManager.Instance.ReleaseConnection();
            }
        }