Ejemplo n.º 1
0
 public TenantResolver(
     ITenantContextFactory tenantContextFactory,
     ITenantCodeResolver tenantCodeResolver)
 {
     _tenantCodeResolver = tenantCodeResolver;
     tenantContext       = tenantContextFactory.Get();
 }
        public void Configuration(IAppBuilder app)
        {
            log4net.Config.XmlConfigurator.Configure();
            ILog logger = LogManager.GetLogger("Logger");

            logger.Info("Application Started");
            logger.Info("Configuring DI container");
            IWindsorContainer container = new WindsorContainer();

            ServiceLocator.Set(container);
            BootstrapConfig.Register(container, logger);

            logger.Info("Configuring HTTP Middleware");
            app.MapSignalR();
            app.UseMultitenancy(new MultitenancyNotifications <TenantDto>
            {
                TenantIdentifierNotFound = context =>
                {
                    throw new HttpException(404, "Tenant identifier must be provided");
                },
                TenantRecordNotFound = context =>
                {
                    context.Response.Redirect("/signup/tenant/");
                    return(Task.FromResult(0));
                },
                CreateTenantContext = (context, tenantRecord) =>
                {
                    ITenantContextFactory tenantContextFactory = ServiceLocator.Resolve <ITenantContextFactory>();
                    TenantContext tenantContext = tenantContextFactory.Create(tenantRecord.Id, tenantRecord.NameFriendly, tenantRecord.AuthClientId, tenantRecord.AuthAuthority);
                    return(Task.FromResult(tenantContext));
                }
            });
            app.UsePerTenant((tenantContext, appBranch) =>
            {
                appBranch.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

                appBranch.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    CookieName = $"OAuthCookie.{tenantContext.FriendlyName}"
                });

                appBranch.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
                {
                    ClientId      = tenantContext.AuthClientId,
                    Authority     = tenantContext.AuthAuthority,
                    RedirectUri   = $"http://localhost:2295/{tenantContext.FriendlyName}/",
                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        AuthenticationFailed = context =>
                        {
                            context.HandleResponse();
                            throw context.Exception;
                        }
                    }
                });

                appBranch.Use <AuthenticationChallangeMiddleware>();
                appBranch.Use <AuthenticationAudienceCheckMiddleware>(tenantContext);
                appBranch.Use <AuthenticationClaimsAppenderMiddleware>();
            });

            logger.Info("Configuring MVC Pipeline");
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

            logger.Info("Configuring Domain, DTO and Model Mapping");
            MappingConfig.RegisterMapping();
            Mapper.AddProfile(new Web.Models.Map());

            app.OnDispose(() =>
            {
                ServiceLocator.Resolve <ILog>().Info("Application Ended");
                ServiceLocator.Release();
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates new instance of <see cref="SystemHost"/> using <see cref="ITenantContextFactory"/>.
 /// </summary>
 /// <param name="contextFactory">Instance of <see cref="ITenantContextFactory"/> for constructing tenants.</param>
 public SystemHost(ITenantContextFactory contextFactory)
 {
     _contextFactory = contextFactory;
     _tenantContexts = new ConcurrentDictionary<string, ITenantContext>();
 }