Exemplo n.º 1
0
        /// <summary>
        /// Checks if the given object is allowed access to the tenant.
        /// </summary>
        /// <param name="iamClient">The IamClient to use.</param>
        /// <param name="request">The object that requires a permission check.</param>
        /// <param name="tenantId">The tenant id to check against.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>The raw HttpResponseMessage.</returns>
        public static async Task <Result <AclCheckResponse> > IsAllowedAccessToTenantResultAsync(this IIamClient iamClient, AclCheckRequest request, Guid tenantId, System.Threading.CancellationToken cancellationToken = default)
        {
            if (iamClient is null)
            {
                throw new ArgumentNullException(nameof(iamClient));
            }

            HttpResponseMessage response = await iamClient.IsAllowedAccessToTenantHttpResponseAsync(request, tenantId, cancellationToken).ConfigureAwait(false);

            using (response)
            {
                switch (response.StatusCode)
                {
                case HttpStatusCode.OK:
                    return(await response.DeserializeJsonContentAsync <AclCheckResponse>().ConfigureAwait(false));

                case HttpStatusCode.NoContent:
                    return(default);

                case HttpStatusCode.BadRequest:
                case HttpStatusCode.InternalServerError:
                {
                    ErrorResponse errorResponse = await response.DeserializeJsonContentAsync <ErrorResponse>().ConfigureAwait(false);

                    return(ErrorResult <AclCheckResponse>(errorResponse.Error));
                }

                default:
                {
                    UnexpectedStatusCodeError error = await UnexpectedStatusCodeError.CreateAsync(response, $"{nameof(IIamClient)}.{nameof(IsAllowedAccessToTenantResultAsync)}").ConfigureAwait(false);

                    return(ErrorResult <AclCheckResponse>(error));
                }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if the given subject is allowed access to the tenant.
        /// </summary>
        /// <param name="iamClient">The IamClient to use.</param>
        /// <param name="request">The subject that requires a permission check.</param>
        /// <param name="tenantId">The tenant id to check against.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>The raw HttpResponseMessage.</returns>
        public static async Task <AclCheckResponse> IsAllowedAccessToTenantAsync(this IIamClient iamClient, AclCheckRequest request, Guid tenantId, CancellationToken cancellationToken = default)
        {
            if (iamClient is null)
            {
                throw new ArgumentNullException(nameof(iamClient));
            }

            Result <AclCheckResponse> result = await iamClient.IsAllowedAccessToTenantResultAsync(request, tenantId, cancellationToken).ConfigureAwait(false);

            if (result.IsSuccess)
            {
                return(result.Value);
            }

            throw ApiException.Create(result.Error);
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public async Task <HttpResponseMessage> IsAllowedAccessToTenantHttpResponseAsync(AclCheckRequest request, Guid tenantId, CancellationToken cancellationToken = default)
        {
            IHttpRequestMessageBuilder requestBuilder = UrlBuilder
                                                        .Create("tenants/{tenantId}/acl/check")
                                                        .ReplaceToken("{tenantId}", tenantId)
                                                        .ToRequest()
                                                        .WithHttpMethod().Post()
                                                        .WithContentJson(request)
                                                        .WithAcceptApplicationJson();

            requestBuilder = await this.PreviewIsAllowedAccessToTenantAsync(requestBuilder, cancellationToken).ConfigureAwait(false);

            HttpResponseMessage response = await this.SendRequestWithPolicy(requestBuilder, this.IsAllowedAccessToTenantPolicy, cancellationToken).ConfigureAwait(false);

            return(response);
        }