Ejemplo n.º 1
0
        private async Task <IActionResult> InternalAdd(RepresentationParameter jobj)
        {
            _logger.LogInformation(string.Format(Global.AddResource, jobj.ToString()));
            try
            {
                var command            = new AddRepresentationCommand(_resourceType, jobj);
                var scimRepresentation = await _addRepresentationCommandHandler.Handle(command);

                return(BuildHTTPResult(scimRepresentation, HttpStatusCode.Created, false));
            }
            catch (SCIMSchemaViolatedException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.SchemaViolated));
            }
            catch (SCIMBadSyntaxException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }
            catch (SCIMUniquenessAttributeException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.Conflict, ex.Message, SCIMConstants.ErrorSCIMTypes.Uniqueness));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.InternalServerError, ex.ToString(), SCIMConstants.ErrorSCIMTypes.InternalServerError));
            }
        }
Ejemplo n.º 2
0
        private async Task <IActionResult> InternalAdd([FromBody] JObject jobj)
        {
            try
            {
                var command            = new AddRepresentationCommand(_scimEndpoint, _schemas.Select(s => s.Id).ToList(), jobj);
                var scimRepresentation = await _addRepresentationCommandHandler.Handle(command);

                return(BuildHTTPResult(scimRepresentation, HttpStatusCode.Created, false));
            }
            catch (SCIMBadRequestException)
            {
                return(this.BuildError(HttpStatusCode.BadRequest, "Request is unparsable, syntactically incorrect, or violates schema.", "invalidSyntax"));
            }
            catch (SCIMUniquenessAttributeException)
            {
                return(this.BuildError(HttpStatusCode.Conflict, "One or more of the attribute values are already in use or are reserved.", "uniqueness"));
            }
        }
Ejemplo n.º 3
0
        protected async Task <IActionResult> InternalAdd(RepresentationParameter jobj)
        {
            if (jobj == null)
            {
                return(this.BuildError(HttpStatusCode.BadRequest, Global.HttpPostNotWellFormatted, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }

            _logger.LogInformation(Global.AddResource);
            try
            {
                var command            = new AddRepresentationCommand(_resourceType, jobj, Request.GetAbsoluteUriWithVirtualPath());
                var scimRepresentation = await _addRepresentationCommandHandler.Handle(command);

                var location = GetLocation(scimRepresentation);
                var content  = scimRepresentation.ToResponse(location, false);
                if (SCIMConstants.MappingScimResourceTypeToCommonType.ContainsKey(scimRepresentation.ResourceType))
                {
                    await _busControl.Publish(new RepresentationAddedEvent(scimRepresentation.Id, scimRepresentation.Version, SCIMConstants.MappingScimResourceTypeToCommonType[scimRepresentation.ResourceType], content, _options.IncludeToken ? Request.GetToken() : string.Empty));
                }

                return(BuildHTTPResult(HttpStatusCode.Created, location, scimRepresentation.Version, content));
            }
            catch (SCIMSchemaViolatedException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.SchemaViolated));
            }
            catch (SCIMBadSyntaxException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }
            catch (SCIMUniquenessAttributeException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.Conflict, ex.Message, SCIMConstants.ErrorSCIMTypes.Uniqueness));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.InternalServerError, ex.ToString(), SCIMConstants.ErrorSCIMTypes.InternalServerError));
            }
        }
Ejemplo n.º 4
0
        protected async Task <IActionResult> InternalAdd(RepresentationParameter jobj)
        {
            if (jobj == null)
            {
                return(this.BuildError(HttpStatusCode.BadRequest, Global.HttpPostNotWellFormatted, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }

            _logger.LogInformation(string.Format(Global.AddResource, jobj.ToString()));
            try
            {
                var command            = new AddRepresentationCommand(_resourceType, jobj);
                var scimRepresentation = await _addRepresentationCommandHandler.Handle(command);

                var location = GetLocation(scimRepresentation);
                var content  = scimRepresentation.ToResponse(location, false);
                await _busControl.Publish(new RepresentationAddedEvent(scimRepresentation.Id, scimRepresentation.VersionNumber, _resourceType, content));

                return(BuildHTTPResult(HttpStatusCode.Created, location, scimRepresentation.Version, content));
            }
            catch (SCIMSchemaViolatedException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.SchemaViolated));
            }
            catch (SCIMBadSyntaxException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }
            catch (SCIMUniquenessAttributeException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.Conflict, ex.Message, SCIMConstants.ErrorSCIMTypes.Uniqueness));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.InternalServerError, ex.ToString(), SCIMConstants.ErrorSCIMTypes.InternalServerError));
            }
        }