|
|
@@ -53,15 +53,16 @@ public class ADSyncService {
|
|
|
if(employee.getEm_adid()!=null){
|
|
|
//判断是否需要更新组织
|
|
|
if("离职".equals(employee.getEm_class())){
|
|
|
- deleteUser(employee.getEm_adid(),connection);
|
|
|
+ disableUser(employee.getEm_adid(),connection);
|
|
|
baseDao.updateByCondition("employee","em_adid=null","em_code='"+employee.getEm_code()+"'");
|
|
|
}
|
|
|
Optional<HrOrg> orgOptional = orgList.stream().filter(org -> org.getOr_code().equals(employee.getOrcode())).findFirst();
|
|
|
logger.info("同步用户更新:{}",employee.getEm_name());
|
|
|
+ updateUserDescription(employee.getEm_adid(),employee.getEmjob());
|
|
|
if(orgOptional.isPresent()){
|
|
|
String newOUPath = getOUPath(orgOptional.get().getOr_path());
|
|
|
logger.info("同步用户更新:oldpath{},newpath{}",getUserOUPath(employee.getEm_adid()),newOUPath);
|
|
|
- if(employee.getEm_code().equals("ADMIN") && !getUserOUPath(employee.getEm_adid()).equals(newOUPath)){
|
|
|
+ if(!getUserOUPath(employee.getEm_adid()).equals(newOUPath)){
|
|
|
moveUser(employee.getEm_adid(),"CN="+employee.getEm_name()+","+newOUPath,connection);
|
|
|
baseDao.updateByCondition("employee","em_adid='CN="+employee.getEm_name()+","+newOUPath+"'","em_code='"+employee.getEm_code()+"'");
|
|
|
}
|
|
|
@@ -90,6 +91,7 @@ public class ADSyncService {
|
|
|
"objectClass: person",
|
|
|
"objectClass: organizationalPerson",
|
|
|
"objectClass: user",
|
|
|
+ "userAccountControl: 512",
|
|
|
"sAMAccountName: " + userName,
|
|
|
"userPrincipalName: " + userName + "@" + adConfig.getBaseDn().replace("DC=", "").replace(",", "."),
|
|
|
"userPassword: " + password
|
|
|
@@ -105,6 +107,54 @@ public class ADSyncService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ //更新用户信息
|
|
|
+ public void updateUserDescription(String userName, String newDescription) {
|
|
|
+ LdapConnection connection = null;
|
|
|
+ try {
|
|
|
+ connection = ldapConnectionManager.getConnection();
|
|
|
+ Dn dn = new Dn( userName);
|
|
|
+ Entry entry = new DefaultEntry(
|
|
|
+ dn,
|
|
|
+ "objectClass: top",
|
|
|
+ "objectClass: organizationalPerson"
|
|
|
+ );
|
|
|
+ connection.modify(dn, new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "description", newDescription));
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("updateOrgDescription 更新组织描述失败:{}",e.getMessage());
|
|
|
+ }finally {
|
|
|
+ if (connection != null) {
|
|
|
+ try {
|
|
|
+ connection.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void disableUser(String userDn, LdapConnection connection) {
|
|
|
+ if(connection==null || !connection.isConnected()){
|
|
|
+ connection = ldapConnectionManager.getConnection();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Dn dn = new Dn( userDn);
|
|
|
+ Entry entry = new DefaultEntry(
|
|
|
+ dn,
|
|
|
+ "objectClass: top",
|
|
|
+ "objectClass: organizationalPerson"
|
|
|
+ );
|
|
|
+ connection.modify(dn, new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "userAccountControl", "2"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("updateOrgDescription 禁用账号失败:{}",e.getMessage());
|
|
|
+ }finally {
|
|
|
+ if (connection != null) {
|
|
|
+ try {
|
|
|
+ connection.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
public void deleteUser(String userDn, LdapConnection connection) {
|
|
|
if(connection==null || !connection.isConnected()){
|
|
|
connection = ldapConnectionManager.getConnection();
|
|
|
@@ -145,6 +195,7 @@ public class ADSyncService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //移动人员组织
|
|
|
}
|
|
|
public List<ADUser> getUsers(LdapConnection connection) throws IOException {
|
|
|
List<ADUser> userList = new ArrayList<>();
|