feat: LDAP设置中支持多个OU
This commit is contained in:
parent
686baea129
commit
f9b2cdc20d
|
@ -57,17 +57,22 @@ public class PersonRepoImpl implements PersonRepo {
|
|||
LdapTemplate ldapTemplate = getConnection();
|
||||
|
||||
String filter = getUserFilter();
|
||||
String ou = getUserOu();
|
||||
String[] arr = getUserOu();
|
||||
|
||||
List<Person> result = null;
|
||||
try {
|
||||
result = ldapTemplate.search(query().base(ou).filter(filter, username), getContextMapper());
|
||||
} catch (NameNotFoundException e) {
|
||||
MSException.throwException(Translator.get("login_fail_ou_error"));
|
||||
} catch (InvalidNameException e) {
|
||||
MSException.throwException(Translator.get("login_fail_ou_error"));
|
||||
} catch (InvalidSearchFilterException e) {
|
||||
MSException.throwException(Translator.get("login_fail_filter_error"));
|
||||
for (String ou : arr) {
|
||||
try {
|
||||
result = ldapTemplate.search(query().base(ou.trim()).filter(filter, username), getContextMapper());
|
||||
if (result.size() == 1) {
|
||||
return result.get(0);
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
MSException.throwException(Translator.get("login_fail_ou_error"));
|
||||
} catch (InvalidNameException e) {
|
||||
MSException.throwException(Translator.get("login_fail_ou_error"));
|
||||
} catch (InvalidSearchFilterException e) {
|
||||
MSException.throwException(Translator.get("login_fail_filter_error"));
|
||||
}
|
||||
}
|
||||
|
||||
if (result.size() != 1) {
|
||||
|
@ -87,14 +92,16 @@ public class PersonRepoImpl implements PersonRepo {
|
|||
return filter;
|
||||
}
|
||||
|
||||
private String getUserOu() {
|
||||
private String[] getUserOu() {
|
||||
String ou = service.getValue(ParamConstants.LDAP.OU.getValue());
|
||||
|
||||
if (StringUtils.isBlank(ou)) {
|
||||
MSException.throwException(Translator.get("ldap_ou_is_null"));
|
||||
}
|
||||
|
||||
return ou;
|
||||
String[] arr = ou.split("\\|");
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
protected ContextMapper getContextMapper() {
|
||||
|
|
Loading…
Reference in New Issue