public IHttpActionResult PostUser([FromBody] SCIMUser user) { logger.Debug("Enter PostUser " + user.userName); SCIMUser scimUserOut = new SCIMUser(); try { scimUserOut = connector.createUser(user); if (string.IsNullOrEmpty(scimUserOut.id)) { logger.Error("Exit error create user name " + user.userName); SCIMException createException = new SCIMException(); createException.ErrorMessage = "error create user name " + user.userName; createException.ErrorSummary = "error create user name " + user.userName; return(InternalServerError(createException)); } else { //return Ok(); logger.Debug("Exit Successfully created user username " + scimUserOut.userName + " appId " + scimUserOut.id); string uri = Url.Link("DefaultAPI", new { id = user.id }); return(Created <SCIMUser>(uri, scimUserOut)); } } catch (Exception e) { logger.Debug("Exit Exception at PostUser "); logger.Error(e); return(InternalServerError(e)); } }
public IHttpActionResult Patch(String id, [FromBody] SCIMUserOperation operation) { bool result = true; SCIMUser scimUserOut = new SCIMUser(); if (id == null) { logger.Error("Error at PATCH User, id missing "); return(BadRequest()); } else { logger.Debug("Enter Patch Id " + id); } try { if (operation.Operations[0].op == "replace") { if (operation.Operations[0].value.active) { scimUserOut = connector.reactivateUser(id); } else { scimUserOut = connector.deactivateUser(id); } if (string.IsNullOrEmpty(scimUserOut.id)) { logger.Error("Exit error update user id " + id); SCIMException updateException = new SCIMException(); updateException.ErrorMessage = "error update user id " + id; updateException.ErrorSummary = "error update user id " + id; return(InternalServerError(updateException)); } else { //return Ok(); logger.Debug("Exit Successfully updated user username " + scimUserOut.userName + " appId " + scimUserOut.id); return(Ok <SCIMUser>(scimUserOut)); } } else { logger.Debug("Exit Patch user failed with unknown operation " + id); SCIMException patchException = new SCIMException(); patchException.ErrorMessage = "Patch user failed with unknown operation id " + id; patchException.ErrorSummary = "Patch user failed with unknown operation " + id; return(InternalServerError(patchException)); } } catch (Exception e) { logger.Debug("Exit Error at Patching User Status "); logger.Error(e); return(InternalServerError(e)); } }
public IActionResult Put(string id, [FromBody] SCIMUser user) { SCIMUser scimUserOut = new SCIMUser(); if (id == null) { _logger.LogError("Error at PUT User, id missing "); return(BadRequest()); } else { _logger.LogDebug("Enter Put " + user.displayName + " Id " + id); } try { user.id = id; scimUserOut = _connector.updateUser(user); if (string.IsNullOrEmpty(scimUserOut.id)) { _logger.LogError("Exit error update user id " + id); SCIMException updateException = new SCIMException(); updateException.ErrorMessage = "error update user id " + id; updateException.ErrorSummary = "error update user id " + id; return(StatusCode(StatusCodes.Status500InternalServerError, updateException)); } else { //return Ok(); _logger.LogDebug("Exit Successfully updated user username " + scimUserOut.userName + " appId " + scimUserOut.id); return(Ok(scimUserOut)); } } catch (Exception e) { _logger.LogDebug("Exit Error at PUT User"); _logger.LogError(e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, e)); } }
public IActionResult Put(string id, [FromBody] SCIMGroup group) { SCIMGroup scimGroupOut = new SCIMGroup(); if (id == null) { _logger.LogError("Error at PUT Group, id missing "); return(BadRequest()); } else { _logger.LogDebug("Enter Put " + group.displayName + " Id " + id); } try { group.id = id; scimGroupOut = _connector.updateGroup(group); if (string.IsNullOrEmpty(scimGroupOut.id)) { _logger.LogError("Exit error update group id " + id); SCIMException updateException = new SCIMException(); updateException.ErrorMessage = "error update group id " + id; updateException.ErrorSummary = "error update group id " + id; return(StatusCode(StatusCodes.Status500InternalServerError)); } else { //return Ok(); _logger.LogDebug("Exit Successfully updated group " + scimGroupOut.displayName); return(Ok(scimGroupOut)); } } catch (Exception e) { _logger.LogDebug("Exit Error at PUT User"); _logger.LogError(e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, e)); } }
public IActionResult PostUser([FromBody] SCIMUser user) { _logger.LogDebug("Enter PostUser " + user.userName); SCIMUser scimUserOut = new SCIMUser(); try { scimUserOut = _connector.createUser(user); if (string.IsNullOrEmpty(scimUserOut.id)) { _logger.LogError("Exit error create user name " + user.userName); SCIMException createException = new SCIMException(); createException.ErrorMessage = "error create user name " + user.userName; createException.ErrorSummary = "error create user name " + user.userName; //return InternalServerError(createException); return(StatusCode(StatusCodes.Status500InternalServerError, createException)); } else { //return Ok(); _logger.LogDebug("Exit Successfully created user username " + scimUserOut.userName + " appId " + scimUserOut.id); //string uri = Url.Link("DefaultAPI", new { id = user.id }); string uri = "https://default.com"; return(Created(uri, scimUserOut)); } } catch (Exception e) { _logger.LogDebug("Exit Exception at PostUser "); _logger.LogError(e.ToString()); //return InternalServerError(e); return(StatusCode(StatusCodes.Status500InternalServerError, e)); } }
public IActionResult Patch(String id, [FromBody] SCIMGroupOperation operation) { bool result = false; bool response = false; if (id == null) { _logger.LogError("Error at PATCH Group, id missing "); return(BadRequest()); } else { _logger.LogDebug("Enter Patch Id " + id); } try { foreach (var nextOp in operation.Operations) { switch (nextOp.op) { case "add": Member addMember = new Member(); response = false; addMember.value = nextOp.value[0].value; addMember.display = nextOp.value[0].display; response = _connector.addGroupMember(id, addMember); if (response) { result = true; } break; case "remove": Member removeMember = new Member(); response = false; string path = nextOp.path; var index = path.IndexOf("eq"); var path1 = path.Substring(index + 2); var text = Regex.Replace(path1, "[^\\w\\._]", ""); removeMember.value = text; response = _connector.removeGroupMember(id, removeMember); if (response) { result = true; } break; case "replace": Member replaceMember = new Member(); response = false; response = _connector.removeGroupMember(id, replaceMember); if (response) { response = _connector.addGroupMember(id, replaceMember); if (response) { result = true; } } break; default: _logger.LogDebug("Exit Patch group failed with unknown operation id" + id); SCIMException patchException = new SCIMException(); patchException.ErrorMessage = "Patch group failed with unknown operation id " + id; patchException.ErrorSummary = "Patch group failed with unknown operation id" + id; return(StatusCode(StatusCodes.Status500InternalServerError, patchException)); } }//end foreach if (result) { _logger.LogDebug("Exit Successfully Patch group id " + id); //both a 204 and 200 with full object are legal return(Ok(_connector.getGroup(id))); //return StatusCode(HttpStatusCode.NoContent); } else { _logger.LogDebug("Exit Patch group failed id " + id); SCIMException patchException = new SCIMException(); patchException.ErrorMessage = "Patch group failed id " + id; patchException.ErrorSummary = "Patch group failed id " + id; return(StatusCode(StatusCodes.Status500InternalServerError, patchException)); } }//end try catch (Exception e) { _logger.LogDebug("Exit Error at Patching Group "); _logger.LogError(e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, e)); } }