Ver código fonte

开通邮箱增加3种字符判断

zhouy 4 meses atrás
pai
commit
28067b3e4a

+ 8 - 0
src/main/java/com/uas/eis/entity/Employee.java

@@ -15,6 +15,7 @@ public class Employee {
     private String em_mobile;
     private String em_yonghongid;
     private String em_email;
+    private String emjob;
     public String getEm_code() {
         return em_code;
     }
@@ -126,6 +127,13 @@ public class Employee {
     public void setEm_email(String em_email) {
         this.em_email = em_email;
     }
+    public String getEmjob() {
+        return emjob;
+    }
+
+    public void setEmjob(String emjob) {
+        this.emjob = emjob;
+    }
 
     @Override
     public String toString() {

+ 53 - 2
src/main/java/com/uas/eis/serviceImpl/ADSyncService.java

@@ -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<>();

+ 14 - 1
src/main/java/com/uas/eis/serviceImpl/NetEasyService.java

@@ -113,7 +113,7 @@ public class NetEasyService {
                 .addParam("job", employee.getEm_position())
                 .addParam("jobNumber", employee.getEm_code())
                 .addParam("unitId", employee.getOrneteasyid());
-        if(employee.getEm_password().length() >=8){
+        if(employee.getEm_password().length() >=8 && hasThreeCharacterTypes(employee.getEm_password())){
             q.addParam("password", employee.getEm_password());
         }
         if(StringUtil.hasText(employee.getEm_mobile())){
@@ -453,4 +453,17 @@ public class NetEasyService {
         return 0;
     }
 
+    private boolean hasThreeCharacterTypes(String password) {
+        int typeCount = 0;
+        // 检查是否包含大写字母
+        if (password.matches(".*[A-Z].*")) typeCount++;
+        // 检查是否包含小写字母
+        if (password.matches(".*[a-z].*")) typeCount++;
+        // 检查是否包含数字
+        if (password.matches(".*[0-9].*")) typeCount++;
+        // 检查是否包含特殊符号(非字母数字)
+        if (password.matches(".*[^A-Za-z0-9].*")) typeCount++;
+        return typeCount >= 3;
+    }
+
 }

+ 4 - 2
src/main/java/com/uas/eis/serviceImpl/UasSyncService.java

@@ -15,8 +15,10 @@ public class UasSyncService {
     private BaseDao baseDao;
 
     public List<Employee> getADUserList() {
-        return  baseDao.query("select em_code,em_name,or_code orcode,em_class,em_adid,em_emptype,em_position  from employee  left join hrorg on em_defaultorid=or_id"+
-                " where em_adid is not  null or em_class<>'离职' order by em_id asc"
+        return  baseDao.query("select em_code,em_name,or_code orcode,em_class,em_adid,em_emptype,(select wm_concat(jo_name) from employee A left join empsjobs on em_id=emp_id left join job" +
+                        "            on (job_id=jo_id or em_defaulthsid=jo_id ) where a.em_id=b.em_id) emjob from employee b" +
+                        " left join hrorg on em_defaultorid=or_id" +
+                        "               where em_adid is not  null or em_class<>'离职' order by em_id asc"
                 ,
                 Employee.class);
     }

+ 12 - 1
src/test/java/com/uas/eis/UasEisApplicationTests.java

@@ -52,13 +52,23 @@ public class UasEisApplicationTests {
 		adSyncService.addUser("abcd", displayName, "OU=人力资源部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad", "password123");
 	}
 
+	@Test
+	public void moveUser() throws LdapException, UnsupportedEncodingException {
+		adSyncService.moveUser( "CN=刘健荣,OU=安全厂务部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad", "CN=刘健荣,OU=安全管理部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad",null);
+	}
+
 	@Test
 	public void deleteuser() throws Exception {
 	 adSyncService.deleteUser("CN=测试,OU=人力资源部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad", null);
 	}
 	@Test
+	public void disableUser() throws Exception {
+		adSyncService.disableUser("CN=黄谨怡,OU=党群部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad", null);
+	}
+	@Test
 	public void deleteOrg() throws Exception {
-		adSyncService.deleteOrg("OU=测试,OU=人力资源部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad", null);
+		adSyncService.deleteOrg("OU=安全厂务部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad", null);
+		//adSyncService.deleteOrg("OU=测试组织,OU=综合管理部,OU=经营班子,OU=董事会,OU=User,DC=si,DC=ad", null);
 	}
 
 	@Test
@@ -74,6 +84,7 @@ public class UasEisApplicationTests {
 		adSyncService.syncOrg();
 	}
 
+
 	@Test
 	public void SyncUser() throws Exception {
 		adSyncService.syncUser();