コード例 #1
0
        public bool DeleteADAccount(common.clsUser User, common.clsPassword Password)
        {
            // Get the DirectoryEntry for the supplied MemberStation OU
            strLDAPPath += "/OU=" + User.Profile.Organization + ",OU=MemberStations," + strLDAPLocalDomain;

            try
            {
                de = new DirectoryEntry(strLDAPPath, strAdminUsr, strAdminPwd);

                // Get the DirectoryEntry for this User
                DirectorySearcher srch = new DirectorySearcher(strLDAPPath);
                srch.Filter = "(samAccountName=" + User.LoginID + ")";
                srch.PropertiesToLoad.Add("CN");
                SearchResult   srchResult = srch.FindOne();
                DirectoryEntry deUser     = srchResult.GetDirectoryEntry();

                // Remove this User from OU container
                de.Children.Remove(deUser);

                deUser.Dispose();
                srch.Dispose();
                de.CommitChanges();
                de.RefreshCache();

                return(true);
            }
            catch (System.Exception ex)
            {
                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to DeleteADAccount! " + strLDAPPath + " ", ex);

                return(false);
            }
        }
コード例 #2
0
        unsafe public bool IsADAccountEnabled(common.clsUser User)
        {
            DirectoryEntry deUser = this.GetUserByLoginID(User.LoginID);
            int            intVal = (int)deUser.Properties["userAccountControl"].Value;

            return(!deUser.Properties["userAccountControl"].Value.Equals(intVal | (int)ADS_USER_FLAG_ENUM.ADS_UF_ACCOUNTDISABLE));
        }
コード例 #3
0
        public bool ResetPassword(common.clsUser User, common.clsPassword Password)
        {
            try
            {
                this.strLDAPPath = this.GetUserByLoginID(User.LoginID).Path.Replace("LDAP://", CONFIG_ADSI_Root + "/");

                // Add NewPassword to an array
                string   strNewPwd = Password.NewPassword;
                object[] arrPwd    = new object[1];
                arrPwd.SetValue(strNewPwd, 0);

                // Get the DirectoryEntry for this User, authenticating with the Admin usr/pwd
                de = new DirectoryEntry(strLDAPPath, strAdminUsr, strAdminPwd);

                // Call native AD method to set new Password
                de.Invoke("setPassword", arrPwd);
                de.CommitChanges();
                de.RefreshCache();

                return(true);
            }
            catch (System.Exception ex)
            {
                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to ResetPassword! " + strLDAPPath + " ", ex);

                return(false);
            }
        }
コード例 #4
0
        public bool ResetPassword(common.clsUser User, common.clsPassword Password)
        {
            try
            {
                // Get the full LDAP path to the user
                // Set the DirectoryEntry object for this User
                DirectoryEntry de          = clsADMngr.GetUserByLoginID(User.LoginID);
                string         strLDAPPath = de.Properties["distinguishedName"].Value.ToString();

                // Instantiate a new PBSAD object using this user path
                clsADMngr = new ad.clsActiveDirectoryManager(CONFIG_ADSI_AdminUsr, CONFIG_ADSI_AdminPwd, strLDAPPath);

                // Return success/failure;
                bool boolSuccess = clsADMngr.ResetPassword(User, Password);
                if (boolSuccess)
                {
                    strMessage += "Password change successful<br>";

                    return(true);
                }
                else
                {
                    throw new System.Exception();
                }
            }
            catch (System.Exception ex)
            {
                strMessage += "Password change failed!<br><br>" + ex.GetBaseException().Message + "<br>";

                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to ResetPassword!", ex);
            }

            return(false);
        }
コード例 #5
0
        public common.clsUser Update(common.clsUser User, common.clsPassword Password)
        {
            try
            {
                bool boolSuccess = false;

                // User opted to ChangePassword
                if (Password.OldPassword != null && Password.NewPassword != null)
                {
                    boolSuccess = this.ChangePassword(User, Password); if (!boolSuccess)
                    {
                        throw new System.Exception("Password change failed");
                    }                                                                                                                                                      // strMessage
                }
                // Admin opted to ResetPassword
                else if (Password.NewPassword != null && Password.Hint != null)
                {
                    boolSuccess = this.ResetPassword(User, Password); if (!boolSuccess)
                    {
                        throw new System.Exception("Password reset failed");
                    }                                                                                                                                                // strMessage
                }

                // Update Active Directory and StationContact records
                if (User.Profile.Organization.ToUpper() != "PBS")
                {
                    boolSuccess = clsADMngr.UpdateADAccount(User, Password);            if (!boolSuccess)
                    {
                        throw new System.Exception("Account update to Active Directory failed!");
                    }
                }
                boolSuccess = clsStationDBMngr.UpdateProfile(User, Password);   if (!boolSuccess)
                {
                    throw new System.Exception("Account update to Stations DB failed!");
                }

                clsUser = clsStationDBMngr.GetUser(User.LoginID);

                // Update WebBoard account
                clsWebBoardMngr.wbUpdateUser(clsUser);

                strMessage += "Account update for \"" + User.DisplayName + "\" succeeded<br>";

                return(clsUser);
            }
            catch (System.Exception ex)
            {
                if (strMessage.Length == 0)
                {
                    strMessage = "Account update failed!";
                }

                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to Update account!", ex);

                throw new System.Exception(strMessage);
            }
        }
コード例 #6
0
 /// <summary>This method retrieves the User's group memberships</summary>
 /// <param name="User">The User object whose "memberOf" property needs to be accessed</param>
 /// <param name="strLDAPPath">The full LDAP path to the User</param>
 /// <returns>string[]</returns>
 public string[] GetGroups(common.clsUser User, string strLDAPPath)
 {
     try
     {
         return(_clsPBSActiveDirectory.GetGroups(User, strLDAPPath));
     }
     catch (System.Exception ex)
     {
         throw new System.Exception(ex.GetBaseException().Message);
     }
 }
コード例 #7
0
        public string[] GetGroups(common.clsUser User, string strLDAPPath)
        {
            string strGroups = this.GetGroupsRecursive(User, strLDAPPath);

            if (strGroups.Length > 0)
            {
                return(strGroups.Split(new char[] { '|' }));
            }
            else
            {
                return(new string[0]);
            }
        }
コード例 #8
0
        public common.clsUser ApproveRegistration(common.clsUser User, common.clsPassword Password, common.clsRequest Request)
        {
            try
            {
                // Create Active Directory and StationContact records
                bool boolSuccess = false;
                boolSuccess = clsADMngr.CreateADAccount(User, Password);
                if (!boolSuccess)
                {
                    throw new System.Exception("Failed to create new Active Directory account!");
                }
                boolSuccess = clsStationDBMngr.ApproveRegistrationRequest(Request);
                if (!boolSuccess)
                {
                    throw new System.Exception("Failed to insert STATIONS.tblREGISTRATIONREQUESTS record into STATIONS.tblSTATIONCONTACTS!");
                }

                clsUser = clsStationDBMngr.GetUser(Request.UserInfo.LoginID);

                // Create new WebBoard account
                try
                {
                    clsWebBoardMngr.wbAddUser(clsUser, CONFIG_CONN_WebBoardDefaultBoardID);
                    if (clsWebBoardMngr.wbGetWebBoardIdForUser(clsUser) <= 0)
                    {
                        throw new System.Exception("Failed to create new WebBoard account!");
                    }
                }
                catch (System.Exception ex)
                {
                    clsErr = new common.LogError();
                    clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbAddUser!", ex);
                    throw new System.Exception(ex.GetBaseException().Message);
                }

                strMessage += "Registration Request from \"" + Request.UserInfo.FirstName + " " + Request.UserInfo.LastName + "\" has been approved";

                return(clsUser);
            }
            catch (System.Exception ex)
            {
                strMessage += ex.GetBaseException().Message;

                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to ApproveRegistration!", ex);
            }

            return(User);
        }
コード例 #9
0
        public bool CreateADAccount(common.clsUser User, common.clsPassword Password)
        {
            this.strLDAPPath += "/OU=" + User.Profile.Organization + ",OU=MemberStations," + strLDAPLocalDomain;
            DirectoryEntry deGroupOU        = this.GetUserByLoginID(User.Profile.Organization + "Usr");
            DirectoryEntry deGroupPBSCUsers = this.GetUserByLoginID("PBSC All Users");

            // Add User to OU=[MemberStation]
            // Set User account properties
            // Set User account password
            // Set User account = Enabled
            // Add User to [MemberStation]Usr Group (Use the pre-W2K AD group name!!!!!!!!!)
            // Add User to "PBSC All Users" Group
            bool boolSuccess = false;

            boolSuccess = this.AddToOU(User, strLDAPPath);                                  if (!boolSuccess)
            {
                return(false);
            }
            boolSuccess = this.UpdateADAccount(User, Password);                             if (!boolSuccess)
            {
                return(false);
            }
            boolSuccess = this.ResetPassword(User, Password);                               if (!boolSuccess)
            {
                return(false);
            }
            boolSuccess = this.EnableADAccount(User);                                               if (!boolSuccess)
            {
                return(false);
            }
            boolSuccess = this.AddUserToGroup(User, deGroupOU.Path);                if (!boolSuccess)
            {
                return(false);
            }
            //		boolSuccess = this.AddUserToGroup(User, deGroupPBSCUsers.Path);	if (!boolSuccess) { return false; }

            deGroupOU.Dispose();
            deGroupPBSCUsers.Dispose();

            return(boolSuccess);
        }
コード例 #10
0
        public common.clsUser Delete(common.clsUser User, common.clsPassword Password)
        {
            try
            {
                // Delete WebBoard account
                try
                {
                    clsWebBoardMngr.wbDeleteUser(User);
                }
                catch (System.Exception ex)
                {
                    clsErr = new common.LogError();
                    clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbDeleteUser!", ex);
                    throw new System.Exception(ex.GetBaseException().Message);
                }

                // Delete Active Directory and StationContact records
                bool boolSuccess = false;
                boolSuccess = clsADMngr.DeleteADAccount(User, Password);                if (!boolSuccess)
                {
                    throw new System.Exception();
                }
                boolSuccess = clsStationDBMngr.DeleteProfile(User, Password);   if (!boolSuccess)
                {
                    throw new System.Exception();
                }

                strMessage += "Account deletion for \"" + User.DisplayName + "\" succeeded<br>";

                return(User);
            }
            catch (System.Exception ex)
            {
                strMessage += "Account deletion failed!<ul><li>" + ex.GetBaseException().Message + "<br><br>" + ex.GetBaseException().StackTrace + "</li></ul>";

                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to Delete account!", ex);
            }

            return(User);
        }
コード例 #11
0
        private string GetGroupsRecursive(common.clsUser User, string strLDAPPath)
        {
            // Get the AD DirectoryEntry per strLDAPPath
            DirectoryEntry deToCheck = ((strLDAPPath == null) == true) ? this.GetUserByLoginID(User.LoginID) : new DirectoryEntry(strLDAPPath, CONFIG_ADSI_AdminUsr, CONFIG_ADSI_AdminPwd);
            StringBuilder  sb        = new StringBuilder("");
            DirectoryEntry deTest;
            string         cn, strGroupName;
            int            ixEquals, ixComma;

            for (int i = 0; i < deToCheck.Properties["memberOf"].Count; i++)
            {
                cn     = (string)deToCheck.Properties["memberOf"][i];
                deTest = new DirectoryEntry(CONFIG_ADSI_Root + "/" + cn, CONFIG_ADSI_AdminUsr, CONFIG_ADSI_AdminPwd);

                ixEquals     = cn.IndexOf("=", 1);
                ixComma      = cn.IndexOf(",", 1);
                strGroupName = cn.Substring((ixEquals + 1), (ixComma - ixEquals) - 1);

                if (sb.ToString().IndexOf(strGroupName) < 0 || sb.ToString().IndexOf(strGroupName + "|") < 0)
                {
                    sb.Append(strGroupName + "|");
                }

                if (deTest.Properties.Contains("memberOf"))
                {
                    sb.Append(this.GetGroupsRecursive(User, CONFIG_ADSI_Root + "/" + cn) + "|");
                }
            }
            deToCheck.Close();
            deToCheck.Dispose();

            string strGroups = sb.ToString();

            if (strGroups.EndsWith("|"))
            {
                // Remove trailing pipe char
                strGroups = strGroups.Remove(strGroups.Length - 1, 1);
            }

            return(strGroups);
        }
コード例 #12
0
        public bool AddToOU(common.clsUser User, string strLDAPPath)
        {
            this.strLDAPPath = strLDAPPath;

            try
            {
                de = new DirectoryEntry(this.strLDAPPath, strAdminUsr, strAdminPwd);

                // Check for existence of User
                DirectoryEntry deUser = this.GetUser("CN", User.DisplayName);

                // Note: Active Directory will reject attempts to add dupe CNs, so
                // we have to check DiplayName instead of LoginID
                //		DirectoryEntry		deUser		= this.GetUserByLoginID(User.LoginID);
                //		if (!deUser.Properties.Contains("samAccountName"))

                // No User found, Add to AD tree
                if (deUser.Properties["samAccountName"].Value == null)
                {
                    deUser = de.Children.Add("CN=" + User.DisplayName, "user");
                }

                // Set the samAccountName, then commit changes to the directory entry and it's parent
                deUser.UsePropertyCache = true;
                deUser.Properties["samAccountName"].Value    = User.LoginID;
                deUser.Properties["userPrincipalName"].Value = User.LoginID + "@" + ConfigurationSettings.AppSettings["ActiveDirectoryRootString"].Replace("LDAP://", "");
                deUser.CommitChanges();

                // Get the new AD path to this User
                this.strLDAPPath = this.GetUser("CN", User.DisplayName).Path;

                return(true);
            }
            catch (System.Exception ex)
            {
                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to AddToOU! " + strLDAPPath + " ", ex);

                return(false);
            }
        }
コード例 #13
0
        public bool RemoveFromOU(common.clsUser User, string strLDAPPath)
        {
            try
            {
                de = new DirectoryEntry(strLDAPPath, strAdminUsr, strAdminPwd);
                de.Children.Remove(this.GetUserByLoginID(User.LoginID));

                // Get LastIndexOf(User.LoginID)
                int ixLogin = this.GetUsers(User.Profile.Organization).ToString().LastIndexOf(User.LoginID);

                // Return success/failure
                return(ixLogin < 0 ? true : false);
            }
            catch (System.Exception ex)
            {
                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to RemoveFromOU! " + strLDAPPath + " ", ex);

                return(false);
            }
        }
コード例 #14
0
        public common.clsUser Create(common.clsUser User, common.clsPassword Password)
        {
            try
            {
                // Create Active Directory and StationContact records
                bool boolSuccess = false;
                boolSuccess = clsADMngr.CreateADAccount(User, Password);
                boolSuccess = clsStationDBMngr.CreateProfile(User, Password);   if (!boolSuccess)
                {
                    throw new System.Exception("Failed to insert STATIONS.tblSTATIONCONTACTS record!");
                }

                clsUser = clsStationDBMngr.GetUser(User.LoginID);

                // Create new WebBoard account
                try
                {
                    clsWebBoardMngr.wbAddUser(clsUser, CONFIG_CONN_WebBoardDefaultBoardID);
                }
                catch (System.Exception ex)
                {
                    clsErr = new common.LogError();
                    clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbAddUser!", ex);
                    throw new System.Exception(ex.GetBaseException().Message);
                }

                strMessage += "Account creation for \"" + User.DisplayName + "\" succeeded<br>";

                return(clsUser);
            }
            catch (System.Exception ex)
            {
                strMessage += "Account creation failed!<ul><li>" + ex.GetBaseException().Message + "<br><br>" + ex.GetBaseException().StackTrace + "</li></ul>";

                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to Create account!", ex);
            }

            return(User);
        }
コード例 #15
0
        unsafe public bool DisableADAccount(common.clsUser User)
        {
            try
            {
                DirectoryEntry deUser = this.GetUserByLoginID(User.LoginID);
                int            intVal = (int)deUser.Properties["userAccountControl"].Value;

                deUser.Properties["userAccountControl"].Value = intVal | (int)ADS_USER_FLAG_ENUM.ADS_UF_ACCOUNTDISABLE;
                deUser.CommitChanges();
                deUser.RefreshCache();

                // Return success/failure
                return(!this.IsADAccountEnabled(User));
            }
            catch (System.Exception ex)
            {
                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to DisableADAccount! " + strLDAPPath + " ", ex);

                return(false);
            }
        }
コード例 #16
0
        public bool RemoveUserFromGroup(common.clsUser User, string strLDAPPath)
        {
            try
            {
                de = new DirectoryEntry(strLDAPPath, strAdminUsr, strAdminPwd);
                DirectoryEntry deUser = this.GetUserByLoginID(User.LoginID);

                if (de.Properties["member"].Contains(deUser.Properties["distinguishedName"].Value))
                {
                    de.Properties["member"].Remove(deUser.Properties["distinguishedName"].Value);
                    de.CommitChanges();
                    de.RefreshCache();
                }

                return(!de.Properties["member"].Contains(deUser.Properties["distinguishedName"].Value));
            }
            catch (System.Exception ex)
            {
                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to RemoveUserFromGroup! " + strLDAPPath + " ", ex);

                return(false);
            }
        }
コード例 #17
0
 /// <summary>
 /// This method deletes an account
 /// </summary>
 /// <param name="User">The User to delete</param>
 /// <param name="Password">Not used</param>
 /// <returns>bool</returns>
 public bool DeleteADAccount(common.clsUser User, common.clsPassword Password)
 {
     return(_clsPBSActiveDirectory.DeleteADAccount(User, Password));
 }
コード例 #18
0
 /// <summary>This method removes a User from the OU specified</summary>
 /// <param name="User">The User to remove</param>
 /// <param name="strLDAPPath">The full LDAP path to the OU object</param>
 /// <returns>bool</returns>
 public bool RemoveFromOU(common.clsUser User, string strLDAPPath)
 {
     return(_clsPBSActiveDirectory.RemoveFromOU(User, strLDAPPath));
 }
コード例 #19
0
 /// <summary>This method adds a User to the OU specified</summary>
 /// <param name="User">The User to add</param>
 /// <param name="strLDAPPath">The full LDAP path to the OU object</param>
 /// <returns>bool</returns>
 public bool AddToOU(common.clsUser User, string strLDAPPath)
 {
     return(_clsPBSActiveDirectory.AddToOU(User, strLDAPPath));
 }
コード例 #20
0
 /// <summary>This method checks to see if a User account is enabled. This method is flagged as an unsafe code block (see MSDN docs on the ADS_USER_FLAGS)</summary>
 /// <param name="User">The User whose account needs to be checked</param>
 /// <returns>bool</returns>
 public bool IsADAccountEnabled(common.clsUser User)
 {
     return(_clsPBSActiveDirectory.IsADAccountEnabled(User));
 }
コード例 #21
0
 /// <summary>This method resets a User's password. Calls native AD "setPassword" method</summary>
 /// <param name="User">The User to be reset</param>
 /// <param name="Password">The Password object containing NewPassword</param>
 /// <returns>bool</returns>
 public bool ResetPassword(common.clsUser User, common.clsPassword Password)
 {
     return(_clsPBSActiveDirectory.ResetPassword(User, Password));
 }
コード例 #22
0
 /// <summary>This method disables a User account. This method is flagged as an unsafe code block (see MSDN docs on the ADS_USER_FLAGS)</summary>
 /// <param name="User">The User to disable</param>
 /// <returns>bool</returns>
 public bool DisableADAccount(common.clsUser User)
 {
     return(_clsPBSActiveDirectory.DisableADAccount(User));
 }
コード例 #23
0
        public bool ApproveConfReq(common.clsUser User, common.clsConfRequest ConfRequest)
        {
            try
            {
                bool boolSuccess = false;
                boolSuccess = clsStationDBMngr.UpdateConfRequest(ConfRequest, User); if (!boolSuccess)
                {
                    throw new System.Exception("Failed to update STATIONS.tblCONFREQUEST (stationcontactid=" + ConfRequest.User.StationContactID.ToString() + ", forumid=" + ConfRequest.ForumID.ToString() + ")!");
                }

                // Add User to WebBoard Conference
                int intWebBoardUserID = 0;
                try
                {
                    intWebBoardUserID = clsWebBoardMngr.wbGetWebBoardIdForUser(ConfRequest.User);
                }
                catch
                {
                    try
                    {
                        // User does not yet exist in WebBoard, Auto-add WebBoard account for User
                        clsWebBoardMngr.wbAddUser(ConfRequest.User, CONFIG_CONN_WebBoardDefaultBoardID);
                        intWebBoardUserID = clsWebBoardMngr.wbGetWebBoardIdForUser(ConfRequest.User);
                    }
                    catch (System.Exception ex)
                    {
                        clsErr = new common.LogError();
                        clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbAddUser!", ex);
                        throw new System.Exception(ex.GetBaseException().Message);
                    }
                }
                // Try to AddUserToConference
                try
                {
                    clsWebBoardMngr.wbAddUserToConference(ConfRequest.User, ConfRequest.ForumID);
                    strMessage += "Approve Request from \"" + ConfRequest.User.DisplayName + "\" succeeded";
                }
                catch (System.Exception ex)
                {
                    clsErr = new common.LogError();
                    clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbAddUserToConference!", ex);
                    throw new System.Exception(ex.GetBaseException().Message);
                }


                if (boolSuccess)
                {
                    // Add User to corresponding Active Directory users group
                    string strUsersGroupPath = "";
                    try
                    {
                        DataSet dsGroup;
                        string  strUsersGroup = "";

                        if (ConfRequest.ADGroup == null)
                        {
                            // Retrieve the AD group name for this ForumID from STATIONS.FORUMS
                            DataSet ds = clsStationDBMngr.GetForum(ConfRequest.ForumID);
                            strUsersGroup = ds.Tables[0].Rows[0]["AD_UsersGroup"].ToString();
                            dsGroup       = clsADMngr.GetADDataSet(CONFIG_ADSI_Root + "/OU=Conferences,OU=AppSecurityGroups," + CONFIG_ADSI_RootLocal, "(CN=" + strUsersGroup + ")");

                            ds.Dispose();
                        }
                        else
                        {
                            dsGroup = clsADMngr.GetADDataSet(CONFIG_ADSI_Root + "/OU=Conferences,OU=AppSecurityGroups," + CONFIG_ADSI_RootLocal, "(CN=" + ConfRequest.ADGroup + ")");
                        }

                        strUsersGroupPath = dsGroup.Tables[0].Rows[0]["Path"].ToString();
                        boolSuccess       = clsADMngr.AddUserToGroup(ConfRequest.User, strUsersGroupPath);

                        if (!boolSuccess)
                        {
                            throw new System.Exception("Failed to add User to Active Directory group \"" + strUsersGroup + "\"");
                        }

                        dsGroup.Dispose();
                    }
                    catch (System.Exception ex)
                    {
                        clsErr = new common.LogError();
                        clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to add ConfRequest.User to " + strUsersGroupPath, ex);
                        throw new System.Exception(ex.GetBaseException().Message);
                    }
                }

                return(boolSuccess);
            }
            catch (System.Exception ex)
            {
                strMessage += "Approve Request from \"" + ConfRequest.User.DisplayName + "\" failed!";

                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to ApproveConfReq!", ex);

                throw new System.Exception(ex.Message);
            }
        }
コード例 #24
0
        public bool UpdateADAccount(common.clsUser User, common.clsPassword Password)
        {
            try
            {
                de = this.GetUserByLoginID(User.LoginID);

                // Update the DirectoryEntry property collection for this User
                de.Properties["samAccountName"].Value    = User.LoginID;
                de.Properties["userPrincipalName"].Value = User.LoginID + "@" + ConfigurationSettings.AppSettings["ActiveDirectoryRootString"].Replace("LDAP://", "");
                de.Properties["givenName"].Value         = User.Profile.FirstName;
                de.Properties["sn"].Value          = User.Profile.LastName;
                de.Properties["displayName"].Value = User.DisplayName;

                //string	strInitials	 = User.Profile.FirstName.Substring(0,1);
                //if (!common.clsFunctions.IsFieldEmpty(User.Profile.MiddleName)) { strInitials += User.Profile.MiddleName.Substring(0,1); }
                //strInitials += User.Profile.LastName.Substring(0,1);
                //de.Properties["initials"].Value					= strInitials;

                de.Properties["company"].Value = User.Profile.Organization;

                //	de.Properties["title"].Value					= User.Profile.Title;
                //	de.Properties["description"].Value				= User.Profile.JobFunction;
                //	de.Properties["streetAddress"].Value			= User.Profile.Address1 + ", " + User.Profile.Address2;
                //	de.Properties["l"].Value						= User.Profile.City;
                //	de.Properties["st"].Value						= User.Profile.State;
                //	de.Properties["postalCode"].Value				= User.Profile.Zip;

                //	de.Properties["c"].Value						= "US";
                //	de.Properties["co"].Value						= "UNITED STATES";
                //	de.Properties["countryCode"].Value				= 840;

                /*
                 * string strTelephone = "";
                 *
                 * bool	boolExtExists	= true;
                 * if (User.Profile.Extension == null) { boolExtExists = false; }
                 * if (User.Profile.Extension.Length.Equals(0)) { boolExtExists = false; }
                 *
                 * if (boolExtExists)
                 * {
                 *      strTelephone = User.Profile.AreaCode + " " + User.Profile.Exchange + " ext. " + User.Profile.Extension;
                 * }
                 * else
                 * {
                 *      strTelephone = User.Profile.AreaCode + " " + User.Profile.Exchange;
                 * }
                 * de.Properties["telephoneNumber"].Value			= strTelephone;
                 * de.Properties["facsimileTelephoneNumber"].Value	= User.Profile.FaxAreaCode + " " + User.Profile.FaxExchange;
                 */
                de.Properties["mail"].Value = User.Profile.EmailAddress;

                /*
                 * CDOEXM.IMailRecipient mailUser = (CDOEXM.IMailRecipient) de.NativeObject;
                 * try		{ mailUser.MailDisable(); }
                 * catch	{ }
                 * mailUser.MailEnable( "SMTP:" + User.Profile.EmailAddress );
                 */
                /*
                 * if (de.Properties.Contains("proxyAddresses"))
                 * {
                 *      de.Properties["proxyAddresses"].Clear();
                 *      de.Properties["proxyAddresses"].Add( "SMTP:"+User.Profile.EmailAddress );
                 *      de.Properties["proxyAddresses"].Add( "X400:c=us;a= ;p=company US;o=Exchange;s="+User.Profile.LastName+";g="+User.DisplayName+";" );
                 * }
                 * if (de.Properties.Contains("mailNickname"))
                 * {
                 *      de.Properties["mailNickname"].Value		= User.LoginID;
                 * }
                 * if (de.Properties.Contains("targetAddress"))
                 * {
                 *      de.Properties["targetAddress"].Value	= "SMTP:"+User.Profile.EmailAddress;
                 * }
                 */

                // Commit changes, refresh cache
                de.CommitChanges();
                de.RefreshCache();

                return(true);
            }
            catch (System.Exception ex)
            {
                clsErr = new common.LogError();
                clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to UpdateADAccount! " + strLDAPPath + " ", ex);

                return(false);
            }
        }