public static HttpConfiguration Configure(MultiTenantBlobStorageOptions options) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.SuppressDefaultHostAuthentication(); config.MessageHandlers.Insert(0, new KatanaDependencyResolver()); config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger()); //config.Formatters.Remove(config.Formatters.XmlFormatter); var jsonFormatter = new JsonMediaTypeFormatter(); jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); //optional: set serializer settings here config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter)); config.Services.Replace(typeof(IHttpControllerTypeResolver), new EndpointHttpControllerTypeResolver()); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; if (options.LoggingOptions.EnableWebApiDiagnostics) { var liblog = new TraceSource("LibLog"); liblog.Switch.Level = SourceLevels.All; liblog.Listeners.Add(new LibLogTraceListener()); var diag = config.EnableSystemDiagnosticsTracing(); diag.IsVerbose = options.LoggingOptions.WebApiDiagnosticsIsVerbose; diag.TraceSource = liblog; } if (options.LoggingOptions.EnableHttpLogging) { config.MessageHandlers.Add(new RequestResponseLogger()); } return(config); }
public DefaultRequestHandlerService(MultiTenantBlobStorageOptions options, IAuthenticationService authService) { Options = options; this._authService = authService; }
public static IAppBuilder UseMultiTenantBlobStorage(this IAppBuilder app, MultiTenantBlobStorageOptions options) { if (app == null) { throw new ArgumentNullException("app"); } if (options == null) { throw new ArgumentNullException("options"); } if (options.RequireSsl) { app.Use <RequireSslMiddleware>(); } app.ConfigureRequestId(); var container = app.UseUnityContainer(); var fact = options.Factory ?? new MultiTenantBlobStorageServiceFactory(); container.RegisterType <IDependencyResolver, UnityDependencyResolver>(new HierarchicalLifetimeManager(), new InjectionFactory((c) => new UnityDependencyResolver(c))); container.RegisterDefaultType <ITenantContainerNameService, DefaultTenantContainerNameService>(fact.TenantContainerNameService); container.RegisterDefaultType <IStorageAccountResolverService, DefaultStorageAccountResolverService>(fact.StorageAccountResolver); container.RegisterDefaultType <IResourceAuthorizationManager, DefaultResourceAuthorizationManager>(fact.AuthorizationManager); container.RegisterDefaultType <IAuthenticationService, DefaultAuthenticationService>(fact.AuthenticationService); container.RegisterDefaultType <IRequestTenantResolver, DefaultRequestTenantResolver>(fact.RequestTenantResolver); foreach (var registration in fact.Registrations) { container.Register(registration); } // container.RegisterType<IRequestTenantResolver, DefaultRequestTenantResolver>(); container.RegisterType <IRequestHandlerService, DefaultRequestHandlerService>(); container.RegisterType <ResourceContext>(new HierarchicalLifetimeManager()); app.UseResourceAuthorization(new ResourceAuthorizationMiddlewareOptions { ManagerProvider = (ctx) => ctx.ResolveDependency <IResourceAuthorizationManager>() }); container.RegisterInstance(options); app.Use(async(ctx, next) => { await next(); if (options.ContainerResourceName.IsPresent() && ctx.Response.ReasonPhrase.IsPresent()) { var idx = ctx.Response.ReasonPhrase.IndexOf("container"); if (idx > -1) { ctx.Response.ReasonPhrase = ctx.Response.ReasonPhrase.Substring(0, idx) + options.ContainerResourceName + ctx.Response.ReasonPhrase.Substring(idx + 9); } } }); app.Use <StorageMirrowMiddleware>(); // app.UseWebApi(WebApiConfig.Configure(options)); return(app); }
public DefaultStorageAccountResolverService(MultiTenantBlobStorageOptions options) { Options = options; }
public virtual async Task <ClaimsPrincipal> AuthenticateRequestAsync(IOwinRequest request, MultiTenantBlobStorageOptions options) { var result = await request.Context.Authentication.AuthenticateAsync(options.AuthenticationType); if (result == null) { return(null); } return(new ClaimsPrincipal(result.Identity)); }