public LdapSaveSyncOperation(LdapSettings settings, Tenant tenant, LdapOperationType operation, LdapLocalization resource = null) : base(settings, tenant, operation, resource) { _ldapChanges = new LdapChangeCollection { Tenant = tenant }; }
public LdapSaveSyncOperation(LdapSettings settings, Tenant tenant, LdapOperationType operation, LdapLocalization resource = null, string userId = null) : base(settings, tenant, operation, resource) { _ldapChanges = new LdapChangeCollection { Tenant = tenant }; _currentUser = userId != null?CoreContext.UserManager.GetUsers(Guid.Parse(userId)) : null; }
private UserInfo SyncLDAPUser(UserInfo ldapUserInfo, List <UserInfo> ldapUsers, out LdapChangeCollection changes, bool onlyGetChanges = false) { UserInfo result; changes = new LdapChangeCollection(); UserInfo userToUpdate; var userBySid = CoreContext.UserManager.GetUserBySid(ldapUserInfo.Sid); if (Equals(userBySid, Constants.LostUser)) { var userByEmail = CoreContext.UserManager.GetUserByEmail(ldapUserInfo.Email); if (Equals(userByEmail, Constants.LostUser)) { if (ldapUserInfo.Status != EmployeeStatus.Active) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } _log.DebugFormat("SyncUserLDAP(SID: {0}, Username: '******') ADD failed: Status is {2}", ldapUserInfo.Sid, ldapUserInfo.UserName, Enum.GetName(typeof(EmployeeStatus), ldapUserInfo.Status)); return(Constants.LostUser); } if (!TryAddLDAPUser(ldapUserInfo, onlyGetChanges, out result)) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } return(Constants.LostUser); } if (onlyGetChanges) { changes.SetAddUserChange(result, _log); } return(result); } if (userByEmail.IsLDAP()) { if (ldapUsers == null || ldapUsers.Any(u => u.Sid.Equals(userByEmail.Sid))) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } _log.DebugFormat( "SyncUserLDAP(SID: {0}, Username: '******') ADD failed: Another ldap user with email '{2}' already exists", ldapUserInfo.Sid, ldapUserInfo.UserName, ldapUserInfo.Email); return(Constants.LostUser); } } userToUpdate = userByEmail; } else { userToUpdate = userBySid; } UpdateLdapUserContacts(ldapUserInfo, userToUpdate.Contacts); if (!NeedUpdateUser(userToUpdate, ldapUserInfo)) { if (onlyGetChanges) { changes.SetNoneUserChange(ldapUserInfo); } return(userBySid); } if (!TryUpdateUserWithLDAPInfo(userToUpdate, ldapUserInfo, onlyGetChanges, out result)) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } return(Constants.LostUser); } if (onlyGetChanges) { changes.SetUpdateUserChange(ldapUserInfo, result, _log); } return(result); }
public UserInfo GetLDAPSyncUserChange(UserInfo ldapUserInfo, List <UserInfo> ldapUsers, out LdapChangeCollection changes) { return(SyncLDAPUser(ldapUserInfo, ldapUsers, out changes, true)); }
private UserInfo SyncLDAPUser(UserInfo ldapUserInfo, List <UserInfo> ldapUsers, out LdapChangeCollection changes, bool onlyGetChanges = false) { UserInfo result; changes = new LdapChangeCollection(); UserInfo userToUpdate; var userBySid = CoreContext.UserManager.GetUserBySid(ldapUserInfo.Sid); if (Equals(userBySid, Constants.LostUser)) { var userByEmail = CoreContext.UserManager.GetUserByEmail(ldapUserInfo.Email); if (Equals(userByEmail, Constants.LostUser)) { if (ldapUserInfo.Status != EmployeeStatus.Active) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } _log.DebugFormat("SyncUserLDAP(SID: {0}, Username: '******') ADD failed: Status is {2}", ldapUserInfo.Sid, ldapUserInfo.UserName, Enum.GetName(typeof(EmployeeStatus), ldapUserInfo.Status)); return(Constants.LostUser); } if (!TryAddLDAPUser(ldapUserInfo, onlyGetChanges, out result)) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } return(Constants.LostUser); } if (onlyGetChanges) { changes.SetAddUserChange(result, _log); } if (!onlyGetChanges && LdapSettings.Load().SendWelcomeEmail&& (ldapUserInfo.ActivationStatus != EmployeeActivationStatus.AutoGenerated)) { var client = LdapNotifyHelper.StudioNotifyClient; var confirmLink = CommonLinkUtility.GetConfirmationUrl(ldapUserInfo.Email, ConfirmType.EmailActivation); client.SendNoticeToAsync( NotifyConstants.ActionLdapActivation, null, new[] { new DirectRecipient(ldapUserInfo.Email, null, new[] { ldapUserInfo.Email }, false) }, new[] { ASC.Core.Configuration.Constants.NotifyEMailSenderSysName }, null, new TagValue(NotifyConstants.TagUserName, ldapUserInfo.DisplayUserName()), new TagValue(NotifyConstants.TagUserEmail, ldapUserInfo.Email), new TagValue(NotifyConstants.TagMyStaffLink, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetMyStaff())), NotifyConstants.TagGreenButton(Resource.NotifyButtonJoin, confirmLink), new TagValue(NotifyCommonTags.WithoutUnsubscribe, true)); } return(result); } if (userByEmail.IsLDAP()) { if (ldapUsers == null || ldapUsers.Any(u => u.Sid.Equals(userByEmail.Sid))) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } _log.DebugFormat( "SyncUserLDAP(SID: {0}, Username: '******') ADD failed: Another ldap user with email '{2}' already exists", ldapUserInfo.Sid, ldapUserInfo.UserName, ldapUserInfo.Email); return(Constants.LostUser); } } userToUpdate = userByEmail; } else { userToUpdate = userBySid; } UpdateLdapUserContacts(ldapUserInfo, userToUpdate.Contacts); if (!NeedUpdateUser(userToUpdate, ldapUserInfo)) { _log.DebugFormat("SyncUserLDAP(SID: {0}, Username: '******') No need to update, skipping", ldapUserInfo.Sid, ldapUserInfo.UserName); if (onlyGetChanges) { changes.SetNoneUserChange(ldapUserInfo); } return(userBySid); } _log.DebugFormat("SyncUserLDAP(SID: {0}, Username: '******') Userinfo is outdated, updating", ldapUserInfo.Sid, ldapUserInfo.UserName); if (!TryUpdateUserWithLDAPInfo(userToUpdate, ldapUserInfo, onlyGetChanges, out result)) { if (onlyGetChanges) { changes.SetSkipUserChange(ldapUserInfo); } return(Constants.LostUser); } if (onlyGetChanges) { changes.SetUpdateUserChange(ldapUserInfo, result, _log); } return(result); }