Retrieve the first OU in search of distinguishedName attribute
<p>I am using Spring Security 3.1 Active Directory.</p>

<p>I have a AD structure, where I need to get an OU value out of the AD structural distinguishedName attribute.</p>

<p>The OU that I want, will always be the first OU after the last DC.</p>

<p>below is my code example - <strong>I need to get the myCompany OU value</strong>, there must be a better way to do this:</p>

<p>public class Test {</p>

<pre><code>public static void main(String[] args) {

    String s = "cn=harry,cn=group,ou=myCompany,ou=customers,dc=this,dc=that";

    System.out.println("s: "+s);

    String s1 = s.substring(s.indexOf("ou=") + 3);

    System.out.println("s1: "+s1);

    String s2 = s1.substring(s1.indexOf(""), s1.indexOf(",ou="));

    System.out.println("s2: "+s2);

}
</code></pre>

<p>}</p>

<p>This outputs the following:</p>

<pre><code>s: cn=harry,ou=myCompany,ou=customers,dc=this,dc=that 
s1: myCompany,ou=customers,dc=this,dc=that 
s2: myCompany
</code></pre>

<p>Can anyone help please?</p>
