@Test public void organizationalUnit() { assertNull(LdapUtils.getOrganizationalUnit(null)); assertNull(LdapUtils.getOrganizationalUnit(null, null)); assertNull(LdapUtils.getOrganizationalUnit(null, "")); assertNull(LdapUtils.getOrganizationalUnit("cn=hurzel")); assertNull(LdapUtils.getOrganizationalUnit("cn=hurzel", null)); assertNull(LdapUtils.getOrganizationalUnit("cn=hurzel", "")); assertEquals("ou=users", LdapUtils.getOrganizationalUnit("cn=hurzel,ou=users", "")); assertEquals("ou=users", LdapUtils.getOrganizationalUnit("cn=hurzel", "ou=users")); assertEquals("ou=intern,ou=users", LdapUtils.getOrganizationalUnit("cn=hurzel,ou=intern,ou=users", "")); assertEquals("ou=intern,ou=users", LdapUtils.getOrganizationalUnit("cn=hurzel,ou=intern", "ou=users")); assertEquals("ou=intern,ou=users", LdapUtils.getOrganizationalUnit("cn=hurzel", "ou=intern,ou=users")); }
public static String getOrganizationalUnit(final String dn) { if (dn == null || !dn.contains("ou=")) { return null; } final String[] entries = StringUtils.split(dn, ","); final StringBuilder buf = new StringBuilder(); boolean first = true; for (String entry : entries) { if (entry == null) { continue; } entry = entry.trim(); if (!entry.startsWith("ou=") || entry.length() < 4) { continue; } if (first) { first = false; } else { buf.append(","); } buf.append(entry); } return buf.toString(); }
LdapUtils { public static String getOrganizationalUnit(final String dn) { if (dn == null || !dn.contains("ou=")) { return null; } final String[] entries = StringUtils.split(dn, ","); final StringBuilder buf = new StringBuilder(); boolean first = true; for (String entry : entries) { if (entry == null) { continue; } entry = entry.trim(); if (!entry.startsWith("ou=") || entry.length() < 4) { continue; } if (first) { first = false; } else { buf.append(","); } buf.append(entry); } return buf.toString(); } }
LdapUtils { public static String getOrganizationalUnit(final String dn) { if (dn == null || !dn.contains("ou=")) { return null; } final String[] entries = StringUtils.split(dn, ","); final StringBuilder buf = new StringBuilder(); boolean first = true; for (String entry : entries) { if (entry == null) { continue; } entry = entry.trim(); if (!entry.startsWith("ou=") || entry.length() < 4) { continue; } if (first) { first = false; } else { buf.append(","); } buf.append(entry); } return buf.toString(); }  }
LdapUtils { public static String getOrganizationalUnit(final String dn) { if (dn == null || !dn.contains("ou=")) { return null; } final String[] entries = StringUtils.split(dn, ","); final StringBuilder buf = new StringBuilder(); boolean first = true; for (String entry : entries) { if (entry == null) { continue; } entry = entry.trim(); if (!entry.startsWith("ou=") || entry.length() < 4) { continue; } if (first) { first = false; } else { buf.append(","); } buf.append(entry); } return buf.toString(); }  static String escapeCommonName(final String name); static String getOu(final String... organizationalUnits); static String getOu(final String ou, final String[] organizationalUnits); static void buildOu(final StringBuffer buf, final String ou, final String[] organizationalUnits); static void buildOu(final StringBuffer buf, final String... organizationalUnits); static void appendOu(final StringBuffer buf, final String... organizationalUnits); static String getOrganizationalUnit(final String dn); static String getOrganizationalUnit(final String dn, final String ouBase); static Object getAttributeValue(final Attributes attributes, final String attrId); static String getAttributeStringValue(final Attributes attributes, final String attrId); static String[] getAttributeStringValues(final Attributes attributes, final String attrId); static Integer getAttributeIntegerValue(final Attributes attributes, final String attrId); static Attribute putAttribute(final Attributes attributes, final String attrId, final String attrValue); static String splitMultipleAttribute(final String attrId, final String value); static List<String> getMissedObjectClasses(final String[] expectedAdditionalObjectClasses, final String expectedObjectClass,
      final String[] objectClasses); }
LdapUtils { public static String getOrganizationalUnit(final String dn) { if (dn == null || !dn.contains("ou=")) { return null; } final String[] entries = StringUtils.split(dn, ","); final StringBuilder buf = new StringBuilder(); boolean first = true; for (String entry : entries) { if (entry == null) { continue; } entry = entry.trim(); if (!entry.startsWith("ou=") || entry.length() < 4) { continue; } if (first) { first = false; } else { buf.append(","); } buf.append(entry); } return buf.toString(); }  static String escapeCommonName(final String name); static String getOu(final String... organizationalUnits); static String getOu(final String ou, final String[] organizationalUnits); static void buildOu(final StringBuffer buf, final String ou, final String[] organizationalUnits); static void buildOu(final StringBuffer buf, final String... organizationalUnits); static void appendOu(final StringBuffer buf, final String... organizationalUnits); static String getOrganizationalUnit(final String dn); static String getOrganizationalUnit(final String dn, final String ouBase); static Object getAttributeValue(final Attributes attributes, final String attrId); static String getAttributeStringValue(final Attributes attributes, final String attrId); static String[] getAttributeStringValues(final Attributes attributes, final String attrId); static Integer getAttributeIntegerValue(final Attributes attributes, final String attrId); static Attribute putAttribute(final Attributes attributes, final String attrId, final String attrValue); static String splitMultipleAttribute(final String attrId, final String value); static List<String> getMissedObjectClasses(final String[] expectedAdditionalObjectClasses, final String expectedObjectClass,
      final String[] objectClasses);  }