Beispiel #1
0
        public void GetCluster_If_Cluster_Level_Auth_Use_PasswordAuthenticator()
        {
            // Arrange

            var options = new Mock <IOptions <CouchbaseClientDefinition> >();

            options.Setup(x => x.Value).Returns(new CouchbaseClientDefinition
            {
                Username = "******",
                Password = "******"
            });

            var loggerFactory = new LoggerFactory();

            var provider = new ClusterProvider(options.Object, loggerFactory);

            // Act/Assert

            var cluster       = provider.GetCluster();
            var authenticator = cluster.Configuration.GetType()
                                .GetProperty("Authenticator", BindingFlags.NonPublic | BindingFlags.Instance)
                                .GetValue(cluster.Configuration);

            Assert.IsType <PasswordAuthenticator>(authenticator);
        }
Beispiel #2
0
 public ClusterProviderSpecs()
 {
     _match1 = new Match()
     {
         Length = 10, QuerySequenceOffset = 1, ReferenceSequenceOffset = 5
     };
     _match2 = new Match()
     {
         Length = 20, QuerySequenceOffset = 2, ReferenceSequenceOffset = 1
     };
     _sut = new ClusterProvider();
 }
        public async Task GetClusterAsync_Disposed_Exception()
        {
            // Arrange

            var options = new Mock <IOptions <ClusterOptions> >();

            var provider = new ClusterProvider(options.Object);

            provider.Dispose();

            // Act/Assert

            var ex = await Assert.ThrowsAsync <ObjectDisposedException>(() => provider.GetClusterAsync().AsTask());

            Assert.Equal(nameof(ClusterProvider), ex.ObjectName);
        }
Beispiel #4
0
        public void GetCluster_Disposed_Exception()
        {
            // Arrange

            var options       = new Mock <IOptions <CouchbaseClientDefinition> >();
            var loggerFactory = new LoggerFactory();

            var provider = new ClusterProvider(options.Object, loggerFactory);

            provider.Dispose();

            // Act/Assert

            var ex = Assert.Throws <ObjectDisposedException>(() => provider.GetCluster());

            Assert.Equal(nameof(ClusterProvider), ex.ObjectName);
        }
Beispiel #5
0
        protected override void ConfigureIoC(IStyletIoCBuilder builder)
        {
            IAppPathProvider pathProvider = new AppPathProvider(registryProvider);

            try
            {
                try
                {
                    ClusterProvider provider = new ClusterProvider();

                    if (provider.IsClustered && !provider.IsOnActiveNode())
                    {
                        throw new ClusterNodeNotActiveException("The AMS service is not active on this cluster node. Please run this app on the currently active node");
                    }
                }
                catch (ClusterNodeNotActiveException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    logger.LogError(EventIDs.UIGenericError, ex, "Unable to determine cluster node status");
                }

                if (!File.Exists(pathProvider.ConfigFile))
                {
                    this.logger.LogCritical(EventIDs.UIGenericError, "Config file was not found at path {path}", pathProvider.ConfigFile);
                    throw new MissingConfigurationException($"The appsettings.config file could not be found at path {pathProvider.ConfigFile}. Please resolve the issue and restart the application");
                }

                if (!File.Exists(pathProvider.HostingConfigFile))
                {
                    this.logger.LogCritical(EventIDs.UIGenericError, "Apphost file was not found at path {path}", pathProvider.HostingConfigFile);
                    throw new MissingConfigurationException($"The apphost.config file could not be found at path {pathProvider.HostingConfigFile}. Please resolve the issue and restart the application");
                }

                appconfig = ApplicationConfig.Load(pathProvider.ConfigFile);
                var hosting = HostingOptions.Load(pathProvider.HostingConfigFile);

                //Config
                builder.Bind <IApplicationConfig>().ToInstance(appconfig);
                builder.Bind <AuthenticationOptions>().ToInstance(appconfig.Authentication);
                builder.Bind <AuditOptions>().ToInstance(appconfig.Auditing);
                builder.Bind <AuthorizationOptions>().ToInstance(appconfig.Authorization);
                builder.Bind <EmailOptions>().ToInstance(appconfig.Email);
                builder.Bind <ForwardedHeadersAppOptions>().ToInstance(appconfig.ForwardedHeaders);
                builder.Bind <HostingOptions>().ToInstance(hosting);
                builder.Bind <RateLimitOptions>().ToInstance(appconfig.RateLimits);
                builder.Bind <UserInterfaceOptions>().ToInstance(appconfig.UserInterface);
                builder.Bind <JitConfigurationOptions>().ToInstance(appconfig.JitConfiguration);
                builder.Bind <LicensingOptions>().ToInstance(appconfig.Licensing);
                builder.Bind <DatabaseConfigurationOptions>().ToInstance(appconfig.DatabaseConfiguration);
                builder.Bind <DataProtectionOptions>().ToInstance(appconfig.DataProtection);
                builder.Bind <AdminNotificationOptions>().ToInstance(appconfig.AdminNotifications);

                // ViewModel factories
                builder.Bind(typeof(INotificationChannelDefinitionsViewModelFactory <,>)).ToAllImplementations();
                builder.Bind(typeof(INotificationChannelDefinitionViewModelFactory <,>)).ToAllImplementations();
                builder.Bind <INotificationChannelSelectionViewModelFactory>().To <NotificationChannelSelectionViewModelFactory>();
                builder.Bind <ISecurityDescriptorTargetViewModelFactory>().To <SecurityDescriptorTargetViewModelFactory>();
                builder.Bind <ISecurityDescriptorTargetsViewModelFactory>().To <SecurityDescriptorTargetsViewModelFactory>();
                builder.Bind <IFileSelectionViewModelFactory>().To <FileSelectionViewModelFactory>();
                builder.Bind <IActiveDirectoryDomainPermissionViewModelFactory>().To <ActiveDirectoryDomainPermissionViewModelFactory>();
                builder.Bind <IActiveDirectoryForestSchemaViewModelFactory>().To <ActiveDirectoryForestSchemaViewModelFactory>();
                builder.Bind <IX509Certificate2ViewModelFactory>().To <X509Certificate2ViewModelFactory>();
                builder.Bind <IJitGroupMappingViewModelFactory>().To <JitGroupMappingViewModelFactory>();
                builder.Bind <IJitDomainStatusViewModelFactory>().To <JitDomainStatusViewModelFactory>();
                builder.Bind <IEffectiveAccessViewModelFactory>().To <EffectiveAccessViewModelFactory>();
                builder.Bind <IImportProviderFactory>().To <ImportProviderFactory>();
                builder.Bind <IImportResultsViewModelFactory>().To <ImportResultsViewModelFactory>();

                // Services
                builder.Bind <RandomNumberGenerator>().ToInstance(RandomNumberGenerator.Create());
                builder.Bind <IDialogCoordinator>().To <DialogCoordinator>();
                builder.Bind <IDirectory>().To <ActiveDirectory>();
                builder.Bind <ILocalSam>().To <LocalSam>();
                builder.Bind <IComputerPrincipalProviderRpc>().To <ComputerPrincipalProviderRpc>();
                builder.Bind <IComputerPrincipalProviderCsv>().To <ComputerPrincipalProviderCsv>();
                builder.Bind <IComputerPrincipalProviderLaps>().To <ComputerPrincipalProviderLaps>();
                builder.Bind <IComputerPrincipalProviderBitLocker>().To <ComputerPrincipalProviderBitLocker>();
                builder.Bind <IDiscoveryServices>().To <DiscoveryServices>();
                builder.Bind <IWindowsServiceProvider>().To <WindowsServiceProvider>();
                builder.Bind <INotificationSubscriptionProvider>().To <NotificationSubscriptionProvider>();
                builder.Bind <IEncryptionProvider>().To <EncryptionProvider>();
                builder.Bind <ICertificateProvider>().To <CertificateProvider>();
                builder.Bind <IAppPathProvider>().To <AppPathProvider>();
                builder.Bind <INotifyModelChangedEventPublisher>().To <NotifyModelChangedEventPublisher>();
                builder.Bind <IShellExecuteProvider>().To <ShellExecuteProvider>();
                builder.Bind <IDomainTrustProvider>().To <DomainTrustProvider>();
                builder.Bind <IComputerTargetProvider>().To <ComputerTargetProvider>();
                builder.Bind <IObjectSelectionProvider>().To <ObjectSelectionProvider>();
                builder.Bind <ITargetDataProvider>().To <TargetDataProvider>();
                builder.Bind <ITargetDataCache>().To <TargetDataCache>();
                builder.Bind <IAuthorizationContextProvider>().To <AuthorizationContextProvider>();
                builder.Bind <IAuthorizationInformationBuilder>().To <AuthorizationInformationBuilder>();
                builder.Bind <IPowerShellSecurityDescriptorGenerator>().To <PowerShellSecurityDescriptorGenerator>();
                builder.Bind <IAuthorizationInformationMemoryCache>().To <AuthorizationInformationMemoryCache>();
                builder.Bind <IPowerShellSessionProvider>().To <CachedPowerShellSessionProvider>();
                builder.Bind <IScriptTemplateProvider>().To <ScriptTemplateProvider>();
                builder.Bind <IRegistryProvider>().ToInstance(registryProvider);
                builder.Bind <ICertificatePermissionProvider>().To <CertificatePermissionProvider>();
                builder.Bind <ICertificateSynchronizationProvider>().To <CertificateSynchronizationProvider>();
                builder.Bind <IApplicationUpgradeProvider>().To <ApplicationUpgradeProvider>();
                builder.Bind <IFirewallProvider>().To <FirewallProvider>();
                builder.Bind <IHttpSysConfigurationProvider>().To <HttpSysConfigurationProvider>();
                builder.Bind <SqlServerInstanceProvider>().ToSelf();

                builder.Bind <IProtectedSecretProvider>().To <ProtectedSecretProvider>().InSingletonScope();
                builder.Bind <IClusterProvider>().To <ClusterProvider>().InSingletonScope();
                builder.Bind <IProductSettingsProvider>().To <ProductSettingsProvider>().InSingletonScope();
                builder.Bind <IAmsLicenseManager>().To <AmsLicenseManager>().InSingletonScope();
                builder.Bind <ISecretRekeyProvider>().To <SecretRekeyProvider>().InSingletonScope();
                builder.Bind <ILicenseDataProvider>().To <OptionsLicenseDataProvider>().InSingletonScope();

                builder.Bind(typeof(IModelValidator <>)).To(typeof(FluentModelValidator <>));
                builder.Bind(typeof(IValidator <>)).ToAllImplementations();
                builder.Bind <ILoggerFactory>().ToInstance(this.loggerFactory);
                builder.Bind(typeof(ILogger <>)).To(typeof(Logger <>));
                builder.Bind(typeof(IOptions <>)).To(typeof(OptionsWrapper <>)).InSingletonScope();
                builder.Bind(typeof(IOptionsSnapshot <>)).To(typeof(OptionsManager <>));
                builder.Bind(typeof(IOptionsFactory <>)).To(typeof(OptionsFactory <>));
                builder.Bind(typeof(IOptionsMonitorCache <>)).To(typeof(OptionsCache <>)).InSingletonScope();

                base.ConfigureIoC(builder);
            }
            catch (ApplicationInitializationException ex)
            {
                this.logger.LogCritical(EventIDs.UIInitializationError, ex, "Initialization error");
                throw;
            }
            catch (Exception ex)
            {
                this.logger.LogCritical(EventIDs.UIInitializationError, ex, "Initialization error");
                throw new ApplicationInitializationException("The application failed to initialize", ex);
            }
        }