/// <summary> /// SetSharedUserData method implementation /// </summary> internal void SetSharedUserData(MFAUserList registrations) { if (usersFormView == null) { return; } WritableSharedDataItem shareddata = usersFormView.SharedUserData.GetItem("@adfsmfa_useredit" + seed); if (shareddata == null) { return; } if (registrations == null) { registrations = (MFAUserList)this.ParentSheet.SelectionObject; if (registrations == null) { registrations = new MFAUserList(); MFAUser reg = new MFAUser { Enabled = true }; registrations.Add(reg); } } shareddata.SetData(registrations); }
/// <summary> /// DisableUser method implmentation /// </summary> public static MFAUserList DisableUser(MFAUserList registrations) { EnsureService(); MFAUserList lst = new MFAUserList(); foreach(MFAUser reg in registrations) { lst.Add(ManagementService.DisableUserRegistration(reg)); } return lst; }
/// <summary> /// AddUser method implmentation /// </summary> public static MFAUserList AddUser(MFAUserList registrations) { EnsureService(); MFAUserList lst = new MFAUserList(); foreach (MFAUser reg in registrations) { lst.Add(ManagementService.AddUserRegistration(reg, false, false, false)); } return(lst); }
/// <summary> /// GetUser method implementation /// </summary> internal static MFAUserList GetUser(MFAUserList registrations) { EnsureService(); MFAUserList lst = new MFAUserList(); foreach(MFAUser reg in registrations) { MFAUser ret = ManagementService.GetUserRegistration(reg.UPN); lst.Add(ret); } return lst; }
/// <summary> /// GetSelectedUsers method implementation /// </summary> internal MFAUserList GetSelectedUsers() { MFAUserList result = new MFAUserList(); foreach (DataGridViewRow row in GridView.SelectedRows) { MFAUser reg = new MFAUser(); reg.ID = GridView.Rows[row.Index].Cells[1].Value.ToString(); if (reg.ID != Guid.Empty.ToString()) { reg.UPN = GridView.Rows[row.Index].Cells[2].Value.ToString(); reg.MailAddress = GridView.Rows[row.Index].Cells[3].Value.ToString(); reg.PhoneNumber = GridView.Rows[row.Index].Cells[4].Value.ToString(); reg.PreferredMethod = (PreferredMethod)Enum.Parse(typeof(PreferredMethod), GridView.Rows[row.Index].Cells[5].Value.ToString()); reg.Enabled = (bool)bool.Parse(GridView.Rows[row.Index].Cells[6].Value.ToString()); result.Add(reg); } } return(result); }
/// <summary> /// ImportMFAUsers method implementation /// </summary> public virtual MFAUserList ImportMFAUsers(string domain, string username, string password, string ldappath, DateTime?created, DateTime?modified, string mailattribute, string phoneattribute, PreferredMethod meth, bool usessl, bool disableall = false) { if (!string.IsNullOrEmpty(ldappath)) { ldappath = ldappath.Replace("ldap://", ""); ldappath = ldappath.Replace("ldaps://", ""); ldappath = ldappath.Replace("LDAP://", ""); ldappath = ldappath.Replace("LDAPS://", ""); } MFAUserList registrations = new MFAUserList(); try { using (DirectoryEntry rootdir = ADDSUtils.GetDirectoryEntry(domain, username, password, ldappath, usessl)) { string qryldap = string.Empty; qryldap = "(&"; qryldap += "(objectCategory=user)(objectClass=user)" + ClaimsUtilities.BuildADDSUserFilter("*"); if (created.HasValue) { qryldap += "(whenCreated>=" + created.Value.ToString("yyyyMMddHHmmss.0Z") + ")"; } if (modified.HasValue) { qryldap += "(whenChanged>=" + modified.Value.ToString("yyyyMMddHHmmss.0Z") + ")"; } qryldap += ")"; using (DirectorySearcher dsusr = new DirectorySearcher(rootdir, qryldap)) { dsusr.PropertiesToLoad.Clear(); dsusr.PropertiesToLoad.Add("objectGUID"); dsusr.PropertiesToLoad.Add("userPrincipalName"); dsusr.PropertiesToLoad.Add("sAMAccountName"); dsusr.PropertiesToLoad.Add("msDS-PrincipalName"); dsusr.PropertiesToLoad.Add("userAccountControl"); if (!string.IsNullOrEmpty(mailattribute)) { dsusr.PropertiesToLoad.Add(mailattribute); } else { dsusr.PropertiesToLoad.Add("mail"); dsusr.PropertiesToLoad.Add("otherMailbox"); } if (!string.IsNullOrEmpty(phoneattribute)) { dsusr.PropertiesToLoad.Add(phoneattribute); } else { dsusr.PropertiesToLoad.Add("mobile"); dsusr.PropertiesToLoad.Add("otherMobile"); dsusr.PropertiesToLoad.Add("telephoneNumber"); } dsusr.SizeLimit = 0; // _host.MaxRows; SearchResultCollection src = dsusr.FindAll(); if (src != null) { foreach (SearchResult sr in src) { MFAUser reg = new MFAUser(); using (DirectoryEntry DirEntry = ADDSUtils.GetDirectoryEntry(domain, username, password, sr, usessl)) { if (DirEntry.Properties["objectGUID"].Value != null) { reg.ID = new Guid((byte[])DirEntry.Properties["objectGUID"].Value).ToString(); if (sr.Properties[ClaimsUtilities.GetADDSUserAttribute()][0] != null) { reg.UPN = sr.Properties[ClaimsUtilities.GetADDSUserAttribute()][0].ToString(); if (!string.IsNullOrEmpty(mailattribute)) { if (DirEntry.Properties[mailattribute].Value != null) { reg.MailAddress = DirEntry.Properties[mailattribute].Value.ToString(); } } else { if (DirEntry.Properties["otherMailbox"].Value != null) { reg.MailAddress = DirEntry.Properties["otherMailbox"].Value.ToString(); } else if (DirEntry.Properties["mail"].Value != null) { reg.MailAddress = DirEntry.Properties["mail"].Value.ToString(); } } if (!string.IsNullOrEmpty(phoneattribute)) { if (DirEntry.Properties[phoneattribute].Value != null) { reg.PhoneNumber = DirEntry.Properties[phoneattribute].Value.ToString(); } } else { if (DirEntry.Properties["mobile"].Value != null) { reg.PhoneNumber = DirEntry.Properties["mobile"].Value.ToString(); } else if (DirEntry.Properties["otherMobile"].Value != null) { reg.PhoneNumber = DirEntry.Properties["otherMobile"].Value.ToString(); } else if (DirEntry.Properties["telephoneNumber"].Value != null) { reg.PhoneNumber = DirEntry.Properties["telephoneNumber"].Value.ToString(); } } reg.PreferredMethod = meth; reg.OverrideMethod = string.Empty; if (disableall) { reg.Enabled = false; } else if (DirEntry.Properties["userAccountControl"] != null) { int v = Convert.ToInt32(DirEntry.Properties["userAccountControl"].Value); reg.Enabled = ((v & 2) == 0); } else { reg.Enabled = true; } registrations.Add(reg); } } }; } } } } } catch (Exception ex) { DataLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5100); throw new Exception(ex.Message); } return(registrations); }