mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 17:08:29 +08:00
synchronizer-activedirectory
This commit is contained in:
parent
506a2200b0
commit
4b973880c9
@ -64,7 +64,38 @@ public class HistorySynchronizer extends JpaBaseEntity implements Serializable
|
||||
String startDate;
|
||||
String endDate;
|
||||
|
||||
public String getId() {
|
||||
public HistorySynchronizer(String id, String syncId, String syncName, String objectId,
|
||||
String objectType, String objectName, String syncTime, String result,String instId) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.syncId = syncId;
|
||||
this.syncName = syncName;
|
||||
this.objectId = objectId;
|
||||
this.objectType = objectType;
|
||||
this.objectName = objectName;
|
||||
this.syncTime = syncTime;
|
||||
this.result = result;
|
||||
this.instId = instId;
|
||||
}
|
||||
|
||||
|
||||
public HistorySynchronizer(String id, String syncId, String sessionId, String syncName, String objectId,
|
||||
String objectType, String objectName, String syncTime, String result, String instId) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.syncId = syncId;
|
||||
this.sessionId = sessionId;
|
||||
this.syncName = syncName;
|
||||
this.objectId = objectId;
|
||||
this.objectType = objectType;
|
||||
this.objectName = objectName;
|
||||
this.syncTime = syncTime;
|
||||
this.result = result;
|
||||
this.instId = instId;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
|
||||
@ -65,11 +65,11 @@ public class ActiveDirectoryOrganizationService extends AbstractSynchronizerSer
|
||||
Object obj = results.nextElement();
|
||||
if (obj instanceof SearchResult) {
|
||||
SearchResult sr = (SearchResult) obj;
|
||||
if(sr.getNameInNamespace().contains("OU=Domain Controllers")) {
|
||||
_logger.info("Skip 'OU=Domain Controllers' .");
|
||||
if(sr.getNameInNamespace().contains("OU=Domain Controllers")||StringUtils.isEmpty(sr.getName())) {
|
||||
_logger.info("Skip '' or 'OU=Domain Controllers' .");
|
||||
continue;
|
||||
}
|
||||
_logger.debug("Sync OrganizationalUnit {} , name {} , NameInNamespace {}" ,
|
||||
_logger.debug("Sync OrganizationalUnit {} , name [{}] , NameInNamespace [{}]" ,
|
||||
(++recordCount),sr.getName(),sr.getNameInNamespace());
|
||||
|
||||
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
|
||||
@ -114,15 +114,16 @@ public class ActiveDirectoryOrganizationService extends AbstractSynchronizerSer
|
||||
organizationsService.saveOrUpdate(organization);
|
||||
orgsNamePathMap.put(organization.getNamePath(), organization);
|
||||
|
||||
HistorySynchronizer historySynchronizer =new HistorySynchronizer();
|
||||
historySynchronizer.setId(historySynchronizer.generateId());
|
||||
historySynchronizer.setSyncId(this.synchronizer.getId());
|
||||
historySynchronizer.setSyncName(this.synchronizer.getName());
|
||||
historySynchronizer.setObjectId(organization.getId());
|
||||
historySynchronizer.setObjectName(organization.getName());
|
||||
historySynchronizer.setObjectType(Organizations.class.getSimpleName());
|
||||
historySynchronizer.setInstId(synchronizer.getInstId());
|
||||
historySynchronizer.setResult("success");
|
||||
HistorySynchronizer historySynchronizer
|
||||
= new HistorySynchronizer(synchronizer.generateId(),
|
||||
this.synchronizer.getId(),
|
||||
this.synchronizer.getName(),
|
||||
organization.getId(),
|
||||
organization.getName(),
|
||||
Organizations.class.getSimpleName(),
|
||||
org.maxkey.util.DateUtils.getCurrentDateAsString(),
|
||||
"success",
|
||||
synchronizer.getInstId());
|
||||
this.historySynchronizerService.insert(historySynchronizer);
|
||||
}
|
||||
}
|
||||
@ -140,9 +141,7 @@ public class ActiveDirectoryOrganizationService extends AbstractSynchronizerSer
|
||||
try {
|
||||
Organizations org = new Organizations();
|
||||
org.setLdapDn(nameInNamespace);
|
||||
nameInNamespace = nameInNamespace.replaceAll(",OU=", "/").replaceAll("OU=", "/");
|
||||
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
|
||||
String []namePaths = nameInNamespace.split("/");
|
||||
String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
|
||||
String namePah= "/"+rootOrganization.getName();
|
||||
for(int i = namePaths.length -1 ; i >= 0 ; i --) {
|
||||
namePah = namePah + "/" + namePaths[i];
|
||||
|
||||
@ -65,7 +65,7 @@ public class ActiveDirectoryUsersService extends AbstractSynchronizerService
|
||||
_logger.trace("Skip 'CN=Users' or 'OU=Domain Controllers' . ");
|
||||
continue;
|
||||
}
|
||||
_logger.debug("Sync User {} , name {} , NameInNamespace {}" ,
|
||||
_logger.debug("Sync User {} , name [{}] , NameInNamespace [{}]" ,
|
||||
(++recordCount),sr.getName(),sr.getNameInNamespace());
|
||||
|
||||
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
|
||||
@ -99,14 +99,12 @@ public class ActiveDirectoryUsersService extends AbstractSynchronizerService
|
||||
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setLdapDn(nameInNamespace);
|
||||
nameInNamespace = nameInNamespace.replaceAll(",OU=", "/").replaceAll("OU=", "/").replaceAll("CN=", "/");
|
||||
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
|
||||
_logger.info("nameInNamespace " + nameInNamespace);
|
||||
String []namePaths = nameInNamespace.split("/");
|
||||
String namePah= "/"+rootOrganization.getName();
|
||||
for(int i = namePaths.length -1 ; i>=1 ;i--) {
|
||||
namePah = namePah + "/"+namePaths[i];
|
||||
}
|
||||
String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
|
||||
String namePah= "/"+rootOrganization.getName();
|
||||
for(int i = namePaths.length -1 ; i >= 0 ; i --) {
|
||||
namePah = namePah + "/" + namePaths[i];
|
||||
}
|
||||
|
||||
//namePah = namePah.substring(0, namePah.length());
|
||||
String deptNamePath= namePah.substring(0, namePah.lastIndexOf("/"));
|
||||
_logger.info("deptNamePath " + deptNamePath);
|
||||
|
||||
@ -64,7 +64,7 @@ public class LdapOrganizationService extends AbstractSynchronizerService implem
|
||||
Object obj = results.nextElement();
|
||||
if (obj instanceof SearchResult) {
|
||||
SearchResult sr = (SearchResult) obj;
|
||||
_logger.debug("Sync OrganizationalUnit {} , name {} , NameInNamespace {}" ,
|
||||
_logger.debug("Sync OrganizationalUnit {} , name [{}] , NameInNamespace [{}]" ,
|
||||
(++recordCount),sr.getName(),sr.getNameInNamespace());
|
||||
|
||||
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
|
||||
@ -133,14 +133,13 @@ public class LdapOrganizationService extends AbstractSynchronizerService implem
|
||||
try {
|
||||
Organizations org = new Organizations();
|
||||
org.setLdapDn(nameInNamespace);
|
||||
nameInNamespace = nameInNamespace.replaceAll(",ou=", "/").replaceAll("ou=", "/");
|
||||
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
|
||||
String []namePaths = nameInNamespace.split("/");
|
||||
String namePah= "/"+rootOrganization.getName();
|
||||
for(int i = namePaths.length -1 ; i>=0 ;i--) {
|
||||
namePah = namePah + "/"+namePaths[i];
|
||||
}
|
||||
namePah = namePah.substring(0, namePah.length() -1);
|
||||
String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
|
||||
String namePah= "/"+rootOrganization.getName();
|
||||
for(int i = namePaths.length -1 ; i >= 0 ; i --) {
|
||||
namePah = namePah + "/" + namePaths[i];
|
||||
}
|
||||
|
||||
namePah = namePah.substring(0, namePah.length() - 1);
|
||||
|
||||
org.setId(org.generateId());
|
||||
org.setCode(org.getId());
|
||||
|
||||
@ -58,7 +58,7 @@ public class LdapUsersService extends AbstractSynchronizerService implements IS
|
||||
Object obj = results.nextElement();
|
||||
if (obj instanceof SearchResult) {
|
||||
SearchResult sr = (SearchResult) obj;
|
||||
_logger.debug("Sync User {} , name {} , NameInNamespace {}" ,
|
||||
_logger.debug("Sync User {} , name [{}] , NameInNamespace [{}]" ,
|
||||
(++recordCount),sr.getName(),sr.getNameInNamespace());
|
||||
|
||||
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
|
||||
@ -93,14 +93,12 @@ public class LdapUsersService extends AbstractSynchronizerService implements IS
|
||||
public UserInfo buildUserInfo(HashMap<String,Attribute> attributeMap,String name,String nameInNamespace) {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setLdapDn(nameInNamespace);
|
||||
nameInNamespace = nameInNamespace.replaceAll(",ou=", "/").replaceAll("ou=", "/").replaceAll("uid=", "/").replaceAll("cn=", "/");
|
||||
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
|
||||
_logger.info("nameInNamespace " + nameInNamespace);
|
||||
String []namePaths = nameInNamespace.split("/");
|
||||
String namePah= "/"+rootOrganization.getName();
|
||||
for(int i = namePaths.length -1 ; i>=1 ;i--) {
|
||||
namePah = namePah + "/"+namePaths[i];
|
||||
}
|
||||
String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
|
||||
String namePah= "/"+rootOrganization.getName();
|
||||
for(int i = namePaths.length -1 ; i >= 0 ; i --) {
|
||||
namePah = namePah + "/" + namePaths[i];
|
||||
}
|
||||
|
||||
//namePah = namePah.substring(0, namePah.length());
|
||||
String deptNamePath= namePah.substring(0, namePah.lastIndexOf("/"));
|
||||
_logger.info("deptNamePath " + deptNamePath);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user