Announcement Announcement Module
Collapse
No announcement yet.
Performing lookup with objectGUID Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Performing lookup with objectGUID

    Hi,

    I found out that the objectGUID of ActiveDirectory is the only attribute that cannot be changed, so I wish to use it to perform lookup.

    My questions are:
    1) How to retreive this attribute (because I understand its 16 bytes of Hex)?
    Is this good enough?
    ldapUser.setGuid((String) context.getObjectAttribute("objectGUID"));

    2) How to use the lookup method with this attribute?

    3) Should I set this property using spring context and if so, how?
    env.put("java.naming.ldap.attributes.binary", "objectGUID");


    Thanks,
    Ohad

  • #2
    Looking for the same

    Has anyone found a way of retreiving the objectGUID from the AD server? Is so please post the methodology used it would be really appreciated.

    Comment


    • #3
      Found a way to do it

      Okay in order to obtain the objectGUID in a binary form when you declare the spring ldap bean in the spring-application context add the following lines to it.

      <bean id="contextSource" class="org.springframework.ldap.support.LdapContex tSource">
      <property name="url" value="${ldap.url}" />
      <property name="base" value="" />
      <property name="userName" value="${ldap.managerdn}" />
      <property name="password" value="${ldap.password}" />
      <property name="baseEnvironmentProperties">
      <map>
      <entry key="java.naming.ldap.attributes.binary" value="objectGUID"/>
      </map>
      </property>

      </bean>

      The baseEnvironment properties provides a way for one to inject specific properties that you would like the environment properties to contain.


      When you query for the objectGUID now you can retireve it as a byte array.

      byte[] GUID = (byte[]) attrs.get("objectGUID").get();
      String strGUID = "";
      String byteGUID = "";
      //Convert the GUID into string using the byte format
      for (int c=0;c<GUID.length;c++) {
      byteGUID = byteGUID + "\\" + AddLeadingZero((int)GUID[c] & 0xFF);
      }
      //convert the GUID into string format
      strGUID = "{";
      strGUID = strGUID + AddLeadingZero((int)GUID[3] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[2] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[1] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[0] & 0xFF);
      strGUID = strGUID + "-";
      strGUID = strGUID + AddLeadingZero((int)GUID[5] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[4] & 0xFF);
      strGUID = strGUID + "-";
      strGUID = strGUID + AddLeadingZero((int)GUID[7] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[6] & 0xFF);
      strGUID = strGUID + "-";
      strGUID = strGUID + AddLeadingZero((int)GUID[8] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[9] & 0xFF);
      strGUID = strGUID + "-";
      strGUID = strGUID + AddLeadingZero((int)GUID[10] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[11] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[12] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[13] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[14] & 0xFF);
      strGUID = strGUID + AddLeadingZero((int)GUID[15] & 0xFF);
      strGUID = strGUID + "}";


      static String AddLeadingZero(int k) {
      return (k<0xF)?"0" + Integer.toHexString(k):Integer.toHexString(k);
      }


      The above code was taken from the java LDAP forum. The user adler_steven provided this piece of code.

      He also provides a way to query the object back based on the objectGUID.

      The link to his post

      http://forum.java.sun.com/thread.jsp...hreadID=646111

      Comment


      • #4
        I think we used to convert the GUID using this code I found on some other forum.
        Code:
            /**
             * Converts the GUID to a readable string format
             * @param inArr
             * @return the formatted GUID
             */
            private static String getGUID ( byte [] inArr )
            {
                StringBuffer guid = new StringBuffer ();
                for ( int i = 0; i < inArr.length; i++ )
                {
                    StringBuffer dblByte = new StringBuffer ( Integer.toHexString ( inArr [ i ] & 0xff ) );
                    if ( dblByte.length () == 1 ) {
                        guid.append ( "0" );
                    }
                    guid.append ( dblByte );
                }
                return guid.toString ();
            }

        Comment

        Working...
        X