Exemplo n.º 1
0
        public async Task <OpenApiResult> SetResourceAccessRuleSetResourceAccessRulesAsync(
            string tenantId,
            string resourceAccessRuleSetId,
            IEnumerable <ResourceAccessRule> body)
        {
            ITenant tenant = await this.tenancyHelper.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IResourceAccessRuleSetStore store = await this.permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(tenant).ConfigureAwait(false);

            ResourceAccessRuleSet ruleSet;

            try
            {
                ruleSet = await store.GetAsync(resourceAccessRuleSetId).ConfigureAwait(false);
            }
            catch (ResourceAccessRuleSetNotFoundException)
            {
                return(this.NotFoundResult());
            }

            ruleSet.Rules = body.ToList();

            await store.PersistAsync(ruleSet).ConfigureAwait(false);

            return(this.OkResult());
        }
Exemplo n.º 2
0
        public async Task <OpenApiResult> CreateResourceAccessRuleSetAsync(
            string tenantId,
            ResourceAccessRuleSet body)
        {
            ITenant tenant = await this.tenancyHelper.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IResourceAccessRuleSetStore store = await this.permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(tenant).ConfigureAwait(false);

            ResourceAccessRuleSet result = await store.PersistAsync(body).ConfigureAwait(false);

            return(this.OkResult(result, "application/json"));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ClaimPermissionsStore" /> class
        ///     backed by the given repository.
        /// </summary>
        /// <param name="container">
        ///     The <see cref="BlobContainerClient" /> in which permissions will be stored.
        /// </param>
        /// <param name="resourceAccessRuleSetStore">The resource access rule set.</param>
        /// <param name="serializerSettingsProvider">The <see cref="IJsonSerializerSettingsProvider"/> for serializion.</param>
        public ClaimPermissionsStore(
            BlobContainerClient container,
            IResourceAccessRuleSetStore resourceAccessRuleSetStore,
            IJsonSerializerSettingsProvider serializerSettingsProvider)
        {
            if (serializerSettingsProvider is null)
            {
                throw new ArgumentNullException(nameof(serializerSettingsProvider));
            }

            this.Container = container ?? throw new ArgumentNullException(nameof(container));
            this.resourceAccessRuleSetStore = resourceAccessRuleSetStore ?? throw new ArgumentNullException(nameof(resourceAccessRuleSetStore));
            this.serializerSettings         = serializerSettingsProvider.Instance;
        }
Exemplo n.º 4
0
        public async Task <OpenApiResult> GetResourceAccessRuleSetAsync(
            string tenantId,
            string resourceAccessRuleSetId)
        {
            ITenant tenant = await this.tenancyHelper.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IResourceAccessRuleSetStore store = await this.permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(tenant).ConfigureAwait(false);

            try
            {
                ResourceAccessRuleSet result = await store.GetAsync(resourceAccessRuleSetId).ConfigureAwait(false);

                return(this.OkResult(result, "application/json"));
            }
            catch (ResourceAccessRuleSetNotFoundException)
            {
                return(this.NotFoundResult());
            }
        }
Exemplo n.º 5
0
        public async Task <OpenApiResult> UpdateResourceAccessRuleSetResourceAccessRulesAsync(
            string tenantId,
            string resourceAccessRuleSetId,
            UpdateOperation operation,
            IEnumerable <ResourceAccessRule> body)
        {
            ITenant tenant = await this.tenancyHelper.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IResourceAccessRuleSetStore store = await this.permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(tenant).ConfigureAwait(false);

            ResourceAccessRuleSet ruleSet;

            try
            {
                ruleSet = await store.GetAsync(resourceAccessRuleSetId).ConfigureAwait(false);
            }
            catch (ResourceAccessRuleSetNotFoundException)
            {
                return(this.NotFoundResult());
            }

            switch (operation)
            {
            case UpdateOperation.Add:
                ruleSet.Rules.AddRange(body);
                break;

            case UpdateOperation.Remove:
                body.ForEach(rc => ruleSet.Rules.Remove(rc));
                break;
            }

            await store.PersistAsync(ruleSet).ConfigureAwait(false);

            return(this.CreatedResult());
        }