DummyBeginner
DummyBeginner

Reputation: 431

Get an object's name by resolving its GUID via LDAP in ActiveDirecotry in Java

There's a GUID of a printer device with this format in a nxlog generated log:

119d0d80-699d-4e81-8e4e-5477e22ac1b3

I'd like to get the device name by resolving its GUID via LDAP. However, the nearest field I encountered is objectGUID in ldapsearch response, which is apparently a Base64 encoded value:

objectGUID:: fuAW6fefLke30d46TDTUWA==


Are these two above GUIDs relative in any way? (In other words, Should I search the first GUID among objectGUID fields in AD after format conversion?

How may I get the object name by using LDAP query in java?

It wasn't possible to achieve that via getAttribute() method and below code:

        //Create the initial directory context
        LdapContext ctx = new InitialLdapContext(env,null);

        //Bind directly using the string form of the GUID
        String strGUID = "<GUID="+guid+">";

        //Specify the attributes to return
        String returnedAtts[]={"distinguishedName"};

        Attributes attr = ctx.getAttributes(strGUID,returnedAtts);

        //print out the retrieved attributes
        if(attr!=null)
            distinguishedName = attr.get("distinguishedName").get().toString();
        System.out.println("distinguishedName: " + distinguishedName);

        ctx.close();

and I got NameNotFoundException:

javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-0310021B, problem 2001 (NO_OBJECT), data 0, best match of:
    ''

Is the format of name (<GUID="+guid+">) correct? (I don't see any sign of the usage of this format in the repsponse output of ldapsearch)

Upvotes: 1

Views: 1346

Answers (1)

jwilleke
jwilleke

Reputation: 10986

The ObjectGuid as used in Microsoft Active Directory is a little strange compared to must GUIDs.

You have to contend with a few aspects including Endianness

I did find a reference to some Java Code.

Upvotes: 1

Related Questions