/** * <p>Decode a raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from Active * Directory.</p> * * <p>The returned string is useful to directly bind an entry. Eg.:</p> * * <p> * String bindingString = decodeObjectGUID(objectGUID); * <br/> * Attributes attributes = ctx.getAttributes(bindingString); * </p> * * @param objectGUID A raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from * Active Directory. * * @return A string representing the decoded value in the form of [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]. */ public static String decodeObjectGUID(byte[] objectGUID) { StringBuilder displayStr = new StringBuilder(); displayStr.append(convertToDashedString(objectGUID)); return displayStr.toString(); }
public String decodeEntryUUID(final Object entryUUID) { String id; if (this.config.isActiveDirectory()) { id = LDAPUtil.decodeObjectGUID((byte[]) entryUUID); } else { id = entryUUID.toString(); } return id; }
private static String convertToDashedString(byte[] objectGUID) { StringBuilder displayStr = new StringBuilder(); displayStr.append(prefixZeros((int) objectGUID[3] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[2] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[1] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[0] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[5] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[4] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[7] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[6] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[8] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[9] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[10] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[11] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[12] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[13] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[14] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[15] & 0xFF)); return displayStr.toString(); }
public String getFilterById(String baseDN, String id) { String filter = null; if (this.config.isActiveDirectory()) { final String strObjectGUID = "<GUID=" + id + ">"; try { Attributes attributes = execute(new LdapOperation<Attributes>() { @Override public Attributes execute(LdapContext context) throws NamingException { return context.getAttributes(strObjectGUID); } }); byte[] objectGUID = (byte[]) attributes.get(LDAPConstants.OBJECT_GUID).get(); filter = "(&(objectClass=*)(" + getUniqueIdentifierAttributeName() + EQUAL + convertObjectGUIToByteString(objectGUID) + "))"; } catch (NamingException ne) { return filter; } } if (filter == null) { filter = "(&(objectClass=*)(" + getUniqueIdentifierAttributeName() + EQUAL + id + "))"; } return filter; }
public String getFilterById(String baseDN, String id) { String filter = null; if (this.config.isActiveDirectory()) { final String strObjectGUID = "<GUID=" + id + ">"; try { Attributes attributes = execute(new LdapOperation<Attributes>() { @Override public Attributes execute(LdapContext context) throws NamingException { return context.getAttributes(strObjectGUID); } }); byte[] objectGUID = (byte[]) attributes.get(LDAPConstants.OBJECT_GUID).get(); filter = "(&(objectClass=*)(" + getUniqueIdentifierAttributeName() + EQUAL + convertObjectGUIToByteString(objectGUID) + "))"; } catch (NamingException ne) { return filter; } } if (filter == null) { filter = "(&(objectClass=*)(" + getUniqueIdentifierAttributeName() + EQUAL + id + "))"; } return filter; }
private static String convertToDashedString(byte[] objectGUID) { StringBuilder displayStr = new StringBuilder(); displayStr.append(prefixZeros((int) objectGUID[3] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[2] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[1] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[0] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[5] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[4] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[7] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[6] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[8] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[9] & 0xFF)); displayStr.append("-"); displayStr.append(prefixZeros((int) objectGUID[10] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[11] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[12] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[13] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[14] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[15] & 0xFF)); return displayStr.toString(); }
public String decodeEntryUUID(final Object entryUUID) { String id; if (this.config.isActiveDirectory()) { id = LDAPUtil.decodeObjectGUID((byte[]) entryUUID); } else { id = entryUUID.toString(); } return id; }
/** * <p>Decode a raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from Active * Directory.</p> * * <p>The returned string is useful to directly bind an entry. Eg.:</p> * * <p> * String bindingString = decodeObjectGUID(objectGUID); * <br/> * Attributes attributes = ctx.getAttributes(bindingString); * </p> * * @param objectGUID A raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from * Active Directory. * * @return A string representing the decoded value in the form of [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]. */ public static String decodeObjectGUID(byte[] objectGUID) { StringBuilder displayStr = new StringBuilder(); displayStr.append(convertToDashedString(objectGUID)); return displayStr.toString(); }
/** * <p>Creates a byte-based {@link String} representation of a raw byte array representing the value of the * <code>objectGUID</code> attribute retrieved from Active Directory.</p> * * <p>The returned string is useful to perform queries on AD based on the <code>objectGUID</code> value. Eg.:</p> * * <p> * String filter = "(&(objectClass=*)(objectGUID" + EQUAL + convertObjectGUIToByteString(objectGUID) + "))"; * </p> * * @param objectGUID A raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from * Active Directory. * * @return A byte-based String representation in the form of \[0]\[1]\[2]\[3]\[4]\[5]\[6]\[7]\[8]\[9]\[10]\[11]\[12]\[13]\[14]\[15] */ public static String convertObjectGUIToByteString(byte[] objectGUID) { StringBuilder result = new StringBuilder(); for (int i = 0; i < objectGUID.length; i++) { String transformed = prefixZeros((int) objectGUID[i] & 0xFF); result.append("\\"); result.append(transformed); } return result.toString(); }
/** * <p>Creates a byte-based {@link String} representation of a raw byte array representing the value of the * <code>objectGUID</code> attribute retrieved from Active Directory.</p> * * <p>The returned string is useful to perform queries on AD based on the <code>objectGUID</code> value. Eg.:</p> * * <p> * String filter = "(&(objectClass=*)(objectGUID" + EQUAL + convertObjectGUIToByteString(objectGUID) + "))"; * </p> * * @param objectGUID A raw byte array representing the value of the <code>objectGUID</code> attribute retrieved from * Active Directory. * * @return A byte-based String representation in the form of \[0]\[1]\[2]\[3]\[4]\[5]\[6]\[7]\[8]\[9]\[10]\[11]\[12]\[13]\[14]\[15] */ public static String convertObjectGUIToByteString(byte[] objectGUID) { StringBuilder result = new StringBuilder(); for (int i = 0; i < objectGUID.length; i++) { String transformed = prefixZeros((int) objectGUID[i] & 0xFF); result.append("\\"); result.append(transformed); } return result.toString(); }