Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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);
            }
        }
Exemplo n.º 13
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);
            }
        }