feat(LDAP): LDAP设置中添加对phone字段的属性映射

This commit is contained in:
shiziyuan9527 2020-07-29 18:32:05 +08:00
parent 560a22a186
commit cdc790e90d
2 changed files with 18 additions and 0 deletions

View File

@ -54,11 +54,17 @@ public class LdapController {
// 新建用户 获取LDAP映射属性
String name = ldapService.getMappingAttr("name", dirContext);
String phone = ldapService.getNotRequiredMappingAttr("phone", dirContext);
User user = new User();
user.setId(userId);
user.setName(name);
user.setEmail(email);
if (StringUtils.isNotBlank(phone)) {
user.setPhone(phone);
}
user.setSource(UserSource.LDAP.name());
userService.addLdapUser(user);
}

View File

@ -213,6 +213,18 @@ public class LdapService {
return result;
}
public String getNotRequiredMappingAttr(String attr, DirContextOperations dirContext) {
String mapping = getLdapMapping();
JSONObject jsonObject = JSONObject.parseObject(mapping);
String mapAttr = jsonObject.getString(attr);
if (StringUtils.isNotBlank(mapAttr)) {
return dirContext.getStringAttribute(mapAttr);
}
return mapAttr;
}
public boolean isOpen() {
String open = service.getValue(ParamConstants.LDAP.OPEN.getValue());
if (StringUtils.isBlank(open)) {