public override void Sync()
        {
            var mappedFields = fullProfileSyncService.Fields.ToList();

            if (mappedFields.Count <= 0)
            {
                return;
            }

            var externalFields     = new List <string>();
            var externalUsersCount = 0;
            var internalFields     = new List <string>();
            var missingUserCount   = 0;
            var missingUsers       = new List <string>();
            var nextIndex          = 0;

            SplitMappedFields(mappedFields, internalFields, externalFields);

            do
            {
                var externalUsers = fullProfileSyncService.List(ref nextIndex);
                externalUsersCount += externalUsers.Count;

                if (externalUsers.Count <= 0)
                {
                    break;
                }

                // sync every external user
                foreach (var externalUser in externalUsers)
                {
                    var internalApiUser = PublicApi.Users.Get(new UsersGetOptions {
                        Email = externalUser.Email
                    });
                    if (internalApiUser != null)
                    {
                        var internalUser = InitInternalUser(internalApiUser);
                        MergeAndUpdate(internalUser, internalFields, externalUser, externalFields, mappedFields);
                    }
                    else
                    {
                        if (missingUsers.Count < 100)
                        {
                            missingUsers.Add(externalUser.Email);
                        }
                        missingUserCount++;
                    }
                }
            } while (true);

            SPLog.Info(string.Format("Profile Sync found {0} SharePoint user(s)", externalUsersCount));

            if (missingUsers.Count > 0)
            {
                SPLog.Event(string.Format("Profile Sync could not find following Evolution user(s) {0}. Total not found: {1}", string.Join(", ", missingUsers.ToArray()), missingUserCount));
            }

            UpdateLastRunStatus(Status.Succeeded);
        }
예제 #2
0
        public List <User> List(ref int nextIndex)
        {
            var users = new List <User>();

            try
            {
                GetUserProfileByIndexResult userInstance;
                if (nextIndex <= 0)
                {
                    // start index for the Profile Web Service
                    nextIndex = -1;
                }

                do
                {
                    userInstance = farmUserProfileService.GetUserProfileByIndex(nextIndex);
                    if (userInstance == null || userInstance.UserProfile == null)
                    {
                        continue;
                    }

                    try
                    {
                        var user = new SPFarmUser(syncSettings.SPFarmUserIdFieldName, syncSettings.SPFarmUserEmailFieldName, userInstance.UserProfile);
                        InitUserFields(user, userInstance.UserProfile);
                        if (!string.IsNullOrEmpty(user.Email))
                        {
                            users.Add(user);
                        }
                    }
                    catch (Exception ex)
                    {
                        SPLog.Event(string.Format("Error : {0} FieldCount: {1} Fields: {2}",
                                                  ex.Message,
                                                  userInstance.UserProfile.Length,
                                                  ProfileFieldDump(userInstance.UserProfile)));
                    }

                    var nextValue = userInstance.NextValue ?? string.Empty;

                    if (!int.TryParse(nextValue.Replace(",", ""), out nextIndex))
                    {
                        SPLog.Event(string.Format("Error with next index : {0}", nextValue));
                    }
                }while (userInstance != null && userInstance.UserProfile != null && users.Count < userProfileBatchCapacity);
            }
            catch (Exception ex)
            {
                SPLog.UserProfileUpdated(ex, string.Format("FarmUserProfileService.List() Failed: {0} {1}", ex.Message, ex.StackTrace));
            }
            return(users);
        }
예제 #3
0
        public List <User> List(DateTime date)
        {
            var users = new List <User>();

            try
            {
                var changeToken    = new UserProfileChangeToken();
                var profileChanges = farmUserProfileChangeService.GetChanges(string.Empty, new UserProfileChangeQuery
                {
                    ChangeTokenStart = changeToken,
                    Add                 = true,
                    Update              = true,
                    UserProfile         = true,
                    SingleValueProperty = true,
                    MultiValueProperty  = true,
                });

                var accNameList = profileChanges.Changes.Where(ch => ch.EventTime >= date).GroupBy(d => d.UserAccountName).Select(gr => gr.Key).ToList();

                foreach (var accName in accNameList)
                {
                    try
                    {
                        var userProfileData = farmUserProfileService.GetUserProfileByName(accName);
                        var user            = new SPFarmUser(syncSettings.SPFarmUserIdFieldName, syncSettings.SPFarmUserEmailFieldName, userProfileData);

                        InitUserFields(user, userProfileData);

                        if (!string.IsNullOrEmpty(user.Email))
                        {
                            users.Add(user);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("could not be found"))
                        {
                            SPLog.Event(string.Format("User with account name {0} could not be found in SharePoint.", accName)); continue;
                        }

                        SPLog.UserProfileUpdated(ex, string.Format("FarmUserProfileService.GetUserProfileByName() Failed: {0} {1}", ex.Message, ex.StackTrace));
                    }
                }
            }
            catch (Exception ex)
            {
                SPLog.UserProfileUpdated(ex, string.Format("FarmUserProfileService.List() Failed: {0} {1}", ex.Message, ex.StackTrace));
            }

            return(users);
        }
        private void EventsAfterDelete(DocumentAfterDeleteEventArgs e)
        {
            if (contentStateChanges != null)
            {
                contentStateChanges.Deleted(e.ContentId);
            }

            try
            {
                TEApi.Search.Delete(e.ContentId.ToString());
            }
            catch (Exception)
            {
                SPLog.Event(string.Format("Warning: Could not remove index for {0}", e.ContentId));
            }
        }
예제 #5
0
        public void SignOut()
        {
            try
            {
                var requestMessage = WSFederationMessage.CreateFromUri(HttpContext.Current.Request.Url) as SignOutRequestMessage;
                if (requestMessage == null)
                {
                    return;
                }

                FederatedPassiveSecurityTokenServiceOperations.ProcessSignOutRequest(requestMessage, HttpContext.Current.User, requestMessage.Reply, HttpContext.Current.Response);
            }
            catch (Exception)
            {
                SPLog.Event("SAML Authentication SignOut failed or FedAuth cookie expired.");
            }
        }
예제 #6
0
        /// <summary>
        /// Returns the correct spacing for a user property. The InProcess API properties contain whitespace and the REST API properties do not.
        /// </summary>
        /// <param name="user">Api user</param>
        /// <param name="field">Field name for lookup</param>
        /// <returns>Field name with proper spacing</returns>
        private static string GetFieldName(ApiUser user, string field)
        {
            if (user == null || field.Equals(AvatarUrlField, StringComparison.OrdinalIgnoreCase))
            {
                return(string.Empty);
            }

            var profileField = user.ProfileFields.FirstOrDefault(pf => String.Equals(field, pf.Label.Replace(" ", string.Empty), StringComparison.InvariantCultureIgnoreCase));

            if (profileField != null)
            {
                return(profileField.Label);
            }

            SPLog.Event(String.Format("Could Not Locate Field Name ({0}) for User({1}).", field, user.Id ?? -1));
            return(string.Empty);
        }
예제 #7
0
        public List <User> List(IEnumerable <string> emails)
        {
            // Load account names using spcontext
            var accNameList = new List <string>();
            var web         = spcontext.Site.RootWeb;

            foreach (var camlQuery in CamlQueryBuilder(emails.ToArray(), userProfileBatchCapacity, syncSettings.SPUserEmailFieldName))
            {
                var spuserCollection = web.SiteUserInfoList.GetItems(new CamlQuery {
                    ViewXml = camlQuery
                });
                spcontext.Load(spuserCollection, uList => uList.Include(u => u["Name"]));
                spcontext.ExecuteQuery();
                accNameList.AddRange(from spuser in spuserCollection where spuser["Name"] != null select spuser["Name"].ToString());
            }

            var users = new List <User>();

            foreach (var accName in accNameList)
            {
                try
                {
                    var userProfileData = farmUserProfileService.GetUserProfileByName(accName);
                    var user            = new SPFarmUser(syncSettings.SPFarmUserIdFieldName, syncSettings.SPFarmUserEmailFieldName, userProfileData);

                    InitUserFields(user, userProfileData);

                    if (!string.IsNullOrEmpty(user.Email))
                    {
                        users.Add(user);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("could not be found") || ex.StackTrace.Contains("could not be found"))
                    {
                        SPLog.Event(string.Format("User with account name {0} could not be found in SharePoint.", accName));
                        continue;
                    }

                    SPLog.UserProfileUpdated(ex, string.Format("FarmUserProfileService.GetUserProfileByName() Failed: {0} {1}", ex.Message, ex.StackTrace));
                }
            }
            return(users);
        }
예제 #8
0
        public bool SignIn()
        {
            try
            {
                SecurityTokenService sts = new TelligentSTS(Configuration);

                var requestMessage  = WSFederationMessage.CreateFromUri(HttpContext.Current.Request.Url) as SignInRequestMessage;
                var responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, HttpContext.Current.User, sts);

                FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(responseMessage, HttpContext.Current.Response);
            }
            catch (Exception)
            {
                SPLog.Event("SAML Authentication SignIn failed or FedAuth cookie expired.");
            }

            return(true);
        }
        private DateTime GetAndResetLastRunTime()
        {
            DateTime?lastUpdatedUtcDate = null;

            try
            {
                Status syncStatus;

                if (ProfileSyncController.GetLastRunTime(InternalProviderId, out lastUpdatedUtcDate, out syncStatus) && syncStatus == Status.Succeeded)
                {
                    ProfileSyncController.ResetLastRunTime(InternalProviderId, Status.InProgress);
                }
                else
                {
                    ProfileSyncController.SetLastRunStatus(InternalProviderId, Status.InProgress);
                }
            }
            catch (Exception)
            {
                SPLog.Event("Cound not get last Profile Incremental Sync time, using default.");
            }

            return(lastUpdatedUtcDate ?? DefaultLastRunTime());
        }