synchronizer-activedirectory

This commit is contained in:
MaxKey 2022-01-27 11:18:30 +08:00
parent 506a2200b0
commit 4b973880c9
5 changed files with 68 additions and 43 deletions

View File

@ -64,6 +64,37 @@ public class HistorySynchronizer extends JpaBaseEntity implements Serializable
String startDate; String startDate;
String endDate; String endDate;
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() { public String getId() {
return id; return id;
} }

View File

@ -65,11 +65,11 @@ public class ActiveDirectoryOrganizationService extends AbstractSynchronizerSer
Object obj = results.nextElement(); Object obj = results.nextElement();
if (obj instanceof SearchResult) { if (obj instanceof SearchResult) {
SearchResult sr = (SearchResult) obj; SearchResult sr = (SearchResult) obj;
if(sr.getNameInNamespace().contains("OU=Domain Controllers")) { if(sr.getNameInNamespace().contains("OU=Domain Controllers")||StringUtils.isEmpty(sr.getName())) {
_logger.info("Skip 'OU=Domain Controllers' ."); _logger.info("Skip '' or 'OU=Domain Controllers' .");
continue; continue;
} }
_logger.debug("Sync OrganizationalUnit {} , name {} , NameInNamespace {}" , _logger.debug("Sync OrganizationalUnit {} , name [{}] , NameInNamespace [{}]" ,
(++recordCount),sr.getName(),sr.getNameInNamespace()); (++recordCount),sr.getName(),sr.getNameInNamespace());
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>(); HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
@ -114,15 +114,16 @@ public class ActiveDirectoryOrganizationService extends AbstractSynchronizerSer
organizationsService.saveOrUpdate(organization); organizationsService.saveOrUpdate(organization);
orgsNamePathMap.put(organization.getNamePath(), organization); orgsNamePathMap.put(organization.getNamePath(), organization);
HistorySynchronizer historySynchronizer =new HistorySynchronizer(); HistorySynchronizer historySynchronizer
historySynchronizer.setId(historySynchronizer.generateId()); = new HistorySynchronizer(synchronizer.generateId(),
historySynchronizer.setSyncId(this.synchronizer.getId()); this.synchronizer.getId(),
historySynchronizer.setSyncName(this.synchronizer.getName()); this.synchronizer.getName(),
historySynchronizer.setObjectId(organization.getId()); organization.getId(),
historySynchronizer.setObjectName(organization.getName()); organization.getName(),
historySynchronizer.setObjectType(Organizations.class.getSimpleName()); Organizations.class.getSimpleName(),
historySynchronizer.setInstId(synchronizer.getInstId()); org.maxkey.util.DateUtils.getCurrentDateAsString(),
historySynchronizer.setResult("success"); "success",
synchronizer.getInstId());
this.historySynchronizerService.insert(historySynchronizer); this.historySynchronizerService.insert(historySynchronizer);
} }
} }
@ -140,9 +141,7 @@ public class ActiveDirectoryOrganizationService extends AbstractSynchronizerSer
try { try {
Organizations org = new Organizations(); Organizations org = new Organizations();
org.setLdapDn(nameInNamespace); org.setLdapDn(nameInNamespace);
nameInNamespace = nameInNamespace.replaceAll(",OU=", "/").replaceAll("OU=", "/"); String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
String []namePaths = nameInNamespace.split("/");
String namePah= "/"+rootOrganization.getName(); String namePah= "/"+rootOrganization.getName();
for(int i = namePaths.length -1 ; i >= 0 ; i --) { for(int i = namePaths.length -1 ; i >= 0 ; i --) {
namePah = namePah + "/" + namePaths[i]; namePah = namePah + "/" + namePaths[i];

View File

@ -65,7 +65,7 @@ public class ActiveDirectoryUsersService extends AbstractSynchronizerService
_logger.trace("Skip 'CN=Users' or 'OU=Domain Controllers' . "); _logger.trace("Skip 'CN=Users' or 'OU=Domain Controllers' . ");
continue; continue;
} }
_logger.debug("Sync User {} , name {} , NameInNamespace {}" , _logger.debug("Sync User {} , name [{}] , NameInNamespace [{}]" ,
(++recordCount),sr.getName(),sr.getNameInNamespace()); (++recordCount),sr.getName(),sr.getNameInNamespace());
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>(); HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
@ -99,14 +99,12 @@ public class ActiveDirectoryUsersService extends AbstractSynchronizerService
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
userInfo.setLdapDn(nameInNamespace); userInfo.setLdapDn(nameInNamespace);
nameInNamespace = nameInNamespace.replaceAll(",OU=", "/").replaceAll("OU=", "/").replaceAll("CN=", "/"); String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
_logger.info("nameInNamespace " + nameInNamespace);
String []namePaths = nameInNamespace.split("/");
String namePah= "/"+rootOrganization.getName(); String namePah= "/"+rootOrganization.getName();
for(int i = namePaths.length -1 ; i>=1 ;i--) { for(int i = namePaths.length -1 ; i >= 0 ; i --) {
namePah = namePah + "/"+namePaths[i]; namePah = namePah + "/" + namePaths[i];
} }
//namePah = namePah.substring(0, namePah.length()); //namePah = namePah.substring(0, namePah.length());
String deptNamePath= namePah.substring(0, namePah.lastIndexOf("/")); String deptNamePath= namePah.substring(0, namePah.lastIndexOf("/"));
_logger.info("deptNamePath " + deptNamePath); _logger.info("deptNamePath " + deptNamePath);

View File

@ -64,7 +64,7 @@ public class LdapOrganizationService extends AbstractSynchronizerService implem
Object obj = results.nextElement(); Object obj = results.nextElement();
if (obj instanceof SearchResult) { if (obj instanceof SearchResult) {
SearchResult sr = (SearchResult) obj; SearchResult sr = (SearchResult) obj;
_logger.debug("Sync OrganizationalUnit {} , name {} , NameInNamespace {}" , _logger.debug("Sync OrganizationalUnit {} , name [{}] , NameInNamespace [{}]" ,
(++recordCount),sr.getName(),sr.getNameInNamespace()); (++recordCount),sr.getName(),sr.getNameInNamespace());
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>(); HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
@ -133,14 +133,13 @@ public class LdapOrganizationService extends AbstractSynchronizerService implem
try { try {
Organizations org = new Organizations(); Organizations org = new Organizations();
org.setLdapDn(nameInNamespace); org.setLdapDn(nameInNamespace);
nameInNamespace = nameInNamespace.replaceAll(",ou=", "/").replaceAll("ou=", "/"); String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
String []namePaths = nameInNamespace.split("/");
String namePah= "/"+rootOrganization.getName(); String namePah= "/"+rootOrganization.getName();
for(int i = namePaths.length -1 ; i>=0 ;i--) { for(int i = namePaths.length -1 ; i >= 0 ; i --) {
namePah = namePah + "/"+namePaths[i]; namePah = namePah + "/" + namePaths[i];
} }
namePah = namePah.substring(0, namePah.length() -1);
namePah = namePah.substring(0, namePah.length() - 1);
org.setId(org.generateId()); org.setId(org.generateId());
org.setCode(org.getId()); org.setCode(org.getId());

View File

@ -58,7 +58,7 @@ public class LdapUsersService extends AbstractSynchronizerService implements IS
Object obj = results.nextElement(); Object obj = results.nextElement();
if (obj instanceof SearchResult) { if (obj instanceof SearchResult) {
SearchResult sr = (SearchResult) obj; SearchResult sr = (SearchResult) obj;
_logger.debug("Sync User {} , name {} , NameInNamespace {}" , _logger.debug("Sync User {} , name [{}] , NameInNamespace [{}]" ,
(++recordCount),sr.getName(),sr.getNameInNamespace()); (++recordCount),sr.getName(),sr.getNameInNamespace());
HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>(); 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) { public UserInfo buildUserInfo(HashMap<String,Attribute> attributeMap,String name,String nameInNamespace) {
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
userInfo.setLdapDn(nameInNamespace); userInfo.setLdapDn(nameInNamespace);
nameInNamespace = nameInNamespace.replaceAll(",ou=", "/").replaceAll("ou=", "/").replaceAll("uid=", "/").replaceAll("cn=", "/"); String []namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
nameInNamespace = nameInNamespace.substring(0, nameInNamespace.length() - ldapUtils.getBaseDN().length() - 1);
_logger.info("nameInNamespace " + nameInNamespace);
String []namePaths = nameInNamespace.split("/");
String namePah= "/"+rootOrganization.getName(); String namePah= "/"+rootOrganization.getName();
for(int i = namePaths.length -1 ; i>=1 ;i--) { for(int i = namePaths.length -1 ; i >= 0 ; i --) {
namePah = namePah + "/"+namePaths[i]; namePah = namePah + "/" + namePaths[i];
} }
//namePah = namePah.substring(0, namePah.length()); //namePah = namePah.substring(0, namePah.length());
String deptNamePath= namePah.substring(0, namePah.lastIndexOf("/")); String deptNamePath= namePah.substring(0, namePah.lastIndexOf("/"));
_logger.info("deptNamePath " + deptNamePath); _logger.info("deptNamePath " + deptNamePath);