private static Response RequiresAuthorization(NancyContext context, AbstractSystemPermissionsProvider permissionsProvider, SystemPermissions get, SystemPermissions post) { var permissionsRequired = SystemPermissions.None; switch (context.Request.Method.ToUpperInvariant()) { case "GET": case "HEAD": permissionsRequired = get; break; case "POST": permissionsRequired = post; break; } if (permissionsRequired == SystemPermissions.None) { return(HttpStatusCode.Unauthorized); } if (!permissionsProvider.HasPermissions(context.CurrentUser, permissionsRequired)) { return(HttpStatusCode.Unauthorized); } return(null); }
public static void RequiresBrightstarSystemPermission(this NancyModule module, AbstractSystemPermissionsProvider permissionsProvider, SystemPermissions get = SystemPermissions.None, SystemPermissions post = SystemPermissions.None) { module.Before.AddItemToEndOfPipeline(ctx => RequiresAuthorization(ctx, permissionsProvider, get, post)); }
/// <summary> /// Creates a new bootstrapper with store and system access goverened by the specified providers. /// </summary> /// <param name="brightstarService">The connection to the BrightstarDB stores</param> /// <param name="authenticationProviders">An enumeration of the authentication providers to be used by the service</param> /// <param name="storePermissionsProvider">The store permissions provider to be used by the service</param> /// <param name="systemPermissionsProvider">The system permissions provider to be used by the service</param> /// <param name="rootPath">The path to the directory containing the service Views and assets folder</param> /// <exception cref="ArgumentNullException">Raised if any of the arguments to the method other than <paramref name="rootPath"/> are Null.</exception> public BrightstarBootstrapper(IBrightstarService brightstarService, IEnumerable <IAuthenticationProvider> authenticationProviders, AbstractStorePermissionsProvider storePermissionsProvider, AbstractSystemPermissionsProvider systemPermissionsProvider, string rootPath = null) { if (brightstarService == null) { throw new ArgumentNullException("brightstarService"); } if (authenticationProviders == null) { throw new ArgumentNullException("authenticationProviders"); } if (storePermissionsProvider == null) { throw new ArgumentNullException("storePermissionsProvider"); } if (systemPermissionsProvider == null) { throw new ArgumentNullException("systemPermissionsProvider"); } _brightstarService = brightstarService; _authenticationProviders = authenticationProviders; _storePermissionsProvider = storePermissionsProvider; _systemPermissionsProvider = systemPermissionsProvider; _rootPathProvider = (rootPath == null ? new DefaultRootPathProvider() : new FixedRootPathProvider(rootPath) as IRootPathProvider); }
public FakeNancyBootstrapper(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider, AbstractSystemPermissionsProvider systemPermissionsProvider) { _brightstarService = brightstarService; _storePermissionsProvider = storePermissionsProvider; _systemPermissionsProvider = systemPermissionsProvider; }
/// <summary> /// Creates a new bootstrapper with store and system access goverened by the specified providers. /// </summary> /// <param name="brightstarService">The connection to the BrightstarDB stores</param> /// <param name="storePermissionsProvider">The store permissions provider to be used by the service</param> /// <param name="systemPermissionsProvider">The system permissions provider to be used by the service</param> /// <param name="rootPath">The path to the directory containing the service Views and assets folder</param> public BrightstarBootstrapper(IBrightstarService brightstarService, AbstractStorePermissionsProvider storePermissionsProvider, AbstractSystemPermissionsProvider systemPermissionsProvider, string rootPath = null) { _brightstarService = brightstarService; _storePermissionsProvider = storePermissionsProvider; _systemPermissionsProvider = systemPermissionsProvider; _rootPathProvider = (rootPath == null ? new DefaultRootPathProvider() : new FixedRootPathProvider(rootPath) as IRootPathProvider); //_rootPathProvider = new FixedRootPathProvider(rootPath); }
public StoresModule(IBrightstarService brightstarService, AbstractSystemPermissionsProvider systemPermissionsProvider) { this.RequiresBrightstarSystemPermission(systemPermissionsProvider, get: SystemPermissions.ListStores, post: SystemPermissions.CreateStore); Get["/"] = parameters => { ViewBag.Title = "Stores"; var stores = brightstarService.ListStores(); return (Negotiate.WithModel(new StoresResponseModel { Stores = stores.ToList() })); }; Post["/"] = parameters => { ViewBag.Title = "Stores"; var request = this.Bind <CreateStoreRequestObject>(); if (request == null || String.IsNullOrEmpty(request.StoreName)) { return(HttpStatusCode.BadRequest); } // Return 409 Conflict if attempt to create a store with a name that is currently in use if (brightstarService.DoesStoreExist(request.StoreName)) { return(HttpStatusCode.Conflict); } // Attempt to create the store try { PersistenceType?storePersistenceType = request.GetBrightstarPersistenceType(); if (storePersistenceType.HasValue) { brightstarService.CreateStore(request.StoreName, storePersistenceType.Value); } else { brightstarService.CreateStore(request.StoreName); } } catch (ArgumentException) { return(HttpStatusCode.BadRequest); } return (Negotiate.WithModel(new StoreResponseModel(request.StoreName)) .WithStatusCode(HttpStatusCode.Created)); }; }
public BrightstarBootstrapper() { var config = ConfigurationManager.GetSection("brightstarService") as BrightstarServiceConfiguration; if (config == null) { throw new ConfigurationErrorsException(Strings.NoServiceConfiguration); } _brightstarService = BrightstarService.GetClient(config.ConnectionString); _storePermissionsProvider = config.StorePermissionsProvider; _systemPermissionsProvider = config.SystemPermissionsProvider; }
/// <summary> /// Create a new bootstrapper that initializes itself from the brightstarService section /// of the application (or web) configuration file. /// </summary> /// <exception cref="ConfigurationErrorsException">Raised if the brightstarService configuration /// section does not exist in the application configuration file, or if the configuration is /// invalid.</exception> public BrightstarBootstrapper() { var config = ConfigurationManager.GetSection("brightstarService") as BrightstarServiceConfiguration; if (config == null) { throw new ConfigurationErrorsException(Strings.NoServiceConfiguration); } _brightstarService = BrightstarService.GetClient(config.ConnectionString); _storePermissionsProvider = config.StorePermissionsProvider ?? new FallbackStorePermissionsProvider(StorePermissions.All); _systemPermissionsProvider = config.SystemPermissionsProvider ?? new FallbackSystemPermissionsProvider(SystemPermissions.All); _authenticationProviders = config.AuthenticationProviders ?? new Collection <IAuthenticationProvider> { new NullAuthenticationProvider() }; }