/// <summary>
        /// Retrieves the tenant with the specified Id and ensures it is of the correct type.
        /// </summary>
        /// <param name="tenantStore">The tenant store.</param>
        /// <param name="tenantId">The Id of the tenant to retrieve.</param>
        /// <param name="allowableTenantTypes">The list of valid types for the tenant.</param>
        /// <returns>The client tenant.</returns>
        /// <exception cref="TenantNotFoundException">There is no tenant with the specified Id.</exception>
        /// <exception cref="InvalidMarainTenantTypeException">The tenant Id provided is not for a tenant with the specified type.</exception>
        public static async Task <ITenant> GetTenantOfTypeAsync(this ITenantStore tenantStore, string tenantId, params MarainTenantType[] allowableTenantTypes)
        {
            ITenant tenant = await tenantStore.GetTenantAsync(tenantId).ConfigureAwait(false);

            tenant.EnsureTenantIsOfType(allowableTenantTypes);
            return(tenant);
        }
Beispiel #2
0
 public TenantResolver(IEnumerable <ITenantStrategy> strategies, ITenantStore store, ICacheService cache, ILogger logger)
 {
     _store      = store.NotNull();
     _strategies = strategies.NotNull().OrderByDescending(s => s.Priority);
     _cache      = cache.NotNull();
     _logger     = logger.NotNull();
 }
Beispiel #3
0
        /// <summary>
        /// Constructs a new instance of <see cref="TenantManager{TTenant}"/>.
        /// </summary>
        /// <param name="store">The persistence store the manager will operate over.</param>
        /// <param name="optionsAccessor">The accessor used to access the <see cref="TenancyOptions"/>.</param>
        /// <param name="tenantValidators">A collection of <see cref="ITenantValidator{TTenant}"/> to validate tenants against.</param>
        /// <param name="keyNormalizer">The <see cref="ILookupNormalizer"/> to use when generating index keys for tenants.</param>
        /// <param name="errors">The <see cref="TenancyErrorDescriber"/> used to provider error messages.</param>
        /// <param name="services">The <see cref="IServiceProvider"/> used to resolve services.</param>
        /// <param name="logger">The logger used to log messages, warnings and errors.</param>
        public TenantManager(ITenantStore <TTenant> store,
                             IOptions <TenancyOptions> optionsAccessor,
                             IEnumerable <ITenantValidator <TTenant> > tenantValidators,
                             ILookupNormalizer keyNormalizer,
                             TenancyErrorDescriber errors,
                             IServiceProvider services,
                             ILogger <TenantManager <TTenant> > logger)
        {
            ArgCheck.NotNull(nameof(store), store);

            Store          = store;
            Options        = optionsAccessor?.Value ?? new TenancyOptions();
            KeyNormalizer  = keyNormalizer;
            ErrorDescriber = errors;
            Logger         = logger;

            if (tenantValidators != null)
            {
                foreach (var v in tenantValidators)
                {
                    TenantValidators.Add(v);
                }
            }

            _services = services;
        }
 public TenantAccessService(
     ITenantResolutionResolver tenantResolutionResolver,
     ITenantStore <T> tenantStore)
 {
     _tenantResolutionResolver = tenantResolutionResolver;
     _tenantStore = tenantStore;
 }
        /// <summary>
        /// Creates a new instance of the <see cref="AddOrUpdateStorageConfigurationCommand"/> class.
        /// </summary>
        /// <param name="tenantStore">The tenant store.</param>
        /// <param name="serializerSettingsProvider">
        /// The <see cref="IJsonSerializerSettingsProvider"/> to use when reading manifest files.
        /// </param>
        public AddOrUpdateStorageConfigurationCommand(
            ITenantStore tenantStore,
            IJsonSerializerSettingsProvider serializerSettingsProvider)
            : base("add-storage-config", "Adds arbitrary storage configuration for the client.")
        {
            this.tenantStore = tenantStore;
            this.serializerSettingsProvider = serializerSettingsProvider;

            var tenantId = new Argument <string>("tenantId")
            {
                Description = "The Id of the tenant.",
                Arity       = ArgumentArity.ExactlyOne,
            };

            this.AddArgument(tenantId);

            var configFile = new Argument <FileInfo>("configFile")
            {
                Description = "JSON configuration file path.",
                Arity       = ArgumentArity.ExactlyOne,
            };

            this.AddArgument(configFile);

            this.Handler = CommandHandler.Create(
                (string tenantId, FileInfo configFile) => this.HandleCommand(tenantId, configFile));
        }
Beispiel #6
0
 public DomainTenantResolveContributor(
     IWebMultiTenancyConfiguration multiTenancyConfiguration,
     ITenantStore tenantStore)
 {
     _multiTenancyConfiguration = multiTenancyConfiguration;
     _tenantStore = tenantStore;
 }
 public MultiTenantController(
     ITenantResolutionResolver tenantResolutionResolver,
     ITenantStore <Tenant> tenantStore)
 {
     _tenantResolutionResolver = tenantResolutionResolver;
     _tenantStore = tenantStore;
 }
Beispiel #8
0
        public void TestLoggingInterception()
        {
            ITenantStore tenantStore = Container.Resolve <ITenantStore>();
            DateTime     serverTime  = tenantStore.GetTime("a");

            Assert.AreNotEqual(DateTime.MinValue, serverTime);
        }
        /// <summary>
        /// Enrolls the specified tenant in the service.
        /// </summary>
        /// <param name="tenantStore">The <see cref="ITenantStore"/>.</param>
        /// <param name="enrollingTenantId">The Id of the tenant to enroll.</param>
        /// <param name="serviceTenantId">The Id of the service to enroll in.</param>
        /// <param name="configurationItems">Configuration for the enrollment.</param>
        /// <returns>A task which completes when the enrollment has finished.</returns>
        public static async Task EnrollInServiceAsync(
            this ITenantStore tenantStore,
            string enrollingTenantId,
            string serviceTenantId,
            EnrollmentConfigurationItem[] configurationItems)
        {
            if (string.IsNullOrWhiteSpace(enrollingTenantId))
            {
                throw new ArgumentException(nameof(enrollingTenantId));
            }

            if (string.IsNullOrWhiteSpace(serviceTenantId))
            {
                throw new ArgumentException(nameof(serviceTenantId));
            }

            if (configurationItems == null)
            {
                throw new ArgumentNullException(nameof(configurationItems));
            }

            // Enrolling tenant can be either a Client tenant or a Delegated tenant.
            ITenant enrollingTenant = await tenantStore.GetTenantOfTypeAsync(
                enrollingTenantId,
                MarainTenantType.Client,
                MarainTenantType.Delegated).ConfigureAwait(false);

            ITenant serviceTenant = await tenantStore.GetServiceTenantAsync(serviceTenantId).ConfigureAwait(false);

            await tenantStore.EnrollInServiceAsync(enrollingTenant, serviceTenant, configurationItems).ConfigureAwait(false);
        }
Beispiel #10
0
        public async Task ThenTheTenancyProviderContainsTenantsAsChildrenOfTheRootTenant(int expectedTenantCount)
        {
            ITenantStore           tenantStore        = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();
            TenantCollectionResult rootTenantChildren = await tenantStore.GetChildrenAsync(tenantStore.Root.Id).ConfigureAwait(false);

            Assert.AreEqual(expectedTenantCount, rootTenantChildren.Tenants.Count);
        }
Beispiel #11
0
        public async Task GivenIHaveUsedTheTenantStoreToCreateANewClientTenantCalled(string clientName)
        {
            ITenantStore service   = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();
            ITenant      newTenant = await service.CreateClientTenantAsync(clientName).ConfigureAwait(false);

            this.scenarioContext.Set(newTenant.Id, clientName);
        }
Beispiel #12
0
 /// <summary>
 /// Constructs the handler.
 /// </summary>
 /// <param name="tenantStore"></param>
 /// <param name="tenantAccessor"></param>
 /// <param name="cache"></param>
 /// <param name="logger"></param>
 public BeTenantMemberHandler(ITenantStore <TTenant> tenantStore, ITenantAccessor <TTenant> tenantAccessor, IDistributedCache cache, ILogger <BeTenantMemberHandler <TTenant> > logger)
 {
     _tenantStore    = tenantStore ?? throw new ArgumentNullException(nameof(tenantStore));
     _tenantAccessor = tenantAccessor ?? throw new ArgumentNullException(nameof(tenantAccessor));
     _cache          = cache ?? throw new ArgumentNullException(nameof(cache));
     _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Beispiel #13
0
 public TransferSurveysToSqlAzureCommand(ISurveyAnswerStore surveyAnswerStore, ISurveyStore surveyStore, ITenantStore tenantStore, ISurveySqlStore surveySqlStore)
 {
     this.surveyAnswerStore = surveyAnswerStore;
     this.surveyStore       = surveyStore;
     this.tenantStore       = tenantStore;
     this.surveySqlStore    = surveySqlStore;
 }
Beispiel #14
0
        public async Task InvokeAsync(HttpContext httpContext, ITenantStore tenantStore)
        {
            async Task <TenantInfo> FindTenantAsync(string tenantIdOrName)
            {
                return(await tenantStore.FindAsync(tenantIdOrName));
            }

            var resolveResult = _tenantResolver.ResolveTenantIdOrName();

            _tenantResolveResultAccessor.Result = resolveResult;

            TenantInfo tenant = null;

            if (resolveResult.TenantIdOrName != null)
            {
                tenant = await FindTenantAsync(resolveResult.TenantIdOrName);

                if (tenant == null)
                {
                    //TODO: A better exception?
                    throw new LinFxException("There is no tenant with given tenant id or name: " + resolveResult.TenantIdOrName);
                }
            }

            using (_currentTenant.Change(tenant?.Id, tenant?.Name))
            {
                await _next(httpContext);
            }
        }
        private async Task EnrollTenantForService(
            string enrollingTenantName,
            string serviceTenantName,
            string?enrollmentConfigurationName = null)
        {
            ITenantStore managementService =
                ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();
            ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantProvider>();

            ITenant enrollingTenant = await tenantProvider.GetTenantAsync(this.scenarioContext.Get <string>(enrollingTenantName)).ConfigureAwait(false);

            ITenant serviceTenant = await tenantProvider.GetTenantAsync(this.scenarioContext.Get <string>(serviceTenantName)).ConfigureAwait(false);

            List <EnrollmentConfigurationItem> enrollmentConfiguration =
                string.IsNullOrEmpty(enrollmentConfigurationName)
                ? new List <EnrollmentConfigurationItem>()
                : this.scenarioContext.Get <List <EnrollmentConfigurationItem> >(enrollmentConfigurationName);

            await CatchException.AndStoreInScenarioContextAsync(
                this.scenarioContext,
                () => managementService.EnrollInServiceAsync(
                    enrollingTenant,
                    serviceTenant,
                    enrollmentConfiguration.ToArray())).ConfigureAwait(false);
        }
Beispiel #16
0
 private Func <ValueTask <ITenant> > GetTenante(ITenantStore store, string identfier, CancellationToken cancellationToken)
 {
     return(async() =>
     {
         return await store.GetByIdentifier(identfier, cancellationToken).ConfigureAwait(false);
     });
 }
Beispiel #17
0
        /// <summary>
        /// Creates a new instance of the <see cref="EnrollCommand"/> class.
        /// </summary>
        /// <param name="tenantStore">The tenant store.</param>
        /// <param name="serializerSettingsProvider">
        /// The <see cref="IJsonSerializerSettingsProvider"/> to use when reading manifest files.
        /// </param>
        public EnrollCommand(
            ITenantStore tenantStore,
            IJsonSerializerSettingsProvider serializerSettingsProvider)
            : base("enroll", "Enrolls the specified client for the service.")
        {
            this.tenantStore = tenantStore;
            this.serializerSettingsProvider = serializerSettingsProvider;

            var clientTenantId = new Argument <string>("clientTenantId")
            {
                Description = "The Id of the client tenant.",
                Arity       = ArgumentArity.ExactlyOne,
            };

            this.AddArgument(clientTenantId);

            var serviceName = new Argument <string>("serviceTenantId")
            {
                Description = "The Id of the service tenant.",
                Arity       = ArgumentArity.ExactlyOne,
            };

            this.AddArgument(serviceName);

            var configFile = new Option <FileInfo>("--config")
            {
                Description = "JSON configuration file to use when enrolling.",
            };

            this.AddOption(configFile);

            this.Handler = CommandHandler.Create(
                (string clientTenantId, string serviceTenantId, FileInfo? config) => this.HandleCommand(clientTenantId, serviceTenantId, config));
        }
 public TenantStoreBasedIssuerNameRegistry()
 {
     using (var container = new UnityContainer())
     {
         ContainerBootstraper.RegisterTypes(container);
         this.tenantStore = container.Resolve<ITenantStore>();
     }
 }
Beispiel #19
0
 public TenantSwitchModalModel(
     ITenantStore tenantStore,
     IOptions <AbpAspNetCoreMultiTenancyOptions> options)
 {
     TenantStore = tenantStore;
     Options     = options.Value;
     LocalizationResourceType = typeof(AbpUiMultiTenancyResource);
 }
Beispiel #20
0
        public Task WhenIUseTheTenantStoreToInitialiseTheTenancyProviderUsingTheForceOption()
        {
            ITenantStore service = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();

            return(CatchException.AndStoreInScenarioContextAsync(
                       this.scenarioContext,
                       () => service.InitialiseTenancyProviderAsync(true)));
        }
 public TenantStoreBasedIssuerNameRegistry()
 {
     using (var container = new UnityContainer())
     {
         ContainerBootstraper.RegisterTypes(container);
         this.tenantStore = container.Resolve <ITenantStore>();
     }
 }
Beispiel #22
0
 public TenantSwitchViewComponent(
     ITenantStore tenantStore,
     ICurrentTenant currentTenant,
     ICurrentUser currentUser)
 {
     TenantStore   = tenantStore;
     CurrentTenant = currentTenant;
     CurrentUser   = currentUser;
 }
Beispiel #23
0
 public FederationSecurityTokenService(SecurityTokenServiceConfiguration configuration)
     : base(configuration)
 {
     using (var container = new UnityContainer())
     {
         ContainerBootstraper.RegisterTypes(container);
         this.tenantStore = container.Resolve <ITenantStore>();
     }
 }
 public SurveysController(
     ISurveyStore surveyStore,
     ISurveyAnswerStore surveyAnswerStore,
     ITenantStore tenantStore)
 {
     this.surveyStore       = surveyStore;
     this.surveyAnswerStore = surveyAnswerStore;
     this.tenantStore       = tenantStore;
 }
Beispiel #25
0
 public MultiTenancyMiddleware(
     ITenantResolver tenantResolver,
     ITenantStore tenantStore,
     ICurrentTenant currentTenant)
 {
     this.tenantResolver = tenantResolver;
     this.tenantStore    = tenantStore;
     this.currentTenant  = currentTenant;
 }
Beispiel #26
0
 public TenantConfigurationProvider(
     ITenantResolver tenantResolver,
     ITenantStore tenantStore,
     ITenantResolveResultAccessor tenantResolveResultAccessor)
 {
     TenantResolver = tenantResolver;
     TenantStore    = tenantStore;
     TenantResolveResultAccessor = tenantResolveResultAccessor;
 }
 public FederationSecurityTokenService(SecurityTokenServiceConfiguration configuration)
     : base(configuration)
 {
     using (var container = new UnityContainer())
     {
         ContainerBootstraper.RegisterTypes(container);
         this.tenantStore = container.Resolve<ITenantStore>();
     }
 }
Beispiel #28
0
 public AppUrlProvider(
     IOptions <AppUrlOptions> options,
     ICurrentTenant currentTenant,
     ITenantStore tenantStore)
 {
     CurrentTenant = currentTenant;
     TenantStore   = tenantStore;
     Options       = options.Value;
 }
Beispiel #29
0
        public Task WhenIValidateTheServiceManifestCalled(string manifestName)
        {
            ITenantStore    store    = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();
            ServiceManifest manifest = this.scenarioContext.Get <ServiceManifest>(manifestName);

            return(CatchException.AndStoreInScenarioContextAsync(
                       this.scenarioContext,
                       () => manifest.ValidateAndThrowAsync(store)));
        }
Beispiel #30
0
        public async Task GivenTheTenancyProviderContainsTenantsAsChildrenOfTheRootTenant(int tenantCount)
        {
            ITenantStore tenantStore = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <ITenantStore>();

            for (int i = 0; i < tenantCount; i++)
            {
                await tenantStore.CreateChildTenantAsync(tenantStore.Root.Id, Guid.NewGuid().ToString()).ConfigureAwait(false);
            }
        }
 public DomainTenantResolveContributor(
     IHttpContextAccessor httpContextAccessor,
     IWebMultiTenancyConfiguration multiTenancyConfiguration,
     ITenantStore tenantStore)
 {
     _httpContextAccessor       = httpContextAccessor;
     _multiTenancyConfiguration = multiTenancyConfiguration;
     _tenantStore = tenantStore;
 }
Beispiel #32
0
 public AccountController(ITenantStore tenantStore, IUDFDictionary udfDictionary)
     : base(tenantStore)
 {
     this.udfDictionary   = udfDictionary;
     this.extendableTypes = new Dictionary <string, Type>()
     {
         { "SurveyRow", typeof(SurveyRow) }
     };
 }
 public SurveyAnswerStore(
     ITenantStore tenantStore, 
     ISurveyAnswerContainerFactory surveyAnswerContainerFactory,
     IAzureQueue<SurveyAnswerStoredMessage> standardSurveyAnswerStoredQueue, 
     IAzureQueue<SurveyAnswerStoredMessage> premiumSurveyAnswerStoredQueue, 
     IAzureBlobContainer<List<string>> surveyAnswerIdsListContainer)
 {
     this.tenantStore = tenantStore;
     this.surveyAnswerContainerFactory = surveyAnswerContainerFactory;
     this.standardSurveyAnswerStoredQueue = standardSurveyAnswerStoredQueue;
     this.premiumSurveyAnswerStoredQueue = premiumSurveyAnswerStoredQueue;
     this.surveyAnswerIdsListContainer = surveyAnswerIdsListContainer;
 }
		public SurveyAnswerStore(
			ITenantStore tenantStore,
			ISurveyAnswerContainerFactory surveyAnswerContainerFactory,
			IMessageQueue<SurveyAnswerStoredMessage> standardSurveyAnswerStoredQueue,
			IMessageQueue<SurveyAnswerStoredMessage> premiumSurveyAnswerStoredQueue,
			IBlobContainer<List<string>> surveyAnswerIdsListContainer)
		{
			Trace.WriteLine(string.Format("Called constructor in SurveyAnswerStore"), "UNITY");
			this.tenantStore = tenantStore;
			this.surveyAnswerContainerFactory = surveyAnswerContainerFactory;
			this.standardSurveyAnswerStoredQueue = standardSurveyAnswerStoredQueue;
			this.premiumSurveyAnswerStoredQueue = premiumSurveyAnswerStoredQueue;
			this.surveyAnswerIdsListContainer = surveyAnswerIdsListContainer;
		}
 public SurveysController(
     ISurveyStore surveyStore,
     ISurveyAnswerStore surveyAnswerStore,
     ISurveyAnswersSummaryStore surveyAnswersSummaryStore,
     ITenantStore tenantStore,
     ISurveyTransferStore surveyTransferStore,
     IUDFDictionary udfDictionary)
     : base(tenantStore)
 {
     this.surveyStore = surveyStore;
     this.surveyAnswerStore = surveyAnswerStore;
     this.surveyAnswersSummaryStore = surveyAnswersSummaryStore;
     this.surveyTransferStore = surveyTransferStore;
     this.udfDictionary = udfDictionary;
 }
 public AccountController(ITenantStore tenantStore, IUDFDictionary udfDictionary)
     : base(tenantStore)
 {
     this.udfDictionary = udfDictionary;
     this.extendableTypes = new Dictionary<string, Type>() { { "SurveyRow", typeof(SurveyRow) } };
 }
 public IssuerController(ITenantStore tenantStore)
 {
     this.tenantStore = tenantStore;
 }
 public ManagementController(ITenantStore tenantStore)
 {
     this.tenantStore = tenantStore;
 }
Beispiel #39
0
 private static void SetLogo(string tenant, ITenantStore tenantStore, Bitmap logo)
 {
     if (string.IsNullOrWhiteSpace(tenantStore.GetTenant(tenant).Logo))
     {
         using (var stream = new MemoryStream())
         {
             logo.Save(stream, ImageFormat.Png);
             tenantStore.UploadLogo(tenant, stream.ToArray());
         }
     }
 }
 public OnBoardingController(ITenantStore tenantStore)
 {
     this.tenantStore = tenantStore;
 }