コード例 #1
0
        private async Task <HttpResponseMessage> ExecuteActualRequest(HttpControllerContext controllerContext, CancellationToken cancellationToken,
                                                                      MixedModeRequestAuthorizer authorizer)
        {
            HttpResponseMessage authMsg;

            if (authorizer.TryAuthorize(this, out authMsg) == false)
            {
                return(authMsg);
            }

            if (IsInternalRequest == false)
            {
                RequestManager.IncrementRequestCount();
            }

            var fileSystemInternal = await FileSystemsLandlord.GetFileSystemInternal(FileSystemName);

            if (fileSystemInternal == null)
            {
                var msg = "Could not find a file system named: " + FileSystemName;
                return(GetMessageWithObject(new { Error = msg }, HttpStatusCode.ServiceUnavailable));
            }

            var sp = Stopwatch.StartNew();

            var result = await base.ExecuteAsync(controllerContext, cancellationToken);

            sp.Stop();
            AddRavenHeader(result, sp);

            return(result);
        }
コード例 #2
0
        private async Task <HttpResponseMessage> ExecuteActualRequest(HttpControllerContext controllerContext, CancellationToken cancellationToken,
                                                                      MixedModeRequestAuthorizer authorizer)
        {
            HttpResponseMessage authMsg;

            if (authorizer.TryAuthorize(this, out authMsg) == false)
            {
                return(authMsg);
            }

            var internalHeader = GetHeader("Raven-internal-request");

            if (internalHeader == null || internalHeader != "true")
            {
                RequestManager.IncrementRequestCount();
            }

            if (DatabaseName != null && await DatabasesLandlord.GetDatabaseInternal(DatabaseName) == null)
            {
                var msg = "Could not find a database named: " + DatabaseName;
                return(GetMessageWithObject(new { Error = msg }, HttpStatusCode.ServiceUnavailable));
            }

            var sp = Stopwatch.StartNew();

            var result = await base.ExecuteAsync(controllerContext, cancellationToken);

            sp.Stop();
            AddRavenHeader(result, sp);

            return(result);
        }
コード例 #3
0
ファイル: RavenDBOptions.cs プロジェクト: dkardach/ravendb
        public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            try
            {
                HttpEndpointRegistration.RegisterHttpEndpointTarget();
                if (db == null)
                {
                    systemDatabase = new DocumentDatabase(configuration);
                    systemDatabase.SpinBackgroundWorkers();
                }
                else
                {
                    systemDatabase = db;
                }
                fileSystemLandlord         = new FileSystemsLandlord(systemDatabase);
                databasesLandlord          = new DatabasesLandlord(systemDatabase);
                countersLandlord           = new CountersLandlord(systemDatabase);
                requestManager             = new RequestManager(databasesLandlord);
                mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer();
                mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration));
            }
            catch
            {
                if (systemDatabase != null)
                {
                    systemDatabase.Dispose();
                }
                throw;
            }
        }
コード例 #4
0
        private async Task <HttpResponseMessage> ExecuteActualRequest(HttpControllerContext controllerContext, CancellationToken cancellationToken,
                                                                      MixedModeRequestAuthorizer authorizer)
        {
            if (SkipAuthorizationSinceThisIsMultiGetRequestAlreadyAuthorized == false)
            {
                HttpResponseMessage authMsg;
                if (authorizer.TryAuthorize(this, out authMsg) == false)
                {
                    return(authMsg);
                }
            }

            if (IsInternalRequest == false)
            {
                RequestManager.IncrementRequestCount();
            }

            if (DatabaseName != null && await DatabasesLandlord.GetDatabaseInternal(DatabaseName) == null)
            {
                var msg = "Could not find a database named: " + DatabaseName;
                return(GetMessageWithObject(new { Error = msg }, HttpStatusCode.ServiceUnavailable));
            }

            var sp = Stopwatch.StartNew();

            controllerContext.RequestContext.Principal = CurrentOperationContext.User.Value;
            var result = await base.ExecuteAsync(controllerContext, cancellationToken);

            sp.Stop();
            AddRavenHeader(result, sp);

            return(result);
        }
コード例 #5
0
        public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            try
            {
                ThreadPool.SetMinThreads(configuration.MinThreadPoolWorkerThreads, configuration.MinThreadPoolCompletionThreads);
                HttpEndpointRegistration.RegisterHttpEndpointTarget();
                HttpEndpointRegistration.RegisterAdminLogsTarget();
                if (db == null)
                {
                    configuration.UpdateDataDirForLegacySystemDb();
                    systemDatabase = new DocumentDatabase(configuration, null);
                    systemDatabase.SpinBackgroundWorkers(false);
                }
                else
                {
                    systemDatabase = db;
                }

                WebSocketBufferPool.Initialize(configuration.WebSockets.InitialBufferPoolSize);
                fileSystemLandlord            = new FileSystemsLandlord(systemDatabase);
                databasesLandlord             = new DatabasesLandlord(systemDatabase);
                countersLandlord              = new CountersLandlord(systemDatabase);
                timeSeriesLandlord            = new TimeSeriesLandlord(systemDatabase);
                requestManager                = new RequestManager(databasesLandlord);
                systemDatabase.RequestManager = requestManager;
                ClusterManager                = new Reference <ClusterManager>();
                systemDatabase.ClusterManager = ClusterManager;
                mixedModeRequestAuthorizer    = new MixedModeRequestAuthorizer();
                mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration));

                serverStartupTasks = configuration.Container.GetExportedValues <IServerStartupTask>();

                foreach (var task in serverStartupTasks)
                {
                    toDispose.Add(task);
                    try
                    {
                        task.Execute(this);
                    }
                    catch (Exception e)
                    {
                        systemDatabase.LogErrorAndAddAlertOnStartupTaskException(task.GetType().FullName, e);
                    }
                }
            }
            catch (Exception)
            {
                if (systemDatabase != null)
                {
                    systemDatabase.Dispose();
                }
                throw;
            }
        }
コード例 #6
0
 public WebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix)
 {
     DatabasesLandlord          = databasesLandlord;
     this.countersLandlord      = countersLandlord;
     this.fileSystemsLandlord   = fileSystemsLandlord;
     this.authorizer            = authorizer;
     this.expectedRequestSuffix = expectedRequestSuffix;
 }
コード例 #7
0
        public RavenDBOptions(RavenConfiguration configuration, DocumentDatabase db = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            try
            {
                HttpEndpointRegistration.RegisterHttpEndpointTarget();
                HttpEndpointRegistration.RegisterAdminLogsTarget();
                if (db == null)
                {
                    systemDatabase = new DocumentDatabase(configuration, null);
                    systemDatabase.SpinBackgroundWorkers(false);
                }
                else
                {
                    systemDatabase = db;
                }

                WebSocketBufferPool.Initialize((int)configuration.WebSockets.InitialBufferPoolSize.GetValue(SizeUnit.Bytes));
                fileSystemLandlord            = new FileSystemsLandlord(systemDatabase);
                databasesLandlord             = new DatabasesLandlord(systemDatabase);
                countersLandlord              = new CountersLandlord(systemDatabase);
                timeSeriesLandlord            = new TimeSeriesLandlord(systemDatabase);
                requestManager                = new RequestManager(databasesLandlord);
                systemDatabase.RequestManager = requestManager;
                ClusterManager                = new Reference <ClusterManager>();
                mixedModeRequestAuthorizer    = new MixedModeRequestAuthorizer();
                mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration));

                serverStartupTasks = configuration.Container.GetExportedValues <IServerStartupTask>();

                foreach (var task in serverStartupTasks)
                {
                    toDispose.Add(task);
                    task.Execute(this);
                }
            }
            catch (Exception)
            {
                if (systemDatabase != null)
                {
                    systemDatabase.Dispose();
                }
                throw;
            }
        }
コード例 #8
0
 public AdminLogsWebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix)
     : base(databasesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix)
 {
 }
コード例 #9
0
 public WatchTrafficWebSocketsRequestParser(DatabasesLandlord databasesLandlord, TimeSeriesLandlord timeSeriesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix)
     : base(databasesLandlord, timeSeriesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix)
 {
 }
コード例 #10
0
ファイル: AbstractLandlord.cs プロジェクト: tryadiadi/ravendb
        public string[] GetUserAllowedResourcesByPrefix(IPrincipal user, DocumentDatabase systemDatabase, AnonymousUserAccessMode annonymouseUserAccessMode, MixedModeRequestAuthorizer mixedModeRequestAuthorizer, string authHeader)
        {
            List <string> approvedResources = null;
            var           nextPageStart     = 0;
            var           resources         = systemDatabase.Documents
                                              .GetDocumentsWithIdStartingWith(ResourcePrefix, null, null, 0,
                                                                              systemDatabase.Configuration.MaxPageSize, CancellationToken.None, ref nextPageStart);

            var reourcesNames = resources
                                .Select(database =>
                                        database.Value <RavenJObject>("@metadata").Value <string>("@id").Replace(ResourcePrefix, string.Empty)).ToArray();

            if (annonymouseUserAccessMode == AnonymousUserAccessMode.None)
            {
                if (user == null)
                {
                    return(null);
                }

                var  oneTimePrincipal = user as MixedModeRequestAuthorizer.OneTimetokenPrincipal;
                bool isAdministrator  = oneTimePrincipal != null ?
                                        oneTimePrincipal.IsAdministratorInAnonymouseMode :
                                        user.IsAdministrator(annonymouseUserAccessMode);

                if (isAdministrator == false)
                {
                    var authorizer = mixedModeRequestAuthorizer;
                    approvedResources = authorizer.GetApprovedResources(user, authHeader, reourcesNames);
                }
            }

            if (approvedResources != null)
            {
                reourcesNames = reourcesNames.Where(resourceName => approvedResources.Contains(resourceName)).ToArray();
            }

            return(reourcesNames);
        }
コード例 #11
0
ファイル: AbstractLandlord.cs プロジェクト: tryadiadi/ravendb
 public IEnumerable <TransportState> GetUserAllowedTransportStates(IPrincipal user, DocumentDatabase systemDatabase, AnonymousUserAccessMode annonymouseUserAccessMode, MixedModeRequestAuthorizer mixedModeRequestAuthorizer, string authHeader)
 {
     foreach (var resourceName in GetUserAllowedResourcesByPrefix(user, systemDatabase, annonymouseUserAccessMode, mixedModeRequestAuthorizer, authHeader))
     {
         TransportState curTransportState;
         if (ResourseTransportStates.TryGetValue(resourceName, out curTransportState))
         {
             yield return(curTransportState);
         }
     }
 }