feat: LDAP设置中支持多个OU

This commit is contained in:
shiziyuan9527 2020-07-14 11:05:01 +08:00
parent 686baea129
commit f9b2cdc20d
1 changed files with 18 additions and 11 deletions

View File

@ -57,11 +57,15 @@ public class PersonRepoImpl implements PersonRepo {
LdapTemplate ldapTemplate = getConnection();
String filter = getUserFilter();
String ou = getUserOu();
String[] arr = getUserOu();
List<Person> result = null;
for (String ou : arr) {
try {
result = ldapTemplate.search(query().base(ou).filter(filter, username), getContextMapper());
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) {
@ -69,6 +73,7 @@ public class PersonRepoImpl implements PersonRepo {
} catch (InvalidSearchFilterException e) {
MSException.throwException(Translator.get("login_fail_filter_error"));
}
}
if (result.size() != 1) {
MSException.throwException(Translator.get("user_not_found_or_not_unique"));
@ -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() {