Beispiel #1
0
        private IList <ScimUserEmail> CreateScimUserEmailObjects(JObject jObject)
        {
            IList <ScimUserEmail> scimUserEmails = new List <ScimUserEmail>();
            var emails = jObject["emails"];

            if (emails != null)
            {
                foreach (var email in emails)
                {
                    var scimUserEmail = new ScimUserEmail
                    {
                        Primary = (bool)email["primary"],
                        Type    = (string)email["type"],
                        Value   = (string)email["value"]
                    };
                    scimUserEmails.Add(scimUserEmail);
                }
            }
            return(scimUserEmails);
        }
Beispiel #2
0
        public IActionResult UpdateScimUserById(string id, [FromBody] JObject jObject)
        {
            try
            {
                var scimUser = _applicationDbContext.scimUsers.Where(su => su.ApplicationUserId == id).FirstOrDefault();
                scimUser.Schemas  = new string[] { "urn:ietf:params:scim:schemas:core:2.0:User" };
                scimUser.Roles    = new string[] { };
                scimUser.UserType = "ScimUser";

                JArray jArray = (JArray)jObject["Operations"];
                foreach (JObject jo in jArray)
                {
                    var operation = (string)jo["op"];
                    var path      = (string)jo["path"];
                    var value     = (string)jo["value"];
                    switch (operation)
                    {
                    case "Add":
                        switch (path)
                        {
                        case "displayName":
                            scimUser.DisplayName = value;
                            break;

                        case "emails[type eq \"work\"].value":
                            var newScimUserEmail = new ScimUserEmail
                            {
                                Type       = "work",
                                Primary    = false,
                                Value      = value,
                                ScimUserId = scimUser.ScimUserId,
                                ScimUser   = scimUser
                            };
                            _applicationDbContext.scimUserEmails.Add(newScimUserEmail);
                            break;
                        }

                        break;

                    case "Replace":
                        switch (path)
                        {
                        case "active":
                            var boolean = (bool)jo["value"];
                            scimUser.Active = boolean;
                            break;
                        }
                        break;
                    }
                }
                var scimUserMeta = _applicationDbContext.scimUserMetaDatas.Where(sum => sum.ScimUserId == scimUser.ScimUserId).FirstOrDefault();
                var lastModified = DateTime.UtcNow;
                var varsion      = CommonFunctions.GetSHA256HashedString(lastModified.ToString());
                var etag         = "W/\"" + varsion + "\"";
                scimUserMeta.LastModified = lastModified;
                scimUserMeta.Version      = etag;

                _applicationDbContext.scimUsers.Update(scimUser);
                _applicationDbContext.scimUserMetaDatas.Update(scimUserMeta);
                _applicationDbContext.SaveChanges();


                var updatedScimUser = _applicationDbContext.scimUsers.Where(su => su.ApplicationUserId == id).FirstOrDefault();

                updatedScimUser.Schemas = new string[] { "urn:ietf:params:scim:schemas:core:2.0:User" };
                updatedScimUser.Roles   = new string[] { };

                var updatedScimUserName        = _applicationDbContext.scimUserNames.Where(sun => sun.ScimUserId == scimUser.ScimUserId).FirstOrDefault();
                var updatedScimUserPhoneNumber = _applicationDbContext.scimUserPhoneNumbers.Where(sup => sup.ScimUserId == scimUser.ScimUserId).ToList();
                var updatedScimUserEmail       = _applicationDbContext.scimUserEmails.Where(sue => sue.ScimUserId == scimUser.ScimUserId).ToList();
                var updatedScimUserMetaData    = _applicationDbContext.scimUserMetaDatas.Where(sum => sum.ScimUserId == scimUser.ScimUserId).FirstOrDefault();

                updatedScimUser.Name         = updatedScimUserName;
                updatedScimUser.PhoneNumbers = updatedScimUserPhoneNumber;
                updatedScimUser.Emails       = updatedScimUserEmail;
                updatedScimUser.Meta         = updatedScimUserMetaData;

                var returnedUserJobject = CreateScimUserJobject(scimUser);

                Response.Headers.Add("Location", scimUser.Meta.Location);
                Response.Headers.Add("Etag", scimUser.Meta.Version);
                Response.Headers.Add("Content-Type", "application/scim+json");

                return(Ok(returnedUserJobject));
            }
            catch (Exception exception)
            {
                var errorJobject = CommonFunctions.CreateErrorJobject(exception);
                Response.Headers.Add("Content-Type", "application/scim+json");

                return(StatusCode(StatusCodes.Status500InternalServerError, errorJobject));
            }
        }