I am using Spring Security 3.1 Active Directory.
I have a AD structure, where I need to get an OU value out of the AD structural distinguishedName attribute.
The OU that I want, will always be the first OU after the last DC.
below is my code example – I need to get the myCompany OU value, there must be a better way to do this:
public class Test {
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);
}
}
This outputs the following:
s: cn=harry,ou=myCompany,ou=customers,dc=this,dc=that
s1: myCompany,ou=customers,dc=this,dc=that
s2: myCompany
Can anyone help please?
Regex! Pick your flavor below (first or second):