private void SyncSingleObjectFromAD(string ldapPath)
{
SyncTree syncTree = null;
DirectoryEntry entry = null;
foreach (SyncTree sTree in _syncTrees)
{
if (sTree.ContainsADPath(ldapPath))
{
entry = sTree.ConnectToObject(ldapPath);
syncTree = sTree;
}
}
if (syncTree == null)
{
AdLog.LogErrorADObject("Configured SyncTree could not be found for this path", ldapPath);
return;
}
string nodePortalParentPath = syncTree.GetPortalParentPath(ldapPath);
if (!Node.Exists(nodePortalParentPath))
{
AdLog.LogErrorADObject(string.Format("Portal parent path ({0}) does not exist", nodePortalParentPath), ldapPath);
return;
}
if (entry == null)
{
AdLog.LogErrorADObject("AD Entry is not found", ldapPath);
return;
}
var guid = Common.GetADObjectGuid(entry, _config.GuidProp);
if (!guid.HasValue)
{
AdLog.LogErrorADObject("AD Entry guid cannot be retrieved", ldapPath);
return;
}
var adObjectType = Common.GetADObjectType(entry, false);
Action<DirectoryEntry, string, Guid, SyncTree> CreateNewObject = null;
Action<DirectoryEntry, Node, SyncTree> UpdateProperties = null;
switch (adObjectType)
{
case ADObjectType.User:
CreateNewObject = CreateNewPortalUser;
UpdateProperties = UpdatePortalUserProperties;
break;
case ADObjectType.Group:
CreateNewObject = CreateNewPortalGroup;
UpdateProperties = UpdatePortalGroupProperties;
break;
case ADObjectType.Container:
case ADObjectType.Organization:
case ADObjectType.OrgUnit:
CreateNewObject = CreateNewPortalContainer;
UpdateProperties = UpdatePortalContainerProperties;
break;
default:
AdLog.LogErrorADObject("Syncing of this type is not supported.", ldapPath);
return;
}
// check if node already exists:
var node = Common.GetPortalObjectByGuid(guid.Value);
if (node == null)
{
if (!Node.Exists(nodePortalParentPath))
EnsurePortalPath(syncTree, syncTree.GetADParentObjectPath(ldapPath), RepositoryPath.GetParentPath(nodePortalParentPath));
CreateNewObject(entry, nodePortalParentPath, guid.Value, syncTree);
}
else
{
if (RepositoryPath.GetParentPath(node.Path) != nodePortalParentPath)
{
Node.Move(node.Path, nodePortalParentPath);
// reload node for further processing (set properties)
node = Node.LoadNode(node.Id);
}
UpdateProperties(entry, node, syncTree);
Common.UpdateLastSync(node, null);
}
}