Querying LDAP Passwords

KMoody

Member
Is it possible to query LDAP through an OpenEdge program?

I found code like this:
Code:
USING System.DirectoryServices.AccountManagement.*.
DEFINE VARIABLE objContext AS CLASS PrincipalContext.
objContext = NEW PrincipalContext(ContextType:Domain,"YourDomain").
MESSAGE objContext:ValidateCredentials("TestUser","TestPasssword1") VIEW-AS ALERT-BOX.

However, running it gave me error 12886: "Could not find class or interface PrincipalContext."

Why doesn't OpenEdge recognize this class? Do I need to add an assembly to the assemblies file, or is there some other workaround?
 

WinningJr

New Member
I think you answered your own question. I have both System.DirectoryServices and System.DirectoryServices.AccountManagement added to the Global Assmblies and the code above works for me.

1695336919531.png
 

Cecil

19+ years progress programming and still learning.
Worked for me too once I updated the assemblies.xml file.


Code:
using System.DirectoryServices.AccountManagement.*.

do on error  undo, leave
    on endkey undo, leave
    on stop   undo, leave
    on quit   undo, leave:
    
    define variable objContext as class PrincipalContext.

    objContext = new PrincipalContext(ContextType:Domain,"YourDomain").
    message objContext:ValidateCredentials("TestUser","TestPasssword1") view-as alert-box.

    define variable i as integer no-undo.
    catch e1 as Progress.Lang.AppError:
        do i = 1 to e1:NumMessages:
            message e1:GetMessage(i) view-as alert-box buttons ok title "Error".
        end.
        if e1:ReturnValue > "" then
            message e1:ReturnValue view-as alert-box buttons ok title "Return Value".
    end catch.
    catch e2 as Progress.Lang.Error:
        do i = 1 to e2:NumMessages:
            message e2:GetMessage(i) view-as alert-box buttons ok title "Error".
        end.
    end catch.
end.
finally.
    
end finally.
 

KMoody

Member
Thanks! That works for me, too.

If I wanted to make the assemblies available to other users, would I add the following to the .ini file?

assemblies=[filepath]\assemblies.xml
 

Cecil

19+ years progress programming and still learning.

Osborne

Active Member
As Cecil posted it is a startup parameter so will not work putting in an ini file.

Something to note, if the other users are only running compiled programs then they do not actually require access to assemblies.xml. When you run from r-code, you don't need the assemblies.xml file because the assembly-qualified name of all referenced classes are in the r-code.

Some further information regarding assemblies.xml that may be useful. To get the path of where it is:

Code:
MESSAGE Progress.ClrBridge.AssemblyStore:Instance:AssembliesPath VIEW-AS ALERT-BOX.

Dynamically change the location of assemblies.xml:

 
Top