Esempio n. 1
0
        public static void ConfigureAuthorization(this IServiceCollection services)
        {
            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<SecurityDbContext>()
                .AddDefaultTokenProviders();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("RequireClimePolicyTest", policy =>
                {
                    policy.RequireClaim("RequireClimePolicyTest");
                });

                options.AddPolicy("RequireRolePolicyTest", policy =>
                {
                    policy.RequireRole("RequireRolePolicyTest");
                });

                options.AddPolicy("RequirementBasedPolicyTest", policy =>
                {
                    policy.AddRequirements(new TestRequirement(preSatisfied: true));
                });
            });

            services.AddSingleton<IAuthorizationHandler, ResourceBasedAuthorizationHandler>();
            services.AddSingleton<IAuthorizationHandler, RequirementBasedAuthorizationHandler>();
        }
        public static IServiceCollection AddSmashLeagueData(
            this IServiceCollection services,
            Action<SmashLeagueDataOptions> setup)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (setup == null)
            {
                throw new ArgumentNullException(nameof(setup));
            }

            var dataOptions = new SmashLeagueDataOptions();
            setup(dataOptions);

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<SmashLeagueDbContext>(options =>
                {
                    options.UseSqlServer(dataOptions.ConnectionString);
                });

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

            services.AddTransient<ApplicationUserManager>();
            services.AddTransient<SmashLeagueDbInitializer>();

            return services;
        }
 public static IServiceCollection AddPanther(this IServiceCollection services)
 {
     services.AddIdentity<User, Role>()
         .AddDefaultTokenProviders();
     services.AddMvc();
     services.ConfigureMvc(options =>
     {
         options.Filters.Add(new SecurityFilterAttribute());
     });
     services.ConfigureRazorViewEngine(razor =>
     {
         razor.ViewLocationExpanders.Add(new ViewLocationExpanderDescriptor(typeof(PantherViewLocationExpander)));
     });
     PantherServices.GetDefaultServices(services);
     return services;
 }
        public static IServiceCollection AddApp(this IServiceCollection services)
        {
            services.AddOptions();
            services.TryAdd(ServiceDescriptor.Transient<IDistributedCache, LocalCache>());
            services.TryAdd(ServiceDescriptor.Singleton<IMemoryCache, MemoryCache>());

            services.AddSingleton<IApplicationSettings, ApplicationSettings>();

            services.AddTransient<IHttpPipelineBuilder, HttpPipelineBuilder>();
            services.AddTransient<ILoggerBuilder, LoggerBuilder>();

            services.AddSingleton<IEntityMapper, EntityMapper>();

            services.AddSingleton<IMapper>(x => x.GetService<IEntityMapper>().CreateMapper());

            services.AddTransient<IHttpPipelineDescriptor, EnvironmentPipelineDescriptor>();
            services.AddTransient<IHttpPipelineDescriptor, StaticFilePipelineDescriptor>();
            services.AddTransient<IHttpPipelineDescriptor, IdentityPipelineDescriptor>();

            services.AddIdentity<User, UserClaim, Role, RoleClaim, UserRole, Guid>();
            return services;
        }
        public static void AddFormsAuthentication(this IServiceCollection services)
        {
            services.AddAuthentication();

            services.AddIdentity<ApplicationUser, IdentityRole>(
               options =>
               {
                   options.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
                   options.Cookies.ApplicationCookie.AutomaticChallenge = true;
                   options.Cookies.ApplicationCookieAuthenticationScheme = "ApplicationCookie";
                   options.Cookies.ApplicationCookie.AuthenticationScheme = IdentityCookieOptions.ApplicationCookieAuthenticationType = "ApplicationCookie";
                   options.Cookies.ApplicationCookie.LoginPath = new PathString("/User/Login");
                   options.Cookies.ApplicationCookie.LogoutPath = new PathString("/User/Logout");
                   options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromMinutes(5);
                   options.Cookies.ApplicationCookie.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
                   options.Cookies.ApplicationCookie.SlidingExpiration = true;
                   options.Cookies.ApplicationCookie.CookieHttpOnly = true;
                   options.Cookies.ApplicationCookie.CookieSecure = CookieSecureOption.SameAsRequest;
                   options.Cookies.ApplicationCookie.SystemClock = new SystemClock();
                   options.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents();
                   options.Cookies.ApplicationCookie.CookieName = "TBMMNet";
                   options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10);
                   options.Lockout.MaxFailedAccessAttempts = 10;
                   options.Lockout.AllowedForNewUsers = false;
               })
               .AddUserStore<IdentityUserStore<ApplicationUser>>()
               .AddRoleStore<IdentityRoleStore<IdentityRole>>()
               .AddDefaultTokenProviders();
        }