Spring Security 3.1 Active Directory を使用しています。
私は、AD 構造の識別名属性から OU 値を取得する必要がある AD 構造を持っています。
私が望む OU は、常に最後の DC の後の最初の OU になります。
以下は私のコード例です - myCompany OU value を取得する必要があります。これを行うにはもっと良い方法があるはずです:
パブリック クラス テスト {
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);
}
}
これにより、次が出力されます。
s: cn=harry,ou=myCompany,ou=customers,dc=this,dc=that
s1: myCompany,ou=customers,dc=this,dc=that
s2: myCompany
誰でも助けてもらえますか?