Esempio n. 1
0
        /// <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>
        /// DeleteUser method implmentation
        /// </summary>
        public static bool DeleteUser(MFAUserList registrations)
        {
            EnsureService();
            bool _ret = true;

            foreach(MFAUser reg in registrations)
            {
                bool tmp = ManagementService.DeleteUserRegistration(reg);
                if (!tmp)
                    _ret = false;
            }
            return _ret;
        }
        /// <summary>
        /// BTNReinit_Click event
        /// </summary>
        private void BTNReinit_Click(object sender, EventArgs e)
        {
            MFAUserList lst = userPropertyPage.GetSharedUserData();

            foreach (MFAUser reg in lst)
            {
                MMCService.NewUserKey(reg.UPN);
            }
            if (!SyncDisabled)
            {
                userPropertyPage.SyncSharedUserData(this, true);
            }
        }
 /// <summary>
 /// SetUserControlData method implementation
 /// </summary>
 public void SetUserControlData(MFAUserList lst, bool disablesync)
 {
     SyncDisabled = disablesync;
     try
     {
         MFAUser obj = lst[0];
         _upn = obj.UPN;
         BuildKeysControl();
         UpdateControlsEnabled();
     }
     finally
     {
         SyncDisabled = false;
     }
 }
Esempio n. 5
0
        /// <summary>
        /// SetUserControlData method implmentation
        /// </summary>
        public void SetUserControlData(MFAUserList lst, bool disablesync)
        {
            SyncDisabled = disablesync;
            try
            {
                MFAUser obj = lst[0];
                _upn       = obj.UPN;
                _email     = obj.MailAddress;
                _secretkey = MMCService.GetEncodedUserKey(obj.UPN);

                if (string.IsNullOrEmpty(_email))
                {
                    this.EmailPrompt.Text = "Email : ";
                    _emailnotset          = true;
                }
                else
                {
                    this.EmailPrompt.Text = string.Format("Email : {0}", _email);
                    _emailnotset          = false;
                }
                if (!string.IsNullOrEmpty(_secretkey))
                {
                    this.DisplayKey.Text = _secretkey;
                    if (!string.IsNullOrEmpty(_upn))
                    {
                        this.qrCodeGraphic.Text = MMCService.GetQRCodeValue(_upn, this.DisplayKey.Text);
                    }
                    else
                    {
                        this.qrCodeGraphic.Text = string.Empty;
                    }
                }
                else
                {
                    userPropertyPage.Dirty = true;
                }
                UpdateControlsEnabled();
            }
            catch (Exception)
            {
                this.DisplayKey.Text    = string.Empty;
                this.qrCodeGraphic.Text = string.Empty;
            }
            finally
            {
                SyncDisabled = false;
            }
        }
        /// <summary>
        /// OnAddPropertyPages method implementation
        /// </summary>
        protected override void OnAddPropertyPages(PropertyPageCollection propertyPageCollection)
        {
            Random      rand          = new Random();
            int         i             = rand.Next();
            MFAUserList registrations = (MFAUserList)SelectionData.SelectionObject;

            if (registrations.Count > 1)
            {
                propertyPageCollection.Add(new UserPropertyPage(this, typeof(UserCommonPropertiesControl), i));
            }
            else
            {
                propertyPageCollection.Add(new UserPropertyPage(this, typeof(UserPropertiesControl), i));
                propertyPageCollection.Add(new UserPropertyPage(this, typeof(UserPropertiesKeysControl), i));
            }
        }
 /// <summary>
 /// SetData method implmentation
 /// </summary>
 public void SetUserControlData(MFAUserList lst, bool disablesync)
 {
     SyncDisabled = disablesync;
     try
     {
         MFAUser obj = ((MFAUserList)lst)[0];
         this.UserName.Text          = ((MFAUser)obj).UPN;
         this.Email.Text             = ((MFAUser)obj).MailAddress;
         this.Phone.Text             = ((MFAUser)obj).PhoneNumber;
         this.cbEnabled.Checked      = ((MFAUser)obj).Enabled;
         this.CBMethod.SelectedValue = (PreferredMethod)(((MFAUser)obj).PreferredMethod);
     }
     finally
     {
         SyncDisabled = false;
     }
 }
        /// <summary>
        /// _delete_Click event
        /// </summary>
        private void _delete_Click(object sender, EventArgs e)
        {
            MessageBoxParameters messageBoxParameters = new MessageBoxParameters
            {
                Caption       = "Multi-Factor Authentication",
                Buttons       = MessageBoxButtons.YesNo,
                DefaultButton = MessageBoxDefaultButton.Button1,
                Icon          = MessageBoxIcon.Question,
                Text          = res.USERSFRMCONFIRMDELETE
            };

            if (this.SnapIn.Console.ShowDialog(messageBoxParameters) == DialogResult.Yes)
            {
                MFAUserList reg  = (MFAUserList)SelectionData.SelectionObject;
                bool        xres = DeleteUserStoreData(reg);
            }
        }
        /// <summary>
        /// RefreshData method implmentation
        /// </summary>
        public void RefreshData(bool refreshgrid = false, bool clearselection = false)
        {
            this.UseWaitCursor = true;
            this.Cursor        = Cursors.WaitCursor;
            ComponentResourceManager resources = new ComponentResourceManager(typeof(UsersListView));

            this.uPNDataGridViewTextBoxColumn.HeaderText             = resources.GetString("uPNDataGridViewTextBoxColumn.HeaderText");
            this.mailAddressDataGridViewTextBoxColumn.HeaderText     = resources.GetString("mailAddressDataGridViewTextBoxColumn.HeaderText");
            this.phoneNumberDataGridViewTextBoxColumn.HeaderText     = resources.GetString("phoneNumberDataGridViewTextBoxColumn.HeaderText");
            this.preferredMethodDataGridViewTextBoxColumn.HeaderText = resources.GetString("preferredMethodDataGridViewTextBoxColumn.HeaderText");
            this.enabledDataGridViewCheckBoxColumn.HeaderText        = resources.GetString("enabledDataGridViewCheckBoxColumn.HeaderText");
            try
            {
                _lst = MMCService.GetUsers();
                if (clearselection)
                {
                    GridView.RowCount = 0;
                }
                // GridView.RowCount = _lst.Count;
                GridView.RowCount = MMCService.GetUsersCount();
                if (refreshgrid)
                {
                    GridView.Refresh();
                }
                if (clearselection)
                {
                    GridView.ClearSelection();
                }
            }
            catch (Exception ex)
            {
                MessageBoxParameters messageBoxParameters = new MessageBoxParameters
                {
                    Text    = ex.Message,
                    Buttons = MessageBoxButtons.OK,
                    Icon    = MessageBoxIcon.Error
                };
                SnapIn.Console.ShowDialog(messageBoxParameters);
            }
            finally
            {
                UseWaitCursor = false;
                Cursor        = Cursors.Default;
            }
        }
 /// <summary>
 /// DisableUserData method implementation
 /// </summary>
 internal void DisableUserData(MFAUserList registrations)
 {
     try
     {
         MFAUserList results = MMCService.DisableUser(registrations);
         EnableDisableRows(results);
     }
     catch (Exception ex)
     {
         MessageBoxParameters messageBoxParameters = new MessageBoxParameters
         {
             Text    = ex.Message,
             Buttons = MessageBoxButtons.OK,
             Icon    = MessageBoxIcon.Error
         };
         SnapIn.Console.ShowDialog(messageBoxParameters);
     }
 }
        /// <summary>
        /// SyncSharedUserData method implementation
        /// </summary>
        internal virtual void SyncSharedUserData(IUserPropertiesDataObject control, bool isdirty)
        {
            if (usersFormView == null)
            {
                return;
            }
            MFAUserList registrations = GetSharedUserData();

            userPropertiesControl.GetUserControlData(registrations);
            foreach (MFAUser reg in registrations)
            {
                reg.IsApplied = false;
            }
            SetSharedUserData(registrations);
            if (!Destroyed)
            {
                Dirty = isdirty;
            }
        }
 /// <summary>
 /// DeleteUserData method implementation
 /// </summary>
 internal bool DeleteUserData(MFAUserList registrations)
 {
     try
     {
         bool ret = MMCService.DeleteUser(registrations);
         DeleteRows(registrations);
         return(ret);
     }
     catch (Exception ex)
     {
         MessageBoxParameters messageBoxParameters = new MessageBoxParameters
         {
             Text    = ex.Message,
             Buttons = MessageBoxButtons.OK,
             Icon    = MessageBoxIcon.Error
         };
         SnapIn.Console.ShowDialog(messageBoxParameters);
         return(false);
     }
 }
Esempio n. 13
0
        /// <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>
        /// AddUserStoreData method implementation
        /// </summary>
        internal void AddUserStoreData(object obj)
        {
            MFAUserList reg = null;

            if (obj is MFAUserList)
            {
                reg = (MFAUserList)obj;
                if (UsersListControl != null)
                {
                    this.SelectionData.BeginUpdates();
                    try
                    {
                        UsersListControl.AddUserData(reg);
                    }
                    finally
                    {
                        this.SelectionData.EndUpdates();
                    }
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// EnsurePageForRowIndex method implmentation
        /// </summary>
        private int EnsurePageForRowIndex(int rowindex)
        {
            int idx  = rowindex % MMCService.Paging.PageSize;
            int page = (rowindex / MMCService.Paging.PageSize) + 1;

            if (page != MMCService.Paging.CurrentPage)
            {
                this.UseWaitCursor = true;
                this.Cursor        = Cursors.WaitCursor;
                try
                {
                    MMCService.Paging.CurrentPage = page;
                    _lst = MMCService.GetUsers();
                }
                finally
                {
                    this.UseWaitCursor = false;
                    this.Cursor        = Cursors.Default;
                }
            }
            return(idx);
        }
        /// <summary>
        /// BTNSendByMail_Click event
        /// </summary>
        private void BTNSendByMail_Click(object sender, EventArgs e)
        {
            Cursor crs = this.Cursor;
            int    cnt = 0;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                MFAUserList lst = userPropertyPage.GetSharedUserData();
                foreach (MFAUser reg in lst)
                {
                    string secret = MMCService.GetEncodedUserKey(reg.UPN);
                    MMCService.SendKeyByEmail(reg.MailAddress, reg.UPN, secret);
                    cnt++;
                }
            }
            catch (Exception ex)
            {
                this.Cursor = crs;
                MessageBoxParameters messageBoxParameters = new MessageBoxParameters
                {
                    Text    = ex.Message,
                    Buttons = MessageBoxButtons.OK,
                    Icon    = MessageBoxIcon.Error
                };
                userPropertyPage.ParentSheet.ShowDialog(messageBoxParameters);
            }
            finally
            {
                this.Cursor = crs;
                MessageBoxParameters messageBoxParameters = new MessageBoxParameters
                {
                    Text    = string.Format(errors_strings.InfosSendingMails, cnt),
                    Buttons = MessageBoxButtons.OK,
                    Icon    = MessageBoxIcon.Information
                };
                userPropertyPage.ParentSheet.ShowDialog(messageBoxParameters);
            }
        }
 /// <summary>
 /// SetUserControlData method implementation
 /// </summary>
 public void SetUserControlData(MFAUserList lst, bool disablesync)
 {
     SyncDisabled = disablesync;
     try
     {
         bool isset = false;
         this.listUsers.Items.Clear();
         foreach (MFAUser obj in lst)
         {
             this.listUsers.Items.Add(((MFAUser)obj).UPN);
             if (!isset)
             {
                 this.cbEnabled.Checked      = ((MFAUser)obj).Enabled;
                 this.CBMethod.SelectedValue = (PreferredMethod)(((MFAUser)obj).PreferredMethod);
                 isset = true;
             }
         }
     }
     finally
     {
         SyncDisabled = false;
     }
 }
        /// <summary>
        /// DeleteUserStoreData method implementation
        /// </summary>
        internal bool DeleteUserStoreData(object obj)
        {
            bool        ret = false;
            MFAUserList reg = null;

            if (obj is MFAUserList)
            {
                reg = (MFAUserList)obj;
                if (UsersListControl != null)
                {
                    this.SelectionData.BeginUpdates();
                    try
                    {
                        ret = UsersListControl.DeleteUserData(reg);
                    }
                    finally
                    {
                        this.SelectionData.EndUpdates();
                    }
                }
            }
            return(ret);
        }
Esempio n. 19
0
 /// <summary>
 /// SetUserData method implementation
 /// </summary>
 internal void SetUserData(MFAUserList registrations)
 {
     MMCService.SetUser(registrations);
     UpdateRows(registrations);
 }
        /// <summary>
        /// DoImport() method implmentation
        /// </summary>
        public override bool DoImport()
        {
            char          sep      = Path.DirectorySeparatorChar;
            string        filename = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + sep + "MFA" + sep + "adimport-" + DateTime.Now.ToFileTime().ToString() + ".log";
            TraceListener listen   = InitializeTrace(filename);

            try
            {
                ADDSHost adht = Config.Hosts.ActiveDirectoryHost;
                if (string.IsNullOrEmpty(Parameters.DomainName))
                {
                    Parameters.DomainName = adht.DomainName;
                }
                if (string.IsNullOrEmpty(Parameters.UserName))
                {
                    Parameters.UserName = adht.Account;
                }
                if (string.IsNullOrEmpty(Parameters.Password))
                {
                    Parameters.Password = adht.Password;
                }

                DataRepositoryService client = null;
                switch (Config.StoreMode)
                {
                case DataRepositoryKind.ADDS:
                    client = new ADDSDataRepositoryService(Config.Hosts.ActiveDirectoryHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.SQL:
                    client = new SQLDataRepositoryService(Config.Hosts.SQLServerHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.Custom:
                    client = CustomDataRepositoryActivator.CreateInstance(Config.Hosts.CustomStoreHost, Config.DeliveryWindow);
                    break;
                }

                Trace.WriteLine("");
                Trace.WriteLine(string.Format("Importing for AD : {0}", Parameters.LDAPPath));
                Trace.Indent();
                Trace.WriteLine("Query users from AD");
                MFAUserList lst = client.ImportMFAUsers(Parameters, DisableAll);
                Trace.WriteLine(string.Format("Query returns {0} user(s) from AD", lst.Count.ToString()));

                DataRepositoryService client2 = null;
                switch (Config.StoreMode)
                {
                case DataRepositoryKind.ADDS:
                    Trace.WriteLine("");
                    Trace.WriteLine("Importing ADDS Mode");
                    Trace.Indent();
                    client2 = new ADDSDataRepositoryService(Config.Hosts.ActiveDirectoryHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.SQL:
                    Trace.WriteLine("");
                    Trace.WriteLine("Importing SQL Mode");
                    Trace.Indent();
                    client2 = new SQLDataRepositoryService(Config.Hosts.SQLServerHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.Custom:

                    Trace.WriteLine("");
                    Trace.WriteLine("Importing Custom Store Mode");
                    Trace.Indent();
                    client2 = CustomDataRepositoryActivator.CreateInstance(Config.Hosts.CustomStoreHost, Config.DeliveryWindow);
                    break;
                }
                client2.OnKeyDataEvent += KeyDataEvent;
                foreach (MFAUser reg in lst)
                {
                    try
                    {
                        MFAUser ext = client2.GetMFAUser(reg.UPN);
                        if (ext == null)
                        {
                            reg.PIN             = Convert.ToInt32(Config.DefaultPin);
                            reg.PreferredMethod = Config.DefaultProviderMethod;
                        }
                        else
                        {
                            if (this.Parameters.Method != PreferredMethod.None)
                            {
                                reg.PreferredMethod = this.Parameters.Method;
                            }
                            else
                            {
                                reg.PreferredMethod = ext.PreferredMethod;
                            }
                        }
                        if (reg.PIN <= 0)
                        {
                            reg.PIN = Convert.ToInt32(Config.DefaultPin);
                        }

                        if (!Utilities.ValidateEmail(reg.MailAddress, (Config.MailProvider.Enabled && Config.MailProvider.IsRequired)))
                        {
                            throw new Exception(string.Format("invalid mail address for user : {0}", reg.UPN));
                        }
                        if (!Utilities.ValidatePhoneNumber(reg.PhoneNumber, (Config.ExternalProvider.Enabled && Config.ExternalProvider.IsRequired)))
                        {
                            throw new Exception(string.Format("invalid phone number for user : {0}", reg.UPN));
                        }

                        client2.AddMFAUser(reg, ForceNewKey, true);
                        Trace.TraceInformation(string.Format("User {0} Imported in MFA", reg.UPN));
                        if (!string.IsNullOrEmpty(reg.MailAddress))
                        {
                            if (SendEmail)
                            {
                                string      qrcode = KeysManager.EncodedKey(reg.UPN);
                                CultureInfo info   = null;
                                try
                                {
                                    info = CultureInfo.CurrentUICulture;
                                }
                                catch
                                {
                                    info = new CultureInfo(Config.DefaultCountryCode);
                                }
                                MailUtilities.SendKeyByEmail(reg.MailAddress, reg.UPN, qrcode, Config.MailProvider, Config, info);
                                Trace.TraceInformation(string.Format("Sending Sensitive mail for User {0}", reg.UPN));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorsCount++;
                        Trace.TraceError("Error importing User {0} : {1}", reg.UPN, ex.Message);
                    }
                    finally
                    {
                        RecordsCount++;
                    }
                }
                Trace.Unindent();
                Trace.WriteLine("");
                Trace.WriteLine(string.Format("Imported {0} User(s) from AD Source", RecordsCount));
            }
            catch (Exception ex)
            {
                Trace.Unindent();
                Trace.TraceError(string.Format("Error importing from AD : {0}", ex.Message));
                Log.WriteEntry(string.Format("Error importing from AD : {0}", ex.Message), EventLogEntryType.Error, 20000);
                return(false);
            }
            finally
            {
                Trace.Unindent();
                FinalizeTrace(listen);
            }
            return(true);
        }
Esempio n. 21
0
        /// <summary>
        /// GetUserControlData method implmentation
        /// </summary>
        public MFAUserList GetUserControlData(MFAUserList lst)
        {
            MFAUser obj = lst[0];

            return(lst);
        }
        /// <summary>
        /// _activate_Click event
        /// </summary>
        private void _activate_Click(object sender, EventArgs e)
        {
            MFAUserList reg = (MFAUserList)SelectionData.SelectionObject;

            EnableUserStoreData(reg, true);
        }
Esempio n. 23
0
        /// <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);
        }
Esempio n. 24
0
        /// <summary>
        /// DoImport() method implmentation
        /// </summary>
        public override bool DoImport()
        {
            char          sep      = Path.DirectorySeparatorChar;
            string        filename = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + sep + "MFA" + sep + "adimport-" + DateTime.Now.ToFileTime().ToString() + ".log";
            TraceListener listen   = InitializeTrace(filename);

            try
            {
                ADDSHost adht = Config.Hosts.ActiveDirectoryHost;
                if (string.IsNullOrEmpty(DomainName))
                {
                    DomainName = adht.DomainName;
                }
                if (string.IsNullOrEmpty(UserName))
                {
                    UserName = adht.Account;
                }
                if (string.IsNullOrEmpty(Password))
                {
                    Password = adht.Password;
                }

                DataRepositoryService client = null;
                switch (Config.StoreMode)
                {
                case DataRepositoryKind.ADDS:
                    client = new ADDSDataRepositoryService(Config.Hosts.ActiveDirectoryHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.SQL:
                    client = new SQLDataRepositoryService(Config.Hosts.SQLServerHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.Custom:
                    client = CustomDataRepositoryActivator.CreateInstance(Config.Hosts.CustomStoreHost, Config.DeliveryWindow);
                    break;
                }

                Trace.WriteLine("");
                Trace.WriteLine(string.Format("Importing for AD : {0}", LDAPPath));
                Trace.Indent();
                Trace.WriteLine("Querying users from AD");
                MFAUserList lst = client.ImportMFAUsers(DomainName, UserName, Password, LDAPPath, CreatedSince, ModifiedSince, MailAttribute, PhoneAttribute, Method, Config.Hosts.ActiveDirectoryHost.UseSSL, DisableAll);
                Trace.WriteLine(string.Format("Querying return {0} users from AD", lst.Count.ToString()));

                DataRepositoryService client2 = null;
                switch (Config.StoreMode)
                {
                case DataRepositoryKind.ADDS:
                    Trace.WriteLine("");
                    Trace.WriteLine("Importing ADDS Mode");
                    Trace.Indent();
                    client2 = new ADDSDataRepositoryService(Config.Hosts.ActiveDirectoryHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.SQL:
                    Trace.WriteLine("");
                    Trace.WriteLine("Importing SQL Mode");
                    Trace.Indent();
                    client2 = new SQLDataRepositoryService(Config.Hosts.SQLServerHost, Config.DeliveryWindow);
                    break;

                case DataRepositoryKind.Custom:

                    Trace.WriteLine("");
                    Trace.WriteLine("Importing Custom Store Mode");
                    Trace.Indent();
                    client2 = CustomDataRepositoryActivator.CreateInstance(Config.Hosts.CustomStoreHost, Config.DeliveryWindow);
                    break;
                }
                client2.OnKeyDataEvent += KeyDataEvent;
                foreach (MFAUser reg in lst)
                {
                    Trace.TraceInformation(string.Format("Importing user {0} from AD", reg.UPN));
                    try
                    {
                        MFAUser ext = client2.GetMFAUser(reg.UPN);
                        if (ext == null)
                        {
                            reg.PIN = Config.DefaultPin;
                            client2.AddMFAUser(reg, ForceNewKey, false);
                            Trace.TraceInformation(string.Format("User {0} Imported in MFA", reg.UPN));
                            if (!string.IsNullOrEmpty(reg.MailAddress))
                            {
                                if (SendEmail)
                                {
                                    string      qrcode = KeysManager.EncodedKey(reg.UPN);
                                    CultureInfo info   = null;
                                    try
                                    {
                                        info = CultureInfo.CurrentUICulture;
                                    }
                                    catch
                                    {
                                        info = new CultureInfo(Config.DefaultCountryCode);
                                    }
                                    MailUtilities.SendKeyByEmail(reg.MailAddress, reg.UPN, qrcode, Config.MailProvider, Config, info);
                                    Trace.TraceInformation(string.Format("Sending Sensitive mail for User {0} Imported in MFA", reg.UPN));
                                }
                            }
                            RecordsCount++;
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorsCount++;
                        Trace.TraceError("Error importing Record N° {0} \r\r {1}", (RecordsCount + 1).ToString(), ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(string.Format("Error importing from AD \r\r {0}", ex.Message));
                return(false);
            }
            finally
            {
                Trace.Unindent();
                FinalizeTrace(listen);
            }
            return(true);
        }
Esempio n. 25
0
 public SelectionDataEventArgs(MFAUserList list, MMCListAction action)
 {
     _list   = list;
     _action = action;
 }
 /// <summary>
 /// EnableDisableRows method implementation
 /// </summary>
 private void EnableDisableRows(MFAUserList registrations)
 {
     RefreshData(true);
     DataSelectionChanged?.Invoke(this, new SelectionDataEventArgs(GetSelectedUsers(), MMCListAction.SelectionChanged));
 }
        /// <summary>
        /// DoImport() method implmentation
        /// </summary>
        public override bool DoImport()
        {
            string        filename = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\MFA\\adimport-" + DateTime.Now.ToFileTime().ToString() + ".log";
            TraceListener listen   = InitializeTrace(filename);

            try
            {
                ADDSHost adht = Config.Hosts.ActiveDirectoryHost;
                if (string.IsNullOrEmpty(DomainName))
                {
                    DomainName = adht.DomainName;
                }
                if (string.IsNullOrEmpty(UserName))
                {
                    UserName = adht.Account;
                }
                if (string.IsNullOrEmpty(Password))
                {
                    Password = adht.Password;
                }

                // DataRepositoryService client = new ADDSDataRepositoryService(adht, Config.DeliveryWindow);
                DataRepositoryService client = new ADDSDataRepositoryService(Config.Hosts.ActiveDirectoryHost, Config.Hosts.ActiveDirectoryHost.Account, Config.Hosts.ActiveDirectoryHost.Password, Config.DeliveryWindow);
                Trace.WriteLine("");
                Trace.WriteLine(string.Format("Importing for AD : {0}", LDAPPath));
                Trace.Indent();
                Trace.WriteLine("Querying users from AD");
                MFAUserList lst = client.ImportMFAUsers(DomainName, UserName, Password, LDAPPath, CreatedSince, ModifiedSince, MailAttribute, PhoneAttribute, Method, DisableAll);
                Trace.WriteLine(string.Format("Querying return {0} users from AD", lst.Count.ToString()));

                DataRepositoryService client2 = null;
                if (Config.UseActiveDirectory)
                {
                    Trace.WriteLine("");
                    Trace.WriteLine("Importing ADDS Mode");
                    Trace.Indent();
                    // client2 = new ADDSDataRepositoryService(Config.Hosts.ActiveDirectoryHost, Config.DeliveryWindow);
                    client2 = new ADDSDataRepositoryService(Config.Hosts.ActiveDirectoryHost, Config.Hosts.ActiveDirectoryHost.Account, Config.Hosts.ActiveDirectoryHost.Password, Config.DeliveryWindow);
                }
                else
                {
                    Trace.WriteLine("");
                    Trace.WriteLine("Importing SQL Mode");
                    Trace.Indent();
                    client2 = new SQLDataRepositoryService(Config.Hosts.SQLServerHost, Config.DeliveryWindow);
                }
                client2.OnKeyDataEvent += KeyDataEvent;
                foreach (MFAUser reg in lst)
                {
                    Trace.TraceInformation(string.Format("Importing user {0} from AD", reg.UPN));
                    try
                    {
                        reg.PIN = Config.DefaultPin;
                        client2.AddMFAUser(reg, ForceNewKey, true);
                        Trace.TraceInformation(string.Format("User {0} Imported in MFA", reg.UPN));
                    }
                    catch (Exception ex)
                    {
                        ErrorsCount++;
                        Trace.TraceError("Error importing Record N° {0} \r\r {1}", (RecordsCount + 1).ToString(), ex.Message);
                    }
                    finally
                    {
                        RecordsCount++;
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(string.Format("Error importing from AD \r\r {0}", ex.Message));
                return(false);
            }
            finally
            {
                Trace.Unindent();
                FinalizeTrace(listen);
            }
            return(true);
        }
Esempio n. 28
0
        /// <summary>
        /// DisableUserData method implementation
        /// </summary>
        internal void DisableUserData(MFAUserList registrations)
        {
            MFAUserList results = MMCService.DisableUser(registrations);

            EnableDisableRows(results);
        }
Esempio n. 29
0
        /// <summary>
        /// AddUserData method implmentation
        /// </summary>
        internal void AddUserData(MFAUserList registrations)
        {
            MFAUserList results = MMCService.AddUser(registrations);

            AddRows(results);
        }