}//ENd getAdsCustomerGroup method #endregion #region Update ADS User process // ================================================================================== /// <summary> /// THis method updates the ADS user details. /// </summary> /// <returns>Application Data object</returns> // ---------------------------------------------------------------------------------- public EvEventCodes updateAdUserProfile ( ) { this.LogMethod ( "updateAdUserProfile" ); this.LogDebug ( "this.Session.AdsEnabled: " + this.Session.AdsEnabled ); // // Skip update if a new user. // if ( this.Session.AdsEnabled == false ) { this.LogValue ( "ADS disabled" ); this.LogMethodEnd ( "updateAdUserProfile" ); return EvEventCodes.Ok; } // // Skip update if a new user. // if ( this.AdapterObjects.Settings.AdsGroupName == null || this.Session.AdsCustomerGroup.Name == null ) { this.LogValue ( "Debug Authenication or AD Group is null" ); this.LogMethodEnd ( "updateAdUserProfile" ); return EvEventCodes.Ok; } this.LogDebug ( "AdminUserProfile.UserId: " + this.Session.AdminUserProfile.UserId ); this.LogDebug ( "AdminUserProfile.Password: "******"AdminUserProfile.GivenName: " + this.Session.AdminUserProfile.GivenName ); this.LogDebug ( "AdminUserProfile.FamilyName: " + this.Session.AdminUserProfile.FamilyName ); this.LogDebug ( "AdsCustomerGroup.Name: " + this.Session.AdsCustomerGroup.Name ); // // Initialise the ADS services // Evado.ActiveDirectoryServices.EvAdsProfiles adsProfiles = new ActiveDirectoryServices.EvAdsProfiles ( ); ActiveDirectoryServices.EvAdsUserProfile outUser = new ActiveDirectoryServices.EvAdsUserProfile ( ); ActiveDirectoryServices.EvAdsGroupProfile customerGroup = new ActiveDirectoryServices.EvAdsGroupProfile ( ); bool newUser = false; this.LogValue ( "domain name: " + adsProfiles.DomainName ); // // Attempt to retrieve the user profile. // Evado.ActiveDirectoryServices.EvAdsUserProfile adUserProfile = adsProfiles.GetUser ( this.Session.AdminUserProfile.UserId ); // // If the user does not exist add them as a new user. // if ( adUserProfile == null ) { this.LogValue ( "user null: initialise a new user." ); // // create the default password. // this.createDefaultPassword ( ); adUserProfile = new ActiveDirectoryServices.EvAdsUserProfile ( ); newUser = true; adUserProfile.UserId = this.Session.AdminUserProfile.UserId; adUserProfile.SamAccountName = this.Session.AdminUserProfile.UserId; adUserProfile.UserPrincipalName = adUserProfile.UserId + "@" + adsProfiles.DomainName; adUserProfile.AddEvGroup ( this.Session.AdsCustomerGroup ); } this.addCustomerGroup ( adUserProfile ); adUserProfile.GivenName = this.Session.AdminUserProfile.GivenName; adUserProfile.Surname = this.Session.AdminUserProfile.FamilyName; adUserProfile.DisplayName = this.Session.AdminUserProfile.CommonName; adUserProfile.EmailAddress = this.Session.AdminUserProfile.EmailAddress; adUserProfile.Password = this.Session.AdminUserProfile.Password; adUserProfile.Enabled = true; string description = adUserProfile.Description; if ( adUserProfile.Description != String.Empty ) { adUserProfile.Description += "\r\n "; } adUserProfile.Description += "Updated by " + this.Session.AdminUserProfile.CommonName + " on " + DateTime.Now.ToString ( "dd-MMM-yyyy HH:mm" ); if ( this.Session.UserProfile.Password != String.Empty ) { adUserProfile.Password = this.Session.AdminUserProfile.Password; } // // update the active directory object. // ActiveDirectoryServices.EvAdsCallResult result = adsProfiles.SaveItem ( adUserProfile, newUser, out outUser ); // // get the debug log. // this.LogValue ( "adsProfiles.ApplicationLog:" + adsProfiles.Log ); if ( result != ActiveDirectoryServices.EvAdsCallResult.Success ) { this.LogValue ( "EvAdsCallResult: " + result ); this.LogMethodEnd ( "updateAdUserProfile" ); return EvEventCodes.Active_Directory_General_Error; } this.LogMethodEnd ( "updateAdUserProfile" ); return EvEventCodes.Ok; }//ENd updateAdUserProfile method
}//END saveUserProfile method //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #endregion #region Update ADS group method. // ================================================================================== /// <summary> /// THis method retrieves the ADS customer group object. /// </summary> /// <returns>EvEventCodes</returns> // ---------------------------------------------------------------------------------- public EvEventCodes getAdsCustomerGroup ( ) { this.LogMethod ( "getAdsCustomerGroup" ); this.LogDebug ( "Customer Group Name: " + this.AdapterObjects.Settings.AdsGroupName ); // // if ADS is not enabled then set the AdsCustomerGroup to null // This will disable ADS access. // if ( this.Session.AdsEnabled == false ) { this.Session.AdsCustomerGroup = null; this.LogDebug ( "Active Directory is NOT enabled." ); return EvEventCodes.Active_Directory_Not_Enabled; } if ( this.AdapterObjects.Settings.AdsGroupName == String.Empty ) { return EvEventCodes.Active_Directory_Group_Not_Found; } if ( this.Session.AdsCustomerGroup != null ) { this.LogValue ( "Customer Group Name: " + this.AdapterObjects.Settings.AdsGroupName + " EXISTS." ); if ( this.Session.AdsCustomerGroup.Name == this.AdapterObjects.Settings.AdsGroupName ) { this.LogMethodEnd ( "getAdsCustomerGroup" ); return EvEventCodes.Ok; } } // // Initialise the ADS services // Evado.ActiveDirectoryServices.EvAdsProfiles adsProfiles = new ActiveDirectoryServices.EvAdsProfiles ( ); ActiveDirectoryServices.EvAdsGroupProfile resultGroup = new ActiveDirectoryServices.EvAdsGroupProfile ( ); //adsProfiles .DebugOn = this.DebugOn; // // Get the customer's Group name. // resultGroup = adsProfiles.GetGroup ( this.AdapterObjects.Settings.AdsGroupName ); // // If the user does not exist add them as a new user. // if ( resultGroup == null ) { this.LogValue ( "result group null " ); this.LogMethodEnd ( "getAdsCustomerGroup" ); return EvEventCodes.Active_Directory_Group_Not_Found; } this.Session.AdsCustomerGroup = resultGroup; this.LogValue ( "ADS RETURNED VALUES:" ); this.LogValue ( "adUserProfile.DisplayName: " + this.Session.AdsCustomerGroup.DisplayName ); this.LogValue ( "adUserProfile.Name: " + this.Session.AdsCustomerGroup.Name ); this.LogValue ( "adUserProfile.SamAccountName: " + this.Session.AdsCustomerGroup.SamAccountName ); this.LogMethodEnd ( "getAdsCustomerGroup" ); return EvEventCodes.Ok; }//ENd getAdsCustomerGroup method