예제 #1
0
        public static HttpConfiguration Configure(IdentityAdminOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("idAdminConfig");
            }

            var config = new HttpConfiguration();

            config.MessageHandlers.Insert(0, new KatanaDependencyResolver());

            config.MapHttpAttributeRoutes();
            if (!options.DisableUserInterface)
            {
                config.Routes.MapHttpRoute(Constants.RouteNames.Home,
                                           "",
                                           new { controller = "AdminPage", action = "Index" });
                config.Routes.MapHttpRoute(Constants.RouteNames.Logout,
                                           "logout",
                                           new { controller = "AdminPage", action = "Logout" });
            }

            config.SuppressDefaultHostAuthentication();
            if (!options.DisableSecurity)
            {
                config.Filters.Add(new HostAuthenticationAttribute(options.AdminSecurityConfiguration.BearerAuthenticationType));
                config.Filters.Add(new AuthorizeAttribute()
                {
                    Roles = options.AdminSecurityConfiguration.AdminRoleName
                });
            }


            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.Formatters.Remove(config.Formatters.FormUrlEncodedFormatter);
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();

            config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger());

            return(config);
        }
예제 #2
0
        public static IContainer Configure(IdentityAdminOptions config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            var builder = new ContainerBuilder();

            builder.RegisterInstance(config);
            builder.Register(config.Factory.IdentityAdminService);
            builder.Register(c => new OwinEnvironmentService(c.Resolve <IOwinContext>()));
            builder.RegisterApiControllers(typeof(AutofacConfig).Assembly);

            foreach (var registration in config.Factory.Registrations)
            {
                builder.Register(registration, registration.Name);
            }

            var container = builder.Build();

            return(container);
        }
        public static void UseIdentityAdmin(this IAppBuilder app, IdentityAdminOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (options == null)
            {
                throw new ArgumentNullException("config");
            }

            app.SetLoggerFactory(new LibLogLoggerFactory());

            Logger.Info("Starting IdentityAdmin configuration");

            options.Validate();

            app.Use(async(ctx, next) =>
            {
                if (!ctx.Request.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) &&
                    options.AdminSecurityConfiguration.RequireSsl)
                {
                    ctx.Response.Write("HTTPS required");
                }
                else
                {
                    await next();
                }
            });

            var container = AutofacConfig.Configure(options);

            app.Use <AutofacContainerMiddleware>(container);

            if (!options.DisableSecurity)
            {
                options.AdminSecurityConfiguration.Configure(app);
            }

            if (!options.DisableUserInterface)
            {
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(IdentityAdminAppBuilderExtensions).Assembly, "Sahra.MutualFund.IdentityAdmin.Core.Assets")
                });
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets/libs/fonts"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(IdentityAdminAppBuilderExtensions).Assembly, "Sahra.MutualFund.IdentityAdmin.Core.Assets.Content.fonts")
                });
                app.UseStageMarker(PipelineStage.MapHandler);
            }

            SignatureConversions.AddConversions(app);
            app.UseWebApi(WebApiConfig.Configure(options));
            app.UseStageMarker(PipelineStage.MapHandler);

            // clears out the OWIN logger factory so we don't recieve other hosting related logs
            app.Properties["server.LoggerFactory"] = null;
        }