public async Task <bool> Execute(AddScopeParameter addScopeParameter)
        {
            var json = addScopeParameter == null ? string.Empty : JsonConvert.SerializeObject(addScopeParameter);

            _umaServerEventSource.StartToAddScope(json);
            if (addScopeParameter == null)
            {
                throw new ArgumentNullException(nameof(addScopeParameter));
            }

            Scope scope = null;

            try
            {
                scope = await _scopeRepository.Get(addScopeParameter.Id);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRetrieved,
                                           ex);
            }

            if (scope != null)
            {
                throw new BaseUmaException(ErrorCodes.InvalidRequestCode,
                                           string.Format(ErrorDescriptions.TheScopeAlreadyExists, addScopeParameter.Id));
            }

            scope = new Scope
            {
                Id      = addScopeParameter.Id,
                IconUri = addScopeParameter.IconUri,
                Name    = addScopeParameter.Name
            };
            _scopeParameterValidator.CheckScopeParameter(scope);

            try
            {
                await _scopeRepository.Insert(scope);

                _umaServerEventSource.FinishToAddScope(json);
                return(true);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeInserted,
                                           ex);
            }
        }
        public async Task <bool> Execute(UpdateScopeParameter updateScopeParameter)
        {
            if (updateScopeParameter == null)
            {
                throw new ArgumentNullException(nameof(updateScopeParameter));
            }

            Scope scope = null;

            try
            {
                scope = await _scopeRepository.Get(updateScopeParameter.Id);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRetrieved,
                                           ex);
            }

            if (scope == null)
            {
                return(false);
            }

            scope = new Scope
            {
                Id      = updateScopeParameter.Id,
                IconUri = updateScopeParameter.IconUri,
                Name    = updateScopeParameter.Name
            };
            _scopeParameterValidator.CheckScopeParameter(scope);

            try
            {
                await _scopeRepository.Update(scope);

                return(true);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeUpdated,
                                           ex);
            }
        }
Ejemplo n.º 3
0
        public async Task <Scope> Execute(string scopeId)
        {
            if (string.IsNullOrWhiteSpace(scopeId))
            {
                throw new ArgumentNullException(nameof(scopeId));
            }

            try
            {
                return(await _scopeRepository.Get(scopeId));
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRetrieved,
                                           ex);
            }
        }
        public async Task <bool> Execute(string scopeId)
        {
            _umaServerEventSource.StartToRemoveScope(scopeId);
            if (string.IsNullOrWhiteSpace(scopeId))
            {
                throw new ArgumentNullException(nameof(scopeId));
            }

            Scope scope = null;

            try
            {
                scope = await _scopeRepository.Get(scopeId);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRetrieved,
                                           ex);
            }

            if (scope == null)
            {
                return(false);
            }

            try
            {
                await _scopeRepository.Delete(scopeId);

                _umaServerEventSource.FinishToRemoveScope(scopeId);
                return(true);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRemoved,
                                           ex);
            }
        }
        public ResourceScopeEntity Create(AddResourceScopeViewModel vm)
        {
            ValidationUtils.ValidateViewModel(vm);

            if (!_resourceRepository.Exists(vm.ResourceId))
            {
                throw new EntityValidationException("No resources with the given ID exists!");
            }

            var scope = _scopeRepository.Get(vm.Name);

            if (null == scope)
            {
                scope = new ScopeEntity()
                {
                    Name        = vm.Name,
                    Description = vm.Description,
                    Active      = true
                };
                scope = _scopeRepository.Create(scope);
            }
            else
            {
                if (_resourceScopeRepository.ExistsOnResource(vm.ResourceId, scope.ScopeId))
                {
                    throw new EntityValidationException("This scope already exists on this resource!");
                }
            }

            var resourceScope = new ResourceScopeEntity()
            {
                ResourceId  = vm.ResourceId,
                ScopeEntity = scope
            };

            return(_resourceScopeRepository.Create(resourceScope));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Get(string id, CancellationToken cancellationToken)
        {
            var scope = await _scopeRepository.Get(id, cancellationToken).ConfigureAwait(false);

            return(scope == null ? (IActionResult)BadRequest() : Ok(scope));
        }