From bd0d37821867fa7f35743bd8caa4041f4e71fae5 Mon Sep 17 00:00:00 2001 From: "Infineon\\Ouellette" Date: Thu, 26 Sep 2024 11:36:14 -0700 Subject: [PATCH] Adjusted logging in pre-existing method. Added more comments for documentation. --- LSL2/STPROC/ACTIVE_DIRECTORY_SERVICES.txt | 71 ++++++++++++----------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/LSL2/STPROC/ACTIVE_DIRECTORY_SERVICES.txt b/LSL2/STPROC/ACTIVE_DIRECTORY_SERVICES.txt index b984895..4e4e296 100644 --- a/LSL2/STPROC/ACTIVE_DIRECTORY_SERVICES.txt +++ b/LSL2/STPROC/ACTIVE_DIRECTORY_SERVICES.txt @@ -503,17 +503,25 @@ Service GetADGroupMembersByGroupName(GroupName, Domain=DOMAIN) end service //---------------------------------------------------------------------------------------------------------------------- -// VerifyEPPMetrology +// GetADUserAttributes // -// RDSNo. - [Required] +// Username - The exact AD username of the user you are looking for. +// Domain - Sets to infineon by Default. override with and string value // -// Sets an error in Error_Services if there is an issue with the metrology data. +// Searches for a matching user in Active Directory and returns a user with @VM delimited attributes. +// First value is the AD User Name, Second value is the Display Name, and third value is the email. //---------------------------------------------------------------------------------------------------------------------- -Service GetADUserAttributes(Username, Domain) +Service GetADUserAttributes(Username, Domain=DOMAIN) Set_Status(0) ThisUser = '' ErrMessage = '' - If Username NE '' AND Domain NE '' then + If Username EQ '' then + ErrMessage = 'Username was null.' + end + If Domain EQ '' then + Domain = 'INFINEON' + end + If ErrMessage EQ '' then DotNetHandle = StartDotNet("","4.0") DotNetDir = CheckDotNet('4.0'):'\' AccountMgmtDllPath = DotNetDir:'System.DirectoryServices.AccountManagement.dll' @@ -530,62 +538,59 @@ Service GetADUserAttributes(Username, Domain) If Not(Get_Status(errCode)) then objUserPrincipal = Send_Message.Net(objPrinSearcher, 'FindOne', '', '', 1) If Not(Get_Status(errCode)) then - UserName = Get_Property.Net(objUserPrincipal, 'Name', 0) - Email = Get_Property.Net(objUserPrincipal, 'EmailAddress', 0) - DisplayName = Get_Property.Net(objUserPrincipal, 'DisplayName', 0) - ThisUser<1> = UserName - ThisUser<2> = DisplayName - ThisUser<3> = Email + ADUserName = Get_Property.Net(objUserPrincipal, 'Name', 0) + Email = Get_Property.Net(objUserPrincipal, 'EmailAddress', 0) + DisplayName = Get_Property.Net(objUserPrincipal, 'DisplayName', 0) + ThisUser<1> = ADUserName + ThisUser<2> = DisplayName + ThisUser<3> = Email end else //Error getting user object - LogData = '' - LogData<1> = LoggingDTM - LogData<2> = 'GetADUserAttributes' - LogData<3> = 'Error getting user attributes of user: ' : Username : ' within the ' : Domain : ' domain.' - Logging_Services('AppendLog', objADLog, LogData, @RM, @FM, False$) + ErrMessage = 'Error getting user attributes of user: ' : Username : ' within the ' : Domain : ' domain.' end Free_class.Net(objPrinSearcher) end else //error creating principle searcher - LogData = '' - LogData<1> = LoggingDTM - LogData<2> = 'GetADUserAttributes' - LogData<3> = 'Error creating principle searcher. Username: ' : Username : ' within the ' : Domain : ' domain.' - Logging_Services('AppendLog', objADLog, LogData, @RM, @FM, False$) + ErrMessage = 'Error creating principle searcher. Username: ' : Username : ' within the ' : Domain : ' domain.' end Free_Class.Net(objUserPrincipal) end else //error creating user principle object - LogData = '' - LogData<1> = LoggingDTM - LogData<2> = 'GetADUserAttributes' - LogData<3> = 'Error creating principle searcher. Username' : Username : 'within the ' : Domain : ' domain.' - Logging_Services('AppendLog', objADLog, LogData, @RM, @FM, False$) + ErrMessage = 'Error creating principle searcher. Username' : Username : 'within the ' : Domain : ' domain.' end Free_Class.Net(objPC) end else //Error creating principle context - LogData = '' - LogData<1> = LoggingDTM - LogData<2> = 'GetADUserAttributes' - LogData<3> = 'Error creating principle context Username' : Username : 'within the ' : Domain : ' domain.' - Logging_Services('AppendLog', objADLog, LogData, @RM, @FM, False$) + ErrMessage = 'Error creating principle context Username' : Username : 'within the ' : Domain : ' domain.' end end else //error calling dotnet + ErrMessage = 'Error creating dotnet object. Username' : Username : 'within the ' : Domain : ' domain.' + end + If ErrMessage EQ '' then + Message = 'Successfully retrieved attributes of user ' : Username : ' within the ' : Domain : ' domain.' LogData = '' LogData<1> = LoggingDTM LogData<2> = 'GetADUserAttributes' - LogData<3> = 'Error creating dotnet object. Username' : Username : 'within the ' : Domain : ' domain.' + LogData<3> = Message Logging_Services('AppendLog', objADLog, LogData, @RM, @FM, False$) + end else + LogData = '' + LogData<1> = LoggingDTM + LogData<2> = 'GetADUserAttributes' + LogData<3> = 'Error getting attributes of user ' : Username : ':' : ErrMessage + Logging_Services('AppendLog', objADLog, LogData, @RM, @FM, False$) + Error_Services('Add', ErrMessage) end end else //Error, missing username or domain name LogData = '' LogData<1> = LoggingDTM LogData<2> = 'GetADUserAttributes' - LogData<3> = 'Missing username or domain name' + LogData<3> = 'Error getting user attributes: ' : ErrMessage Logging_Services('AppendLog', objADLog, LogData, @RM, @FM, False$) + Error_Services('Add', ErrMessage) end Response = ThisUser end service +