Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <AutenticacaoIdentityServer>(Configuration.GetSection("AutenticacaoIdentityServer"));

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IClientAccessToken, AcessoCidadaoClientAccessToken>();
            services.AddScoped <ICurrentUserProvider, CurrentUser>();

            ConfiguracaoDependencias.InjetarDependencias(services);
            ConfiguracaoAutoMapper.CriarMapeamento();

            #region Hnagfire
            //Verica se está no ambiente de desenvolvimento para não iniciar o serviço
            //if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != "Development")
            //{
            var provider     = services.BuildServiceProvider();
            var scopeFactory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory));

            services.AddHangfire(configuration =>
            {
                configuration.UseSqlServerStorage(Environment.GetEnvironmentVariable("OrganogramaConnectionString"), new SqlServerStorageOptions {
                    PrepareSchemaIfNecessary = false
                });
                configuration.UseActivator <AspNetCoreJobActivator>(new AspNetCoreJobActivator(scopeFactory));
            });
            //}
            #endregion

            services.AddMvc();
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Configurar o objeto AutenticacaoIdentityServer para ser usado na autenticação
            services.Configure <AutenticacaoIdentityServer>(Configuration.GetSection("AutenticacaoIdentityServer"));

            services.AddMemoryCache();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IClientAccessToken, AcessoCidadaoClientAccessToken>();
            services.AddScoped <ICurrentUserProvider, CurrentUser>();

            ConfiguracaoDependencias.InjetarDependencias(services);
            ConfiguracaoAutoMapper.CriarMapeamento();

            // Add framework services.
            services.AddMvc()
            .AddJsonOptions(opt =>
            {
                opt.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            });

            services.AddCors(setupAction => setupAction.AddPolicy("default", policy => policy.AllowAnyOrigin()
                                                                  .AllowAnyHeader()
                                                                  .AllowAnyMethod()));

            #region Políticas que serão concedidas
            services.AddAuthorization(options =>
            {
                options.AddPolicy("Esfera.Inserir", policy => policy.RequireClaim("Acao$Esfera", "Inserir"));
                options.AddPolicy("Esfera.Alterar", policy => policy.RequireClaim("Acao$Esfera", "Alterar"));
                options.AddPolicy("Esfera.Excluir", policy => policy.RequireClaim("Acao$Esfera", "Excluir"));
                options.AddPolicy("Municipio.Inserir", policy => policy.RequireClaim("Acao$Municipio", "Inserir"));
                options.AddPolicy("Municipio.Alterar", policy => policy.RequireClaim("Acao$Municipio", "Alterar"));
                options.AddPolicy("Municipio.Excluir", policy => policy.RequireClaim("Acao$Municipio", "Excluir"));
                options.AddPolicy("Organizacao.Inserir", policy => policy.RequireClaim("Acao$Organizacao", "Inserir"));
                options.AddPolicy("Organizacao.InserirPatriarca", policy => policy.RequireClaim("Acao$Organizacao", "InserirPatriarca"));
                options.AddPolicy("Organizacao.Alterar", policy => policy.RequireClaim("Acao$Organizacao", "Alterar"));
                options.AddPolicy("Organizacao.Excluir", policy => policy.RequireClaim("Acao$Organizacao", "Excluir"));
                options.AddPolicy("Poder.Inserir", policy => policy.RequireClaim("Acao$Poder", "Inserir"));
                options.AddPolicy("Poder.Alterar", policy => policy.RequireClaim("Acao$Poder", "Alterar"));
                options.AddPolicy("Poder.Excluir", policy => policy.RequireClaim("Acao$Poder", "Excluir"));
                options.AddPolicy("TipoOrganizacao.Inserir", policy => policy.RequireClaim("Acao$TipoOrganizacao", "Inserir"));
                options.AddPolicy("TipoOrganizacao.Alterar", policy => policy.RequireClaim("Acao$TipoOrganizacao", "Alterar"));
                options.AddPolicy("TipoOrganizacao.Excluir", policy => policy.RequireClaim("Acao$TipoOrganizacao", "Excluir"));
                options.AddPolicy("TipoUnidade.Inserir", policy => policy.RequireClaim("Acao$TipoUnidade", "Inserir"));
                options.AddPolicy("TipoUnidade.Alterar", policy => policy.RequireClaim("Acao$TipoUnidade", "Alterar"));
                options.AddPolicy("TipoUnidade.Excluir", policy => policy.RequireClaim("Acao$TipoUnidade", "Excluir"));
                options.AddPolicy("Unidade.Inserir", policy => policy.RequireClaim("Acao$Unidade", "Inserir"));
                options.AddPolicy("Unidade.Alterar", policy => policy.RequireClaim("Acao$Unidade", "Alterar"));
                options.AddPolicy("Unidade.Excluir", policy => policy.RequireClaim("Acao$Unidade", "Excluir"));
                options.AddPolicy("IntegracaoSiarhes.Integrar", policy => policy.RequireClaim("Acao$IntegracaoSiarhes", "Integrar"));
                options.AddPolicy("AcessoCidadao", policy => policy.RequireClaim("scope", "api-organograma-acessocidadao"));
            }
                                      );
            #endregion

            #region Configuração do Swagger
            // Inject an implementation of ISwaggerProvider with defaulted settings applied
            services.AddSwaggerGen();

            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version        = "v1",
                    Title          = "Organograma Web API",
                    Description    = "Núcleo de serviço do sistema Organograma implementado pelo Governo do Estado do Espírito Santo.",
                    TermsOfService = "None",
                    Contact        = new Contact
                    {
                        Name  = "PRODEST",
                        Email = "*****@*****.**",
                        Url   = "http://prodest.es.gov.br"
                    }
                });

                //Determine base path for the application.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;

                //Set the comments path for the swagger json and ui.
                var xmlPath = Path.Combine(basePath, "WebAPI.xml");
                //options.IncludeXmlComments(xmlPath);
            });
            #endregion
        }