public async Task <bool> Execute(UpdateResourceSetParameter udpateResourceSetParameter)
        {
            if (udpateResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(udpateResourceSetParameter));
            }

            if (await _resourceSetRepository.Get(udpateResourceSetParameter.Id) == null)
            {
                return(false);
            }

            var resourceSet = new ResourceSet
            {
                Id      = udpateResourceSetParameter.Id,
                Name    = udpateResourceSetParameter.Name,
                Uri     = udpateResourceSetParameter.Uri,
                Type    = udpateResourceSetParameter.Type,
                Scopes  = udpateResourceSetParameter.Scopes,
                IconUri = udpateResourceSetParameter.IconUri
            };

            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (!await _resourceSetRepository.Update(resourceSet))
            {
                throw new BaseUmaException(
                          ErrorCodes.InternalError,
                          string.Format(ErrorDescriptions.TheResourceSetCannotBeUpdated, resourceSet.Id));
            }

            return(true);
        }
        public async Task <Option> Execute(ResourceSet resourceSet, CancellationToken cancellationToken)
        {
            var checkResult = CheckResourceSetParameter(resourceSet);

            return(checkResult switch
            {
                Option.Error => checkResult,
                _ => await _resourceSetRepository.Update(resourceSet, cancellationToken).ConfigureAwait(false)
            });
Beispiel #3
0
        public async Task <IActionResult> SetResourceSetPolicy(
            string id,
            PolicyRule[] rules,
            CancellationToken cancellationToken)
        {
            var subject = User.GetSubject();

            if (string.IsNullOrWhiteSpace(subject))
            {
                return(BuildError(
                           ErrorCodes.InvalidRequest,
                           Strings.TheSubjectCannotBeRetrieved,
                           HttpStatusCode.BadRequest));
            }

            if (string.IsNullOrWhiteSpace(id))
            {
                return(BuildError(
                           ErrorCodes.InvalidRequest,
                           Strings.TheIdentifierMustBeSpecified,
                           HttpStatusCode.BadRequest));
            }

            var result = await _resourceSetRepository.Get(subject, id, cancellationToken).ConfigureAwait(false);

            if (result == null)
            {
                return(BuildError(ErrorCodes.InvalidRequest, Strings.InvalidResource, HttpStatusCode.BadRequest));
            }

            result = result with {
                AuthorizationPolicies = rules
            };
            var updated = await _resourceSetRepository.Update(result, cancellationToken).ConfigureAwait(false);

            return(updated switch
            {
                Option.Error => Problem(),
                _ => Ok()
            });
Beispiel #4
0
        public async Task <bool> Execute(UpdateResourceSetParameter udpateResourceSetParameter)
        {
            if (udpateResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(udpateResourceSetParameter));
            }

            var json = JsonConvert.SerializeObject(udpateResourceSetParameter);

            _umaServerEventSource.StartToUpdateResourceSet(json);
            var resourceSet = new ResourceSet
            {
                Id      = udpateResourceSetParameter.Id,
                Name    = udpateResourceSetParameter.Name,
                Uri     = udpateResourceSetParameter.Uri,
                Type    = udpateResourceSetParameter.Type,
                Scopes  = udpateResourceSetParameter.Scopes,
                IconUri = udpateResourceSetParameter.IconUri,
                Owner   = udpateResourceSetParameter.Owner,
                AcceptPendingRequest = udpateResourceSetParameter.AcceptPendingRequest
            };

            if (string.IsNullOrWhiteSpace(udpateResourceSetParameter.Id))
            {
                throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, "id"));
            }
            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (await _resourceSetRepository.Get(udpateResourceSetParameter.Id) == null)
            {
                return(false);
            }

            if (!await _resourceSetRepository.Update(resourceSet))
            {
                throw new BaseUmaException(ErrorCodes.InternalError, string.Format(ErrorDescriptions.TheResourceSetCannotBeUpdated, resourceSet.Id));
            }

            _umaServerEventSource.FinishToUpdateResourceSet(json);
            return(true);
        }