Ejemplo n.º 1
0
        public EmployRepositoryTest()
        {
            string mySqlEmployeesConnStr =
                "0nmBbjjPY3PGbA6j+7Ul0Od1V+u8TMv8E1oQrIvrJTqG8JHkQaQ40CGThX5pKBsAVir1FefOpPPZpgsFZLA6eO8fRum5wnZkcxGWw9aq0ovHRM0OhKYf1GS0YK2slp1jMaKpA0HDylDsswiZ3CByr0cUGPwqSEn04hJAd3FXfbWPpGlUZ4zQz0MO4avuEA1Z";

            connStrMySql     = AesCryptoUtil.Decrypt(mySqlEmployeesConnStr);
            dbOptionsbuilder = new DbContextOptionsBuilder <EmployeesContext>().UseMySQL(connStrMySql);
            context          = new EmployeesContext(dbOptionsbuilder.Options);
        }
Ejemplo n.º 2
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     if (!optionsBuilder.IsConfigured)
     {
         string mySqlEmployeesConnStr =
             "0nmBbjjPY3PGbA6j+7Ul0Od1V+u8TMv8E1oQrIvrJTqG8JHkQaQ40CGThX5pKBsAVir1FefOpPPZpgsFZLA6eO8fRum5wnZkcxGWw9aq0ovHRM0OhKYf1GS0YK2slp1jMaKpA0HDylDsswiZ3CByr0cUGPwqSEn04hJAd3FXfbWPpGlUZ4zQz0MO4avuEA1Z";
         string connStrMySql = AesCryptoUtil.Decrypt(mySqlEmployeesConnStr);
         optionsBuilder.UseMySQL(connStrMySql);
     }
 }
        public VirbelaListingContextShould()
        {
            // ConnString for Dev Environment
            string encConnStr =
                "RsJZctQGW8rsO2X/vhh7ewsDAKo8xDo7bEpjS7RwZFkq9KFLnlGEQLM9b3jGYARYVUINRxCTboYny3aWahtP7BHOew2ToMyxGDuO9BuYfpyZwH81uC883tyfXS2caR6rk0fTN1u/+dg05+L7sfLuDe8becDugt35NR2ahQEXCdVmHOs4JRAwWqvkL0EcqVVmwP4g1zUdfvg4yhzOtXVLmrf+xJFG6CFlCRw91hgUTCk5A6a2uPYHpKKiW7U0/cTZ6i9vKFqFJMvXxzRKU2hu3aMJ1iZsWgF3AR1jSwEOHQg=";

            connStr          = AesCryptoUtil.Decrypt(encConnStr);
            dbOptionsbuilder = new DbContextOptionsBuilder <VirbelaListingContext>()
                               .UseSqlServer(connStr);
            context = new VirbelaListingContext(dbOptionsbuilder.Options);
        }
        public ListingRepositoryShould()
        {
            // Development Setting
            // Server=tcp:virbelalisting.database.windows.net,1433;
            // Initial Catalog=VirbelaListingDev;
            // Persist Security Info=False;
            // User ID=appuser;
            // Password={password};
            // MultipleActiveResultSets=False;
            // Encrypt=True;TrustServerCertificate=False;
            string encConnStr =
                "RsJZctQGW8rsO2X/vhh7ewsDAKo8xDo7bEpjS7RwZFkq9KFLnlGEQLM9b3jGYARYVUINRxCTboYny3aWahtP7BHOew2ToMyxGDuO9BuYfpxmNDCVRydZ5efJTTL2O9FkiOGrbqlILlQPt5/8DcwssjosrrVeyxXrgIHB7pIN48IPOLp29HxT67vWGovw4jt+QtegcVynARe8g9XbGU6dB57kDogQ5t33I5iovM52B1o8tzRuYekLE/std6JtXC7McwscfvTKSE+85Woq7ljaLP6k5pRx83QaMvCe6Y7ICdAc5oKTzODrVpEZ+ae3uhaR";

            connStr          = AesCryptoUtil.Decrypt(encConnStr);
            dbOptionsbuilder = new DbContextOptionsBuilder <VirbelaListingContext>()
                               .UseSqlServer(connStr);
            context = new VirbelaListingContext(dbOptionsbuilder.Options);
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IConfiguration>(Configuration);
            this.securitySettings = ApiConfig.GetSecuritySettings(Configuration);

            services.AddSwaggerGen(c => {
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme {
                    Description =
                        @"JWT Authorization header using the Bearer scheme.
                        Enter token in the text input below.",
                    Name   = "Authorization",
                    In     = ParameterLocation.Header,
                    Type   = SecuritySchemeType.ApiKey,
                    Scheme = "Bearer"
                });

                c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme {
                            Reference = new OpenApiReference {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            },
                            Scheme = "oauth2",
                            Name   = "Bearer",
                            In     = ParameterLocation.Header,
                        },
                        new List <string>()
                    }
                });

                c.SwaggerDoc(
                    name: "v1",
                    new OpenApiInfo()
                {
                    Title   = "Virbela Classifieds API",
                    Version = "v1"
                }
                    );
            });


            // This is where CORS is set up, in case Web App connection is needed.
            services.AddCors(options => {
                options.AddPolicy(name: Exercise1WebOrigins, builder => {
                    builder
                    .AllowAnyHeader()
                    .WithOrigins(
                        securitySettings.AllowedCorsOrigins.ToArray()
                        )
                    .AllowAnyMethod();
                });
            });
            services.AddControllers();

            services.AddResponseCaching();

            // I set up two databaes for DEV and Staging, see appsetting.{env_name}.json
            // to get environment specific connection strings.
            var encConnStrVirbelaListing = Configuration.GetConnectionString("VirbelaListing(Azure)");
            var connStrVirbelaListing    = AesCryptoUtil.Decrypt(encConnStrVirbelaListing);

            services.AddDbContext <VirbelaListingContext>(builder =>
                                                          builder.UseSqlServer(connStrVirbelaListing)
                                                          );
            EnsureDatabaseExists <VirbelaListingContext>(connStrVirbelaListing);

            // UnitOfWork is injected and all repoistory injections are removed.
            services.AddScoped <IUnitOfWork, UnitOfWork>();

            // configure DI for application services
            services.AddScoped <IUserService, UserService>();
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            _identityConfig   = Config.GetIdentityResources();
            _apiConfig        = Config.GetApiResources(Configuration);
            _clientConfig     = Config.GetClients(Configuration);
            _publicOrigin     = Config.GetPublicOrigin(Configuration);
            _cookieExpiration = Config.GetCookieExpirationByMinute(Configuration);

            var encConnStrMySql = Configuration.GetConnectionString("MySqlConnection(Azure)");
            var connStrMySql    = AesCryptoUtil.Decrypt(encConnStrMySql);

            Log.Information($"Connection String: {connStrMySql}");

            services.AddDbContext <ApplicationDbContext>(option =>
                                                         option.UseMySQL(connStrMySql));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddCors(options =>
            {
                options.AddPolicy(EmpWebOrigins, corsBuilder =>
                {
                    corsBuilder
                    .AllowAnyHeader()
                    // .WithHeaders(HeaderNames.AccessControlAllowHeaders, "Content-Type")
                    // .AllowAnyOrigin()
                    .WithOrigins(
                        _clientConfig.First().AllowedCorsOrigins.ToArray()
                        )
                    .AllowAnyMethod()
                    // .WithMethods("GET", "PUT", "POST", "DELETE")
                    .AllowCredentials();
                });
            });

            services.AddMvc();
            services.AddTransient <IProfileService, CustomProfileService>();

            var builder = services.AddIdentityServer(options => {
                options.Events.RaiseErrorEvents               = true;
                options.Events.RaiseInformationEvents         = true;
                options.Events.RaiseFailureEvents             = true;
                options.Events.RaiseSuccessEvents             = true;
                options.Authentication.CheckSessionCookieName = "IDS4_EMP.Sts";
                options.PublicOrigin = _publicOrigin;
            })
                          .AddInMemoryIdentityResources(_identityConfig)
                          .AddInMemoryApiResources(_apiConfig)
                          .AddInMemoryClients(_clientConfig)
                          .AddAspNetIdentity <ApplicationUser>()
                          .AddProfileService <CustomProfileService>();

            services.ConfigureApplicationCookie(options => {
                // To prevent Refresh Access Token overriding cookie refreshe, subtract 1 minute
                options.ExpireTimeSpan      = TimeSpan.FromMinutes(_cookieExpiration - 1);
                options.SlidingExpiration   = true;
                options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
            });

            if (_env.IsDevelopment())
            {
                // builder.AddDeveloperSigningCredential();
                var rsa = new RsaKeyService(_env, TimeSpan.FromDays(30), Configuration);
                services.AddSingleton <RsaKeyService>(provider => rsa);
                builder.AddSigningCredential(rsa.GetKey());
            }
            else
            {
                var rsa = new RsaKeyService(_env, TimeSpan.FromDays(30), Configuration);
                services.AddSingleton <RsaKeyService>(provider => rsa);
                builder.AddSigningCredential(rsa.GetKey());

                // services.AddIdentityServer(...).AddSigningCredential(new X509Certificate2(bytes, "password")
                // builder.AddSigningCredential(new X509Certificate2(bytes, "password");
            }
        }
Ejemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            this.securitySettings = ApiConfig.GetSecuritySettings(Configuration);

            services.AddCors(options => {
                options.AddPolicy(name: EmpWebOrigins, builder => {
                    builder
                    .AllowAnyHeader()
                    // .WithHeaders(HeaderNames.AccessControlAllowHeaders, "Content-Type")
                    // .AllowAnyOrigin()
                    .WithOrigins(
                        securitySettings.AllowedCorsOrigins.ToArray()
                        )
                    .AllowAnyMethod();
                    // .WithMethods("GET", "PUT", "POST", "DELETE");
                });
            });

            services
            .AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options => {
                options.Authority            = securitySettings.StsAuthority;
                options.ApiName              = securitySettings.ApiName;
                options.RequireHttpsMetadata = false;
            });

            services.AddResponseCaching();
            services.AddMvc(options => {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            });

            services.AddControllers();

            // Make MySql Connection Service
            // TO DO: Create factory to return DB connection by ASYNC
            var encConnStrMySqlEmployees = Configuration.GetConnectionString("MySqlEmployees(Azure)");
            var connStrMySqlEmployees    = AesCryptoUtil.Decrypt(encConnStrMySqlEmployees);

            Log.Information($"Connection String: {connStrMySqlEmployees}");

            services.AddDbContext <EmployeesContext>(builder =>
                                                     builder.UseMySQL(connStrMySqlEmployees)
                                                     );
            EnsureDatabaseExists <EmployeesContext>(connStrMySqlEmployees);

            services.AddTransient <EmployeesDataSeeder>();

            var encConnStrMySqlSts = Configuration.GetConnectionString("MySqlSts(Azure)");
            var connStrMySqlSts    = AesCryptoUtil.Decrypt(encConnStrMySqlSts);

            services.AddDbContext <StsContext>(builder =>
                                               builder.UseMySQL(connStrMySqlSts)
                                               );
            EnsureDatabaseExists <StsContext>(connStrMySqlSts);

            services.AddScoped <IRepository <DeptManager>, DeptManagerRepository>();
            services.AddScoped <IRepository <VwDeptManagerDetail>, DeptManagerDetailRepository>();
            services.AddScoped <IRepository <Departments>, DepartmentsRepository>();
            services.AddScoped <IRepository <VwDeptEmpCurrent>, DeptEmpRepository>();
            services.AddScoped <IRepository <VwDeptManagerCurrent>, DeptManagerCurrentRepository>();
            services.AddScoped <IRepository <VwEmpDetails>, EmployeeDetailRepository>();
            services.AddScoped <IRepository <VwEmpDetailsShort>, EmployeeDetailShortRepository>();
            services.AddScoped <IRepository <Employees>, EmployeeRepository>();
            services.AddScoped <IRepository <VwTitlesCurrent>, TitleRepository>();
            services.AddScoped <IRepository <DistinctTitles>, DistinctTitleRepository>();
            services.AddScoped <IRepository <DistinctGenders>, DistinctGenderRepository>();
            services.AddScoped <IRepository <VwSalariesCurrent>, SalaryRepository>();
            services.AddScoped <IRepository <Aspnetusers>, AspnetUsersRepository>();
            services.AddScoped <IUnitOfWorkEmployees, UnitOfWorkEmployees>();
            services.AddScoped <IUnitOfWorkSts, UnitOfWorkSts>();
        }