protected void SetUpProvider() { _ioDispatcher = new IODispatcher(_bus, new PublishEnvelope(_bus)); _bus.Subscribe(_ioDispatcher.BackwardReader); _bus.Subscribe(_ioDispatcher.ForwardReader); _bus.Subscribe(_ioDispatcher.Writer); _bus.Subscribe(_ioDispatcher.StreamDeleter); _bus.Subscribe(_ioDispatcher); PasswordHashAlgorithm passwordHashAlgorithm = new StubPasswordHashAlgorithm(); _internalAuthenticationProvider = new InternalAuthenticationProvider(_ioDispatcher, passwordHashAlgorithm, 1000); _bus.Subscribe(_internalAuthenticationProvider); }
public InternalAuthenticationProvider GetActiveProvider() { InternalAuthenticationProvider provider = null; try { provider = (from i in this.Manager.GetIQ <InternalAuthenticationProvider>() where i.Deleted == BaseStatusDeleted.None select i).Skip(0).Take(1).ToList().FirstOrDefault(); } catch (Exception ex) { provider = null; } return(provider); }
protected void SetUpProvider() { _ioDispatcher = new IODispatcher(_bus, new PublishEnvelope(_bus)); _bus.Subscribe(_ioDispatcher.BackwardReader); _bus.Subscribe(_ioDispatcher.ForwardReader); _bus.Subscribe(_ioDispatcher.Writer); _bus.Subscribe(_ioDispatcher.StreamDeleter); _bus.Subscribe(_ioDispatcher.Awaker); _bus.Subscribe <IODispatcherDelayedMessage>(_ioDispatcher); _bus.Subscribe <ClientMessage.NotHandled>(_ioDispatcher); PasswordHashAlgorithm passwordHashAlgorithm = new StubPasswordHashAlgorithm(); _internalAuthenticationProvider = new InternalAuthenticationProvider(_bus, _ioDispatcher, passwordHashAlgorithm, 1000, false); _bus.Subscribe(_internalAuthenticationProvider); }
public InternalLoginInfo SetPassword(Person person, String newPassword, Boolean isOneTimePassword) { InternalLoginInfo userInfo = null; try { InternalAuthenticationProvider provider = (from p in Manager.GetIQ <InternalAuthenticationProvider>() where p.IsEnabled && p.Deleted == BaseStatusDeleted.None select p).Skip(0).Take(1).ToList().FirstOrDefault(); userInfo = (from i in this.Manager.GetIQ <InternalLoginInfo>() where i.Person == person && i.Deleted == BaseStatusDeleted.None select i).Skip(0).Take(1).ToList().FirstOrDefault(); Person setUser = Manager.GetPerson(UC.CurrentUserID); Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor(); if (userInfo == null || setUser == null) { throw new UnknownItemException(); } else { Manager.BeginTransaction(); userInfo.UpdateMetaInfo(setUser, UC.IpAddress, UC.ProxyIpAddress); userInfo.Password = helper.Encrypt(newPassword); userInfo.ResetType = (isOneTimePassword) ? EditType.oneTime : EditType.admin; if (provider != null && provider.ChangePasswordAfterDays > 0) { userInfo.PasswordExpiresOn = DateTime.Now.AddDays(provider.ChangePasswordAfterDays); } AddToHistory(userInfo); Manager.Commit(); } } catch (UnknownItemException uEx) { userInfo = null; throw uEx; } catch (Exception ex) { Manager.RollBack(); userInfo = null; } return(userInfo); }
public TcpConnectionManager(string connectionName, ITcpDispatcher dispatcher, IPublisher publisher, ITcpConnection openedConnection, IPublisher networkSendQueue, InternalAuthenticationProvider authProvider, TimeSpan heartbeatInterval, TimeSpan heartbeatTimeout, Action <TcpConnectionManager, SocketError> onConnectionClosed) { Ensure.NotNull(dispatcher, "dispatcher"); Ensure.NotNull(publisher, "publisher"); Ensure.NotNull(openedConnection, "openedConnnection"); Ensure.NotNull(networkSendQueue, "networkSendQueue"); Ensure.NotNull(authProvider, "authProvider"); ConnectionId = openedConnection.ConnectionId; ConnectionName = connectionName; _tcpEnvelope = new SendOverTcpEnvelope(this, networkSendQueue); _publisher = publisher; _dispatcher = dispatcher; _authProvider = authProvider; _framer = new LengthPrefixMessageFramer(); _framer.RegisterMessageArrivedCallback(OnMessageArrived); _weakThisEnvelope = new SendToWeakThisEnvelope(this); _heartbeatInterval = heartbeatInterval; _heartbeatTimeout = heartbeatTimeout; _connectionClosed = onConnectionClosed; RemoteEndPoint = openedConnection.RemoteEndPoint; _connection = openedConnection; _connection.ConnectionClosed += OnConnectionClosed; if (_connection.IsClosed) { OnConnectionClosed(_connection, SocketError.Success); return; } ScheduleHeartbeat(0); }
public IAuthenticationProvider BuildAuthenticationProvider(IPublisher mainQueue, ISubscriber mainBus, IPublisher workersQueue, InMemoryBus[] workerBusses) { var passwordHashAlgorithm = new Rfc2898PasswordHashAlgorithm(); var dispatcher = new IODispatcher(mainQueue, new PublishEnvelope(workersQueue, crossThread: true)); foreach (var bus in workerBusses) { bus.Subscribe(dispatcher.ForwardReader); bus.Subscribe(dispatcher.BackwardReader); bus.Subscribe(dispatcher.Writer); bus.Subscribe(dispatcher.StreamDeleter); bus.Subscribe(dispatcher.Awaker); bus.Subscribe(dispatcher); } // USER MANAGEMENT var ioDispatcher = new IODispatcher(mainQueue, new PublishEnvelope(mainQueue)); mainBus.Subscribe(ioDispatcher.BackwardReader); mainBus.Subscribe(ioDispatcher.ForwardReader); mainBus.Subscribe(ioDispatcher.Writer); mainBus.Subscribe(ioDispatcher.StreamDeleter); mainBus.Subscribe(ioDispatcher.Awaker); mainBus.Subscribe(ioDispatcher); var userManagement = new UserManagementService(mainQueue, ioDispatcher, passwordHashAlgorithm, skipInitializeStandardUsersCheck: false); mainBus.Subscribe<UserManagementMessage.Create>(userManagement); mainBus.Subscribe<UserManagementMessage.Update>(userManagement); mainBus.Subscribe<UserManagementMessage.Enable>(userManagement); mainBus.Subscribe<UserManagementMessage.Disable>(userManagement); mainBus.Subscribe<UserManagementMessage.Delete>(userManagement); mainBus.Subscribe<UserManagementMessage.ResetPassword>(userManagement); mainBus.Subscribe<UserManagementMessage.ChangePassword>(userManagement); mainBus.Subscribe<UserManagementMessage.Get>(userManagement); mainBus.Subscribe<UserManagementMessage.GetAll>(userManagement); mainBus.Subscribe<SystemMessage.BecomeMaster>(userManagement); var provider = new InternalAuthenticationProvider(dispatcher, passwordHashAlgorithm, ESConsts.CachedPrincipalCount); var passwordChangeNotificationReader = new PasswordChangeNotificationReader(mainQueue, dispatcher); mainBus.Subscribe<SystemMessage.SystemStart>(passwordChangeNotificationReader); mainBus.Subscribe<SystemMessage.BecomeShutdown>(passwordChangeNotificationReader); mainBus.Subscribe(provider); return provider; }
public SingleVNode(TFChunkDb db, SingleVNodeSettings vNodeSettings, bool dbVerifyHashes, int memTableEntryCount, params ISubsystem[] subsystems) { Ensure.NotNull(db, "db"); Ensure.NotNull(vNodeSettings, "vNodeSettings"); _settings = vNodeSettings; _mainBus = new InMemoryBus("MainBus"); _controller = new SingleVNodeController(_mainBus, _settings.ExternalHttpEndPoint, db, this); _mainQueue = new QueuedHandler(_controller, "MainQueue"); _controller.SetMainQueue(_mainQueue); _subsystems = subsystems; // MONITORING var monitoringInnerBus = new InMemoryBus("MonitoringInnerBus", watchSlowMsg: false); var monitoringRequestBus = new InMemoryBus("MonitoringRequestBus", watchSlowMsg: false); var monitoringQueue = new QueuedHandlerThreadPool(monitoringInnerBus, "MonitoringQueue", true, TimeSpan.FromMilliseconds(100)); var monitoring = new MonitoringService(monitoringQueue, monitoringRequestBus, _mainQueue, db.Config.WriterCheckpoint, db.Config.Path, vNodeSettings.StatsPeriod, _settings.ExternalHttpEndPoint, vNodeSettings.StatsStorage); _mainBus.Subscribe(monitoringQueue.WidenFrom<SystemMessage.SystemInit, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom<SystemMessage.StateChangeMessage, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom<SystemMessage.BecomeShuttingDown, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom<SystemMessage.BecomeShutdown, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom<ClientMessage.WriteEventsCompleted, Message>()); monitoringInnerBus.Subscribe<SystemMessage.SystemInit>(monitoring); monitoringInnerBus.Subscribe<SystemMessage.StateChangeMessage>(monitoring); monitoringInnerBus.Subscribe<SystemMessage.BecomeShuttingDown>(monitoring); monitoringInnerBus.Subscribe<SystemMessage.BecomeShutdown>(monitoring); monitoringInnerBus.Subscribe<ClientMessage.WriteEventsCompleted>(monitoring); monitoringInnerBus.Subscribe<MonitoringMessage.GetFreshStats>(monitoring); var truncPos = db.Config.TruncateCheckpoint.Read(); if (truncPos != -1) { Log.Info("Truncate checkpoint is present. Truncate: {0} (0x{0:X}), Writer: {1} (0x{1:X}), Chaser: {2} (0x{2:X}), Epoch: {3} (0x{3:X})", truncPos, db.Config.WriterCheckpoint.Read(), db.Config.ChaserCheckpoint.Read(), db.Config.EpochCheckpoint.Read()); var truncator = new TFChunkDbTruncator(db.Config); truncator.TruncateDb(truncPos); } db.Open(dbVerifyHashes); // STORAGE SUBSYSTEM var indexPath = Path.Combine(db.Config.Path, "index"); var readerPool = new ObjectPool<ITransactionFileReader>( "ReadIndex readers pool", ESConsts.PTableInitialReaderCount, ESConsts.PTableMaxReaderCount, () => new TFChunkReader(db, db.Config.WriterCheckpoint)); var tableIndex = new TableIndex(indexPath, () => new HashListMemTable(maxSize: memTableEntryCount * 2), () => new TFReaderLease(readerPool), maxSizeForMemory: memTableEntryCount, maxTablesPerLevel: 2, inMem: db.Config.InMemDb); var hasher = new XXHashUnsafe(); var readIndex = new ReadIndex(_mainQueue, readerPool, tableIndex, hasher, ESConsts.StreamInfoCacheCapacity, Application.IsDefined(Application.AdditionalCommitChecks), Application.IsDefined(Application.InfiniteMetastreams) ? int.MaxValue : 1); var writer = new TFChunkWriter(db); var epochManager = new EpochManager(ESConsts.CachedEpochCount, db.Config.EpochCheckpoint, writer, initialReaderCount: 1, maxReaderCount: 5, readerFactory: () => new TFChunkReader(db, db.Config.WriterCheckpoint)); epochManager.Init(); var storageWriter = new StorageWriterService(_mainQueue, _mainBus, _settings.MinFlushDelay, db, writer, readIndex.IndexWriter, epochManager); // subscribes internally monitoringRequestBus.Subscribe<MonitoringMessage.InternalStatsRequest>(storageWriter); var storageReader = new StorageReaderService(_mainQueue, _mainBus, readIndex, ESConsts.StorageReaderThreadCount, db.Config.WriterCheckpoint); _mainBus.Subscribe<SystemMessage.SystemInit>(storageReader); _mainBus.Subscribe<SystemMessage.BecomeShuttingDown>(storageReader); _mainBus.Subscribe<SystemMessage.BecomeShutdown>(storageReader); monitoringRequestBus.Subscribe<MonitoringMessage.InternalStatsRequest>(storageReader); var chaser = new TFChunkChaser(db, db.Config.WriterCheckpoint, db.Config.ChaserCheckpoint); var storageChaser = new StorageChaser(_mainQueue, db.Config.WriterCheckpoint, chaser, readIndex.IndexCommitter, epochManager); _mainBus.Subscribe<SystemMessage.SystemInit>(storageChaser); _mainBus.Subscribe<SystemMessage.SystemStart>(storageChaser); _mainBus.Subscribe<SystemMessage.BecomeShuttingDown>(storageChaser); var storageScavenger = new StorageScavenger(db, tableIndex, hasher, readIndex, Application.IsDefined(Application.AlwaysKeepScavenged), mergeChunks: false /*!Application.IsDefined(Application.DisableMergeChunks)*/); // ReSharper disable RedundantTypeArgumentsOfMethod _mainBus.Subscribe<ClientMessage.ScavengeDatabase>(storageScavenger); // ReSharper restore RedundantTypeArgumentsOfMethod // MISC WORKERS _workerBuses = Enumerable.Range(0, vNodeSettings.WorkerThreads).Select(queueNum => new InMemoryBus(string.Format("Worker #{0} Bus", queueNum + 1), watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(200))).ToArray(); _workersHandler = new MultiQueuedHandler( vNodeSettings.WorkerThreads, queueNum => new QueuedHandlerThreadPool(_workerBuses[queueNum], string.Format("Worker #{0}", queueNum + 1), groupName: "Workers", watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(200))); // AUTHENTICATION INFRASTRUCTURE var passwordHashAlgorithm = new Rfc2898PasswordHashAlgorithm(); var dispatcher = new IODispatcher(_mainQueue, new PublishEnvelope(_workersHandler, crossThread: true)); var internalAuthenticationProvider = new InternalAuthenticationProvider(dispatcher, passwordHashAlgorithm, ESConsts.CachedPrincipalCount); var passwordChangeNotificationReader = new PasswordChangeNotificationReader(_mainQueue, dispatcher); _mainBus.Subscribe<SystemMessage.SystemStart>(passwordChangeNotificationReader); _mainBus.Subscribe<SystemMessage.BecomeShutdown>(passwordChangeNotificationReader); _mainBus.Subscribe(internalAuthenticationProvider); SubscribeWorkers(bus => { bus.Subscribe(dispatcher.ForwardReader); bus.Subscribe(dispatcher.BackwardReader); bus.Subscribe(dispatcher.Writer); bus.Subscribe(dispatcher.StreamDeleter); bus.Subscribe(dispatcher); }); // TCP { var tcpService = new TcpService(_mainQueue, _settings.ExternalTcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Normal, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, null); _mainBus.Subscribe<SystemMessage.SystemInit>(tcpService); _mainBus.Subscribe<SystemMessage.SystemStart>(tcpService); _mainBus.Subscribe<SystemMessage.BecomeShuttingDown>(tcpService); } // SECURE TCP if (vNodeSettings.ExternalSecureTcpEndPoint != null) { var secureTcpService = new TcpService(_mainQueue, _settings.ExternalSecureTcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Secure, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, _settings.Certificate); _mainBus.Subscribe<SystemMessage.SystemInit>(secureTcpService); _mainBus.Subscribe<SystemMessage.SystemStart>(secureTcpService); _mainBus.Subscribe<SystemMessage.BecomeShuttingDown>(secureTcpService); } SubscribeWorkers(bus => { var tcpSendService = new TcpSendService(); // ReSharper disable RedundantTypeArgumentsOfMethod bus.Subscribe<TcpMessage.TcpSend>(tcpSendService); // ReSharper restore RedundantTypeArgumentsOfMethod }); // HTTP var httpAuthenticationProviders = new List<HttpAuthenticationProvider> { new BasicHttpAuthenticationProvider(internalAuthenticationProvider), }; if (_settings.EnableTrustedAuth) httpAuthenticationProviders.Add(new TrustedHttpAuthenticationProvider()); httpAuthenticationProviders.Add(new AnonymousHttpAuthenticationProvider()); var httpPipe = new HttpMessagePipe(); var httpSendService = new HttpSendService(httpPipe, forwardRequests: false); _mainBus.Subscribe<SystemMessage.StateChangeMessage>(httpSendService); _mainBus.Subscribe(new WideningHandler<HttpMessage.SendOverHttp, Message>(_workersHandler)); SubscribeWorkers(bus => { bus.Subscribe<HttpMessage.HttpSend>(httpSendService); bus.Subscribe<HttpMessage.HttpSendPart>(httpSendService); bus.Subscribe<HttpMessage.HttpBeginSend>(httpSendService); bus.Subscribe<HttpMessage.HttpEndSend>(httpSendService); bus.Subscribe<HttpMessage.SendOverHttp>(httpSendService); }); _httpService = new HttpService(ServiceAccessibility.Public, _mainQueue, new TrieUriRouter(), _workersHandler, vNodeSettings.HttpPrefixes); _httpService.SetupController(new AdminController(_mainQueue)); _httpService.SetupController(new PingController()); _httpService.SetupController(new StatController(monitoringQueue, _workersHandler)); _httpService.SetupController(new AtomController(httpSendService, _mainQueue, _workersHandler)); _httpService.SetupController(new GuidController(_mainQueue)); _httpService.SetupController(new UsersController(httpSendService, _mainQueue, _workersHandler)); _mainBus.Subscribe<SystemMessage.SystemInit>(_httpService); _mainBus.Subscribe<SystemMessage.BecomeShuttingDown>(_httpService); _mainBus.Subscribe<HttpMessage.PurgeTimedOutRequests>(_httpService); SubscribeWorkers(bus => { HttpService.CreateAndSubscribePipeline(bus, httpAuthenticationProviders.ToArray()); }); // REQUEST MANAGEMENT var requestManagement = new RequestManagementService(_mainQueue, 1, 1, vNodeSettings.PrepareTimeout, vNodeSettings.CommitTimeout); _mainBus.Subscribe<SystemMessage.SystemInit>(requestManagement); _mainBus.Subscribe<ClientMessage.WriteEvents>(requestManagement); _mainBus.Subscribe<ClientMessage.TransactionStart>(requestManagement); _mainBus.Subscribe<ClientMessage.TransactionWrite>(requestManagement); _mainBus.Subscribe<ClientMessage.TransactionCommit>(requestManagement); _mainBus.Subscribe<ClientMessage.DeleteStream>(requestManagement); _mainBus.Subscribe<StorageMessage.RequestCompleted>(requestManagement); _mainBus.Subscribe<StorageMessage.CheckStreamAccessCompleted>(requestManagement); _mainBus.Subscribe<StorageMessage.AlreadyCommitted>(requestManagement); _mainBus.Subscribe<StorageMessage.CommitAck>(requestManagement); _mainBus.Subscribe<StorageMessage.PrepareAck>(requestManagement); _mainBus.Subscribe<StorageMessage.WrongExpectedVersion>(requestManagement); _mainBus.Subscribe<StorageMessage.InvalidTransaction>(requestManagement); _mainBus.Subscribe<StorageMessage.StreamDeleted>(requestManagement); _mainBus.Subscribe<StorageMessage.RequestManagerTimerTick>(requestManagement); // SUBSCRIPTIONS var subscrBus = new InMemoryBus("SubscriptionsBus", true, TimeSpan.FromMilliseconds(50)); var subscrQueue = new QueuedHandlerThreadPool(subscrBus, "Subscriptions", false); _mainBus.Subscribe(subscrQueue.WidenFrom<SystemMessage.SystemStart, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom<SystemMessage.BecomeShuttingDown, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom<TcpMessage.ConnectionClosed, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom<ClientMessage.SubscribeToStream, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom<ClientMessage.UnsubscribeFromStream, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom<SubscriptionMessage.PollStream, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom<SubscriptionMessage.CheckPollTimeout, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom<StorageMessage.EventCommited, Message>()); var subscription = new SubscriptionsService(_mainQueue, subscrQueue, readIndex); subscrBus.Subscribe<SystemMessage.SystemStart>(subscription); subscrBus.Subscribe<SystemMessage.BecomeShuttingDown>(subscription); subscrBus.Subscribe<TcpMessage.ConnectionClosed>(subscription); subscrBus.Subscribe<ClientMessage.SubscribeToStream>(subscription); subscrBus.Subscribe<ClientMessage.UnsubscribeFromStream>(subscription); subscrBus.Subscribe<SubscriptionMessage.PollStream>(subscription); subscrBus.Subscribe<SubscriptionMessage.CheckPollTimeout>(subscription); subscrBus.Subscribe<StorageMessage.EventCommited>(subscription); // USER MANAGEMENT var ioDispatcher = new IODispatcher(_mainQueue, new PublishEnvelope(_mainQueue)); _mainBus.Subscribe(ioDispatcher.BackwardReader); _mainBus.Subscribe(ioDispatcher.ForwardReader); _mainBus.Subscribe(ioDispatcher.Writer); _mainBus.Subscribe(ioDispatcher.StreamDeleter); _mainBus.Subscribe(ioDispatcher); var userManagement = new UserManagementService( _mainQueue, ioDispatcher, passwordHashAlgorithm, vNodeSettings.SkipInitializeStandardUsersCheck); _mainBus.Subscribe<UserManagementMessage.Create>(userManagement); _mainBus.Subscribe<UserManagementMessage.Update>(userManagement); _mainBus.Subscribe<UserManagementMessage.Enable>(userManagement); _mainBus.Subscribe<UserManagementMessage.Disable>(userManagement); _mainBus.Subscribe<UserManagementMessage.Delete>(userManagement); _mainBus.Subscribe<UserManagementMessage.ResetPassword>(userManagement); _mainBus.Subscribe<UserManagementMessage.ChangePassword>(userManagement); _mainBus.Subscribe<UserManagementMessage.Get>(userManagement); _mainBus.Subscribe<UserManagementMessage.GetAll>(userManagement); _mainBus.Subscribe<SystemMessage.BecomeMaster>(userManagement); // TIMER _timeProvider = new RealTimeProvider(); _timerService = new TimerService(new ThreadBasedScheduler(_timeProvider)); _mainBus.Subscribe<SystemMessage.BecomeShutdown>(_timerService); _mainBus.Subscribe<TimerMessage.Schedule>(_timerService); _workersHandler.Start(); _mainQueue.Start(); monitoringQueue.Start(); subscrQueue.Start(); if (subsystems != null) foreach (var subsystem in subsystems) subsystem.Register(db, _mainQueue, _mainBus, _timerService, _timeProvider, httpSendService, new[]{_httpService}, _workersHandler); }
public SingleVNode(TFChunkDb db, SingleVNodeSettings vNodeSettings, bool dbVerifyHashes, int memTableEntryCount, params ISubsystem[] subsystems) { Ensure.NotNull(db, "db"); Ensure.NotNull(vNodeSettings, "vNodeSettings"); _settings = vNodeSettings; _mainBus = new InMemoryBus("MainBus"); _controller = new SingleVNodeController(_mainBus, _settings.ExternalHttpEndPoint, db, this); _mainQueue = new QueuedHandler(_controller, "MainQueue"); _controller.SetMainQueue(_mainQueue); _subsystems = subsystems; // MONITORING var monitoringInnerBus = new InMemoryBus("MonitoringInnerBus", watchSlowMsg: false); var monitoringRequestBus = new InMemoryBus("MonitoringRequestBus", watchSlowMsg: false); var monitoringQueue = new QueuedHandler(monitoringInnerBus, "MonitoringQueue", true, TimeSpan.FromMilliseconds(100)); var monitoring = new MonitoringService(monitoringQueue, monitoringRequestBus, _mainQueue, db.Config.WriterCheckpoint, db.Config.Path, vNodeSettings.StatsPeriod, _settings.ExternalHttpEndPoint, vNodeSettings.StatsStorage); _mainBus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.SystemInit, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.StateChangeMessage, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.BecomeShuttingDown, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom <ClientMessage.WriteEventsCompleted, Message>()); monitoringInnerBus.Subscribe <SystemMessage.SystemInit>(monitoring); monitoringInnerBus.Subscribe <SystemMessage.StateChangeMessage>(monitoring); monitoringInnerBus.Subscribe <SystemMessage.BecomeShuttingDown>(monitoring); monitoringInnerBus.Subscribe <ClientMessage.WriteEventsCompleted>(monitoring); monitoringInnerBus.Subscribe <MonitoringMessage.GetFreshStats>(monitoring); var truncPos = db.Config.TruncateCheckpoint.Read(); if (truncPos != -1) { Log.Info("Truncate checkpoint is present. Truncate: {0} (0x{0:X}), Writer: {1} (0x{1:X}), Chaser: {2} (0x{2:X}), Epoch: {3} (0x{3:X})", truncPos, db.Config.WriterCheckpoint.Read(), db.Config.ChaserCheckpoint.Read(), db.Config.EpochCheckpoint.Read()); var truncator = new TFChunkDbTruncator(db.Config); truncator.TruncateDb(truncPos); } db.Open(dbVerifyHashes); // STORAGE SUBSYSTEM var indexPath = Path.Combine(db.Config.Path, "index"); var tableIndex = new TableIndex(indexPath, () => new HashListMemTable(maxSize: memTableEntryCount * 2), maxSizeForMemory: memTableEntryCount, maxTablesPerLevel: 2); var readIndex = new ReadIndex(_mainQueue, ESConsts.PTableInitialReaderCount, ESConsts.PTableMaxReaderCount, () => new TFChunkReader(db, db.Config.WriterCheckpoint), tableIndex, new XXHashUnsafe(), new LRUCache <string, StreamCacheInfo>(ESConsts.StreamMetadataCacheCapacity), Application.IsDefined(Application.AdditionalCommitChecks), Application.IsDefined(Application.InfiniteMetastreams) ? int.MaxValue : 1); var writer = new TFChunkWriter(db); var epochManager = new EpochManager(ESConsts.CachedEpochCount, db.Config.EpochCheckpoint, writer, initialReaderCount: 1, maxReaderCount: 5, readerFactory: () => new TFChunkReader(db, db.Config.WriterCheckpoint)); epochManager.Init(); var storageWriter = new StorageWriterService(_mainQueue, _mainBus, _settings.MinFlushDelayMs, db, writer, readIndex, epochManager); // subscribes internally monitoringRequestBus.Subscribe <MonitoringMessage.InternalStatsRequest>(storageWriter); var storageReader = new StorageReaderService(_mainQueue, _mainBus, readIndex, ESConsts.StorageReaderThreadCount, db.Config.WriterCheckpoint); _mainBus.Subscribe <SystemMessage.SystemInit>(storageReader); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(storageReader); _mainBus.Subscribe <SystemMessage.BecomeShutdown>(storageReader); monitoringRequestBus.Subscribe <MonitoringMessage.InternalStatsRequest>(storageReader); var chaser = new TFChunkChaser(db, db.Config.WriterCheckpoint, db.Config.ChaserCheckpoint); var storageChaser = new StorageChaser(_mainQueue, db.Config.WriterCheckpoint, chaser, readIndex, epochManager); _mainBus.Subscribe <SystemMessage.SystemInit>(storageChaser); _mainBus.Subscribe <SystemMessage.SystemStart>(storageChaser); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(storageChaser); var storageScavenger = new StorageScavenger(db, readIndex, Application.IsDefined(Application.AlwaysKeepScavenged), mergeChunks: false /*!Application.IsDefined(Application.DisableMergeChunks)*/); // ReSharper disable RedundantTypeArgumentsOfMethod _mainBus.Subscribe <SystemMessage.ScavengeDatabase>(storageScavenger); // ReSharper restore RedundantTypeArgumentsOfMethod // MISC WORKERS _workerBuses = Enumerable.Range(0, vNodeSettings.WorkerThreads).Select(queueNum => new InMemoryBus(string.Format("Worker #{0} Bus", queueNum + 1), watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(200))).ToArray(); _workersHandler = new MultiQueuedHandler( vNodeSettings.WorkerThreads, queueNum => new QueuedHandlerThreadPool(_workerBuses[queueNum], string.Format("Worker #{0}", queueNum + 1), groupName: "Workers", watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(200))); // AUTHENTICATION INFRASTRUCTURE var passwordHashAlgorithm = new Rfc2898PasswordHashAlgorithm(); var dispatcher = new IODispatcher(_mainBus, new PublishEnvelope(_workersHandler, crossThread: true)); var internalAuthenticationProvider = new InternalAuthenticationProvider(dispatcher, passwordHashAlgorithm, ESConsts.CachedPrincipalCount); var passwordChangeNotificationReader = new PasswordChangeNotificationReader(_mainQueue, dispatcher); _mainBus.Subscribe <SystemMessage.SystemStart>(passwordChangeNotificationReader); _mainBus.Subscribe <SystemMessage.BecomeShutdown>(passwordChangeNotificationReader); _mainBus.Subscribe(internalAuthenticationProvider); SubscribeWorkers(bus => { bus.Subscribe(dispatcher.ForwardReader); bus.Subscribe(dispatcher.BackwardReader); bus.Subscribe(dispatcher.Writer); bus.Subscribe(dispatcher.StreamDeleter); bus.Subscribe(dispatcher); }); // TCP { var tcpService = new TcpService(_mainQueue, _settings.ExternalTcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Normal, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, null); _mainBus.Subscribe <SystemMessage.SystemInit>(tcpService); _mainBus.Subscribe <SystemMessage.SystemStart>(tcpService); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(tcpService); } // SECURE TCP if (vNodeSettings.ExternalSecureTcpEndPoint != null) { var secureTcpService = new TcpService(_mainQueue, _settings.ExternalSecureTcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Secure, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, _settings.Certificate); _mainBus.Subscribe <SystemMessage.SystemInit>(secureTcpService); _mainBus.Subscribe <SystemMessage.SystemStart>(secureTcpService); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(secureTcpService); } SubscribeWorkers(bus => { var tcpSendService = new TcpSendService(); // ReSharper disable RedundantTypeArgumentsOfMethod bus.Subscribe <TcpMessage.TcpSend>(tcpSendService); // ReSharper restore RedundantTypeArgumentsOfMethod }); // HTTP var authenticationProviders = new List <AuthenticationProvider> { new BasicHttpAuthenticationProvider(internalAuthenticationProvider), }; if (_settings.EnableTrustedAuth) { authenticationProviders.Add(new TrustedAuthenticationProvider()); } authenticationProviders.Add(new AnonymousAuthenticationProvider()); var httpPipe = new HttpMessagePipe(); var httpSendService = new HttpSendService(httpPipe, forwardRequests: false); _mainBus.Subscribe <SystemMessage.StateChangeMessage>(httpSendService); _mainBus.Subscribe(new WideningHandler <HttpMessage.SendOverHttp, Message>(_workersHandler)); SubscribeWorkers(bus => { bus.Subscribe <HttpMessage.HttpSend>(httpSendService); bus.Subscribe <HttpMessage.HttpSendPart>(httpSendService); bus.Subscribe <HttpMessage.HttpBeginSend>(httpSendService); bus.Subscribe <HttpMessage.HttpEndSend>(httpSendService); bus.Subscribe <HttpMessage.SendOverHttp>(httpSendService); }); _httpService = new HttpService(ServiceAccessibility.Public, _mainQueue, new TrieUriRouter(), _workersHandler, vNodeSettings.HttpPrefixes); _httpService.SetupController(new AdminController(_mainQueue)); _httpService.SetupController(new PingController()); _httpService.SetupController(new StatController(monitoringQueue, _workersHandler)); _httpService.SetupController(new AtomController(httpSendService, _mainQueue, _workersHandler)); _httpService.SetupController(new GuidController(_mainQueue)); _httpService.SetupController(new UsersController(httpSendService, _mainQueue, _workersHandler)); _mainBus.Subscribe <SystemMessage.SystemInit>(_httpService); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(_httpService); _mainBus.Subscribe <HttpMessage.PurgeTimedOutRequests>(_httpService); SubscribeWorkers(bus => { HttpService.CreateAndSubscribePipeline(bus, authenticationProviders.ToArray()); }); // REQUEST MANAGEMENT var requestManagement = new RequestManagementService(_mainQueue, 1, 1, vNodeSettings.PrepareTimeout, vNodeSettings.CommitTimeout); _mainBus.Subscribe <SystemMessage.SystemInit>(requestManagement); _mainBus.Subscribe <ClientMessage.WriteEvents>(requestManagement); _mainBus.Subscribe <ClientMessage.TransactionStart>(requestManagement); _mainBus.Subscribe <ClientMessage.TransactionWrite>(requestManagement); _mainBus.Subscribe <ClientMessage.TransactionCommit>(requestManagement); _mainBus.Subscribe <ClientMessage.DeleteStream>(requestManagement); _mainBus.Subscribe <StorageMessage.RequestCompleted>(requestManagement); _mainBus.Subscribe <StorageMessage.CheckStreamAccessCompleted>(requestManagement); _mainBus.Subscribe <StorageMessage.AlreadyCommitted>(requestManagement); _mainBus.Subscribe <StorageMessage.CommitAck>(requestManagement); _mainBus.Subscribe <StorageMessage.PrepareAck>(requestManagement); _mainBus.Subscribe <StorageMessage.WrongExpectedVersion>(requestManagement); _mainBus.Subscribe <StorageMessage.InvalidTransaction>(requestManagement); _mainBus.Subscribe <StorageMessage.StreamDeleted>(requestManagement); _mainBus.Subscribe <StorageMessage.RequestManagerTimerTick>(requestManagement); // SUBSCRIPTIONS var subscrBus = new InMemoryBus("SubscriptionsBus", true, TimeSpan.FromMilliseconds(50)); var subscription = new SubscriptionsService(readIndex); subscrBus.Subscribe <TcpMessage.ConnectionClosed>(subscription); subscrBus.Subscribe <ClientMessage.SubscribeToStream>(subscription); subscrBus.Subscribe <ClientMessage.UnsubscribeFromStream>(subscription); subscrBus.Subscribe <StorageMessage.EventCommited>(subscription); var subscrQueue = new QueuedHandlerThreadPool(subscrBus, "Subscriptions", false); _mainBus.Subscribe(subscrQueue.WidenFrom <TcpMessage.ConnectionClosed, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom <ClientMessage.SubscribeToStream, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom <ClientMessage.UnsubscribeFromStream, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom <StorageMessage.EventCommited, Message>()); // USER MANAGEMENT var ioDispatcher = new IODispatcher(_mainBus, new PublishEnvelope(_mainQueue)); _mainBus.Subscribe(ioDispatcher.BackwardReader); _mainBus.Subscribe(ioDispatcher.ForwardReader); _mainBus.Subscribe(ioDispatcher.Writer); _mainBus.Subscribe(ioDispatcher.StreamDeleter); _mainBus.Subscribe(ioDispatcher); var userManagement = new UserManagementService( _mainQueue, ioDispatcher, passwordHashAlgorithm, vNodeSettings.SkipInitializeStandardUsersCheck); _mainBus.Subscribe <UserManagementMessage.Create>(userManagement); _mainBus.Subscribe <UserManagementMessage.Update>(userManagement); _mainBus.Subscribe <UserManagementMessage.Enable>(userManagement); _mainBus.Subscribe <UserManagementMessage.Disable>(userManagement); _mainBus.Subscribe <UserManagementMessage.Delete>(userManagement); _mainBus.Subscribe <UserManagementMessage.ResetPassword>(userManagement); _mainBus.Subscribe <UserManagementMessage.ChangePassword>(userManagement); _mainBus.Subscribe <UserManagementMessage.Get>(userManagement); _mainBus.Subscribe <UserManagementMessage.GetAll>(userManagement); _mainBus.Subscribe <SystemMessage.BecomeMaster>(userManagement); // TIMER _timeProvider = new RealTimeProvider(); _timerService = new TimerService(new ThreadBasedScheduler(_timeProvider)); // ReSharper disable RedundantTypeArgumentsOfMethod _mainBus.Subscribe <TimerMessage.Schedule>(_timerService); // ReSharper restore RedundantTypeArgumentsOfMethod _workersHandler.Start(); _mainQueue.Start(); monitoringQueue.Start(); subscrQueue.Start(); if (subsystems != null) { foreach (var subsystem in subsystems) { subsystem.Register(db, _mainQueue, _mainBus, _timerService, _timeProvider, httpSendService, new[] { _httpService }, _workersHandler); } } }
public PlaygroundVNode(PlaygroundVNodeSettings vNodeSettings) { _tcpEndPoint = vNodeSettings.ExternalTcpEndPoint; _httpEndPoint = vNodeSettings.ExternalHttpEndPoint; _mainBus = new InMemoryBus("MainBus"); _controller = new PlaygroundVNodeController(Bus, _httpEndPoint); _mainQueue = new QueuedHandler(_controller, "MainQueue"); _controller.SetMainQueue(MainQueue); // MONITORING var monitoringInnerBus = new InMemoryBus("MonitoringInnerBus", watchSlowMsg: false); var monitoringQueue = new QueuedHandler( monitoringInnerBus, "MonitoringQueue", true, TimeSpan.FromMilliseconds(100)); Bus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.SystemInit, Message>()); Bus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.StateChangeMessage, Message>()); Bus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.BecomeShuttingDown, Message>()); // MISC WORKERS _workerBuses = Enumerable.Range(0, vNodeSettings.WorkerThreads).Select(queueNum => new InMemoryBus(string.Format("Worker #{0} Bus", queueNum + 1), watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(50))).ToArray(); _workersHandler = new MultiQueuedHandler( vNodeSettings.WorkerThreads, queueNum => new QueuedHandlerThreadPool(_workerBuses[queueNum], string.Format("Worker #{0}", queueNum + 1), groupName: "Workers", watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(50))); // AUTHENTICATION INFRASTRUCTURE var dispatcher = new IODispatcher(_mainBus, new PublishEnvelope(_workersHandler, crossThread: true)); var passwordHashAlgorithm = new Rfc2898PasswordHashAlgorithm(); var internalAuthenticationProvider = new InternalAuthenticationProvider(dispatcher, passwordHashAlgorithm, 1000); var passwordChangeNotificationReader = new PasswordChangeNotificationReader(_mainQueue, dispatcher); _mainBus.Subscribe <SystemMessage.SystemStart>(passwordChangeNotificationReader); _mainBus.Subscribe <SystemMessage.BecomeShutdown>(passwordChangeNotificationReader); _mainBus.Subscribe(internalAuthenticationProvider); _mainBus.Subscribe(dispatcher); SubscribeWorkers(bus => { bus.Subscribe(dispatcher.ForwardReader); bus.Subscribe(dispatcher.BackwardReader); bus.Subscribe(dispatcher.Writer); bus.Subscribe(dispatcher.StreamDeleter); }); // TCP var tcpService = new TcpService( MainQueue, _tcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Normal, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, null); Bus.Subscribe <SystemMessage.SystemInit>(tcpService); Bus.Subscribe <SystemMessage.SystemStart>(tcpService); Bus.Subscribe <SystemMessage.BecomeShuttingDown>(tcpService); // HTTP { var authenticationProviders = new AuthenticationProvider[] { new BasicHttpAuthenticationProvider(internalAuthenticationProvider), new TrustedAuthenticationProvider(), new AnonymousAuthenticationProvider() }; var httpPipe = new HttpMessagePipe(); var httpSendService = new HttpSendService(httpPipe, forwardRequests: false); _mainBus.Subscribe <SystemMessage.StateChangeMessage>(httpSendService); _mainBus.Subscribe(new WideningHandler <HttpMessage.SendOverHttp, Message>(_workersHandler)); SubscribeWorkers(bus => { bus.Subscribe <HttpMessage.HttpSend>(httpSendService); bus.Subscribe <HttpMessage.HttpSendPart>(httpSendService); bus.Subscribe <HttpMessage.HttpBeginSend>(httpSendService); bus.Subscribe <HttpMessage.HttpEndSend>(httpSendService); bus.Subscribe <HttpMessage.SendOverHttp>(httpSendService); }); _httpService = new HttpService(ServiceAccessibility.Private, _mainQueue, new TrieUriRouter(), _workersHandler, vNodeSettings.HttpPrefixes); _mainBus.Subscribe <SystemMessage.SystemInit>(_httpService); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(_httpService); _mainBus.Subscribe <HttpMessage.PurgeTimedOutRequests>(_httpService); HttpService.SetupController(new AdminController(_mainQueue)); HttpService.SetupController(new PingController()); HttpService.SetupController(new StatController(monitoringQueue, _workersHandler)); HttpService.SetupController(new AtomController(httpSendService, _mainQueue, _workersHandler)); HttpService.SetupController(new GuidController(_mainQueue)); HttpService.SetupController(new UsersController(httpSendService, _mainQueue, _workersHandler)); SubscribeWorkers(bus => HttpService.CreateAndSubscribePipeline(bus, authenticationProviders)); } // TIMER _timerService = new TimerService(new ThreadBasedScheduler(new RealTimeProvider())); Bus.Subscribe(TimerService); monitoringQueue.Start(); MainQueue.Start(); }
public PlaygroundVNode(PlaygroundVNodeSettings vNodeSettings) { _tcpEndPoint = vNodeSettings.ExternalTcpEndPoint; _httpEndPoint = vNodeSettings.ExternalHttpEndPoint; _mainBus = new InMemoryBus("MainBus"); _controller = new PlaygroundVNodeController(Bus, _httpEndPoint); _mainQueue = new QueuedHandler(_controller, "MainQueue"); _controller.SetMainQueue(MainQueue); // MONITORING var monitoringInnerBus = new InMemoryBus("MonitoringInnerBus", watchSlowMsg: false); var monitoringQueue = new QueuedHandler( monitoringInnerBus, "MonitoringQueue", true, TimeSpan.FromMilliseconds(100)); Bus.Subscribe(monitoringQueue.WidenFrom<SystemMessage.SystemInit, Message>()); Bus.Subscribe(monitoringQueue.WidenFrom<SystemMessage.StateChangeMessage, Message>()); Bus.Subscribe(monitoringQueue.WidenFrom<SystemMessage.BecomeShuttingDown, Message>()); // MISC WORKERS _workerBuses = Enumerable.Range(0, vNodeSettings.WorkerThreads).Select(queueNum => new InMemoryBus(string.Format("Worker #{0} Bus", queueNum + 1), watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(50))).ToArray(); _workersHandler = new MultiQueuedHandler( vNodeSettings.WorkerThreads, queueNum => new QueuedHandlerThreadPool(_workerBuses[queueNum], string.Format("Worker #{0}", queueNum + 1), groupName: "Workers", watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(50))); // AUTHENTICATION INFRASTRUCTURE var dispatcher = new IODispatcher(_mainBus, new PublishEnvelope(_workersHandler, crossThread: true)); var passwordHashAlgorithm = new Rfc2898PasswordHashAlgorithm(); var internalAuthenticationProvider = new InternalAuthenticationProvider(dispatcher, passwordHashAlgorithm, 1000); var passwordChangeNotificationReader = new PasswordChangeNotificationReader(_mainQueue, dispatcher); _mainBus.Subscribe<SystemMessage.SystemStart>(passwordChangeNotificationReader); _mainBus.Subscribe<SystemMessage.BecomeShutdown>(passwordChangeNotificationReader); _mainBus.Subscribe(internalAuthenticationProvider); _mainBus.Subscribe(dispatcher); SubscribeWorkers(bus => { bus.Subscribe(dispatcher.ForwardReader); bus.Subscribe(dispatcher.BackwardReader); bus.Subscribe(dispatcher.Writer); bus.Subscribe(dispatcher.StreamDeleter); }); // TCP var tcpService = new TcpService( MainQueue, _tcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Normal, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, null); Bus.Subscribe<SystemMessage.SystemInit>(tcpService); Bus.Subscribe<SystemMessage.SystemStart>(tcpService); Bus.Subscribe<SystemMessage.BecomeShuttingDown>(tcpService); // HTTP { var httpAuthenticationProviders = new HttpAuthenticationProvider[] { new BasicHttpAuthenticationProvider(internalAuthenticationProvider), new TrustedHttpAuthenticationProvider(), new AnonymousHttpAuthenticationProvider() }; var httpPipe = new HttpMessagePipe(); var httpSendService = new HttpSendService(httpPipe, forwardRequests: false); _mainBus.Subscribe<SystemMessage.StateChangeMessage>(httpSendService); _mainBus.Subscribe(new WideningHandler<HttpMessage.SendOverHttp, Message>(_workersHandler)); SubscribeWorkers(bus => { bus.Subscribe<HttpMessage.HttpSend>(httpSendService); bus.Subscribe<HttpMessage.HttpSendPart>(httpSendService); bus.Subscribe<HttpMessage.HttpBeginSend>(httpSendService); bus.Subscribe<HttpMessage.HttpEndSend>(httpSendService); bus.Subscribe<HttpMessage.SendOverHttp>(httpSendService); }); _httpService = new HttpService(ServiceAccessibility.Private, _mainQueue, new TrieUriRouter(), _workersHandler, vNodeSettings.HttpPrefixes); _mainBus.Subscribe<SystemMessage.SystemInit>(_httpService); _mainBus.Subscribe<SystemMessage.BecomeShuttingDown>(_httpService); _mainBus.Subscribe<HttpMessage.PurgeTimedOutRequests>(_httpService); HttpService.SetupController(new AdminController(_mainQueue)); HttpService.SetupController(new PingController()); HttpService.SetupController(new StatController(monitoringQueue, _workersHandler)); HttpService.SetupController(new AtomController(httpSendService, _mainQueue, _workersHandler)); HttpService.SetupController(new GuidController(_mainQueue)); HttpService.SetupController(new UsersController(httpSendService, _mainQueue, _workersHandler)); SubscribeWorkers(bus => HttpService.CreateAndSubscribePipeline(bus, httpAuthenticationProviders)); } // TIMER _timerService = new TimerService(new ThreadBasedScheduler(new RealTimeProvider())); Bus.Subscribe<TimerMessage.Schedule>(TimerService); monitoringQueue.Start(); MainQueue.Start(); }
public BasicHttpAuthenticationProvider(InternalAuthenticationProvider internalAuthenticationProvider) { _internalAuthenticationProvider = internalAuthenticationProvider; }
public InternalLoginInfo GenerateUserInfo(Person person, String login, String password, InternalAuthenticationProvider provider, Boolean oneTimePassword) { InternalLoginInfo userInfo = null; try { Person currentUser = Manager.GetPerson(UC.CurrentUserID); if (currentUser == null) { currentUser = person; } if (provider != null && person != null) { Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor(); Manager.BeginTransaction(); if (!(from l in Manager.GetIQ <InternalLoginInfo>() where l.Person == person && l.Deleted == BaseStatusDeleted.None && l.Provider == provider select l.Id).Any()) { userInfo = new InternalLoginInfo(); userInfo.CreateMetaInfo(currentUser, UC.IpAddress, UC.ProxyIpAddress); userInfo.PasswordExpiresOn = (provider == null || provider.ChangePasswordAfterDays == 0) ? DateTime.MaxValue : DateTime.Now.AddDays(provider.ChangePasswordAfterDays); userInfo.Deleted = BaseStatusDeleted.None; userInfo.isEnabled = true; userInfo.Provider = provider; userInfo.Login = login; userInfo.Password = helper.Encrypt(password); userInfo.Person = person; userInfo.ResetType = (oneTimePassword) ? EditType.oneTime : EditType.admin; if (person.IdDefaultProvider == 0 || String.IsNullOrEmpty(person.FirstLetter)) { if (person.IdDefaultProvider == 0) { person.IdDefaultProvider = provider.Id; } if (String.IsNullOrEmpty(person.FirstLetter)) { person.FirstLetter = person.Surname[0].ToString().ToLower(); } Manager.SaveOrUpdate(person); } Manager.SaveOrUpdate(userInfo); AddToHistory(userInfo); } else { userInfo = (from l in Manager.GetIQ <InternalLoginInfo>() where l.Person == person && l.Deleted == BaseStatusDeleted.None && l.Provider == provider select l).Skip(0).Take(1).ToList().FirstOrDefault(); } Manager.Commit(); } } catch (Exception ex) { Manager.RollBack(); userInfo = null; } return(userInfo); }
public InternalLoginInfo AddUserInfo(String login, String password, int idPerson, DateTime passwordExpiresOn, InternalAuthenticationProvider provider) { InternalLoginInfo userInfo = null; try { Person currentUser = Manager.GetPerson(UC.CurrentUserID); Person creator = Manager.GetPerson(idPerson); if (currentUser == null) { currentUser = creator; } if (provider != null && creator != null) { Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor(); Manager.BeginTransaction(); userInfo = new InternalLoginInfo(); userInfo.CreateMetaInfo(currentUser, UC.IpAddress, UC.ProxyIpAddress); userInfo.PasswordExpiresOn = passwordExpiresOn; userInfo.Deleted = BaseStatusDeleted.None; userInfo.isEnabled = true; userInfo.Provider = provider; userInfo.Login = login; userInfo.Password = helper.Encrypt(password); userInfo.Person = creator; if (creator.IdDefaultProvider == 0 || String.IsNullOrEmpty(creator.FirstLetter)) { //// TEMPORANEO //creator.Login = login; //creator.Password=userInfo.Password; //// TEMPORANEO if (creator.IdDefaultProvider == 0) { creator.IdDefaultProvider = provider.Id; } if (String.IsNullOrEmpty(creator.FirstLetter)) { creator.FirstLetter = creator.Surname[0].ToString().ToLower(); } Manager.SaveOrUpdate(creator); } Manager.SaveOrUpdate(userInfo); AddToHistory(userInfo); Manager.Commit(); } } catch (Exception ex) { Manager.RollBack(); userInfo = null; } return(userInfo); }
public InternalLoginInfo AddUserInfo(String login, String password, int idPerson) { InternalAuthenticationProvider provider = (from p in Manager.GetIQ <InternalAuthenticationProvider>() where p.Deleted == BaseStatusDeleted.None select p).Skip(0).Take(1).ToList().FirstOrDefault(); return(AddUserInfo(login, password, idPerson, (provider == null || provider.ChangePasswordAfterDays == 0) ? DateTime.MaxValue : DateTime.Now.AddDays(provider.ChangePasswordAfterDays), provider)); }
//public Boolean EditPassword(String login, String oldPassword, String newPassword) //{ // Boolean result = false; // try // { // Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor(); // InternalLoginInfo info = (from i in this.Manager.GetIQ<InternalLoginInfo>() // where i.Login == login && i.Password == helper.Encrypt(oldPassword) // select i).Skip(0).Take(1).ToList().FirstOrDefault(); // if (info != null) { // Manager.BeginTransaction(); // info.Password = helper.Encrypt(newPassword); // info.UpdateMetaInfo(Manager.GetPerson(UC.CurrentUserID), UC.IpAddress, UC.ProxyIpAddress); // Manager.SaveOrUpdate(info); // result = true; // } // } // catch (Exception ex) // { // Manager.RollBack(); // } // return result; //} public Boolean EditPassword(Person person, String oldPassword, String newPassword, Boolean mustEdit) { Boolean edited = false; try { InternalAuthenticationProvider provider = (from p in Manager.GetIQ <InternalAuthenticationProvider>() where p.IsEnabled && p.Deleted == BaseStatusDeleted.None select p).Skip(0).Take(1).ToList().FirstOrDefault(); InternalLoginInfo info = (from i in this.Manager.GetIQ <InternalLoginInfo>() where i.Person == person && i.Deleted == BaseStatusDeleted.None select i).Skip(0).Take(1).ToList().FirstOrDefault(); Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor(); if (info == null) { throw new UnknownItemException(); } else if (info.Password != helper.Encrypt(oldPassword)) { throw new InvalidPasswordException(); } else if (mustEdit && info.Password == helper.Encrypt(newPassword)) { throw new SamePasswordException(); } else { Manager.BeginTransaction(); info.UpdateMetaInfo(Manager.GetPerson((mustEdit) ? person.Id : UC.CurrentUserID), UC.IpAddress, UC.ProxyIpAddress); info.Password = helper.Encrypt(newPassword); info.ResetType = (info.ModifiedBy == person || mustEdit) ? EditType.user : EditType.admin; if (provider != null && provider.ChangePasswordAfterDays > 0) { info.PasswordExpiresOn = DateTime.Now.AddDays(provider.ChangePasswordAfterDays); } Manager.Commit(); AddToHistory(info); edited = true; } } catch (SamePasswordException uEx) { throw uEx; } catch (UnknownItemException uEx) { throw uEx; } catch (InvalidPasswordException pEx) { throw pEx; } catch (Exception ex) { Manager.RollBack(); newPassword = ""; } return(edited); }