Esempio n. 1
0
        internal bool TryUpdateUser(string userId, IList <ClaimInfo> claims)
        {
            var user = userDataAccess.GetUser(userId);

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

            var isInternal = controllerHelper.IsInternalUser();
            var mgntRole   = controllerHelper.GetMgntRoleFromClaim();

            try
            {
                var userDataOnLogin = new User
                {
                    Id             = userId,
                    IsInternalUser = isInternal,
                    EiamRoles      = mgntRole,
                    UserExtId      = controllerHelper.GetFromClaim("/identity/claims/e-id/userExtId"),
                    Claims         = new JObject {
                        { "claims", JArray.FromObject(claims) }
                    },
                    FamilyName   = isInternal ? controllerHelper.GetFromClaim("/identity/claims/surname") : user.FamilyName,
                    FirstName    = isInternal ? controllerHelper.GetFromClaim("/identity/claims/givenname") : user.FirstName,
                    EmailAddress = isInternal ? controllerHelper.GetFromClaim("/identity/claims/emailaddress") : user.EmailAddress
                };

                // Prüfen User Änderung enthält, falls ja Daten aktualisieren
                if (HasUserChanges(userDataOnLogin, user))
                {
                    userDataAccess.UpdateUserOnLogin(userDataOnLogin, userId, loginSystem);
                }

                // Falls der Benutzer für M-C berechtigt ist, soll die Standardrolle zugewiesen werden
                if (!string.IsNullOrWhiteSpace(mgntRole) && mgntRole.Equals(AccessRoles.RoleMgntAllow))
                {
                    applicationRoleUserDataAccess.InsertRoleUser(roleIdentifier, userId);
                }
                else if (string.IsNullOrWhiteSpace(mgntRole))
                {
                    applicationRoleUserDataAccess.RemoveRolesUser(userId, roleIdentifier);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Could not insert or update user on signin");
            }

            return(true);
        }