public GetADParentObjectPath ( string objectADPath ) : string | ||
objectADPath | string | |
리턴 | string |
// sync objects from AD to portal private void SyncObjectsFromAD(SyncTree syncTree, ADObjectType objType, SearchResultCollection allADObjects, Action <DirectoryEntry, string, Guid, SyncTree> CreateNewObject, Action <DirectoryEntry, Node, SyncTree> UpdateProperties) { foreach (SearchResult result in allADObjects) { try { string nodeADpath = result.Path; if (syncTree.IsADPathExcluded(nodeADpath)) { continue; } AdLog.LogOuterADObject("Syncing", result.Path); var guid = Common.GetADResultGuid(result, _config.GuidProp); if (!guid.HasValue) { // no AD guid present for object AdLog.LogErrorADObject("No AD GUID present", result.Path); continue; } // új objektumok (ou, user, group) felvétele, átmozgatások // - ha létezik az adott guid-ú objektum -> path ellenőrzés, átmozgatás // - ha nem létezik, létrehozás string nodePortalParentPath = syncTree.GetPortalParentPath(nodeADpath); if (!Node.Exists(nodePortalParentPath)) { // adpath: OU=OtherOrg,OU=ExampleOrg,DC=Nativ,DC=local // portalParentPath: "/Root/IMS/NATIV/ExampleOrg" EnsurePortalPath(syncTree, syncTree.GetADParentObjectPath(result.Path), RepositoryPath.GetParentPath(nodePortalParentPath)); } SyncOneADObject(result, null, (Guid)guid, objType, nodePortalParentPath, CreateNewObject, UpdateProperties, syncTree); } catch (Exception ex) { // syncing of one object of the current tree failed AdLog.LogException(ex); } } }
// adpath: OU=OtherOrg,OU=ExampleOrg,DC=Nativ,DC=local // portalParentPath: "/Root/IMS/Nativ.Local/ExampleOrg" private void EnsurePortalPath(SyncTree syncTree, string ADPath, string portalParentPath) { // portalParentPath does not exist if (!Node.Exists(portalParentPath)) { // get parent AD object string ADparentPath = syncTree.GetADParentObjectPath(ADPath); // ensurepath EnsurePortalPath(syncTree, ADparentPath, RepositoryPath.GetParentPath(portalParentPath)); } // portalParentPath exists, so AD object should be synchronized here // domain, container, orgunit using (DirectoryEntry entry = syncTree.ConnectToObject(ADPath)) { var guid = Common.GetADObjectGuid(entry, _config.GuidProp); if (!guid.HasValue) { return; } SyncOneADObject(null, entry, (Guid)guid, ADObjectType.AllContainers, portalParentPath, CreateNewPortalContainer, UpdatePortalContainerProperties, syncTree); } }
// sync objects from AD to portal private void SyncObjectsFromAD(SyncTree syncTree, ADObjectType objType, SearchResultCollection allADObjects, Action<DirectoryEntry, string, Guid, SyncTree> CreateNewObject, Action<DirectoryEntry, Node, SyncTree> UpdateProperties) { foreach (SearchResult result in allADObjects) { try { string nodeADpath = result.Path; if (syncTree.IsADPathExcluded(nodeADpath)) continue; AdLog.LogOuterADObject("Syncing", result.Path); var guid = Common.GetADResultGuid(result, _config.GuidProp); if (!guid.HasValue) { // no AD guid present for object AdLog.LogErrorADObject("No AD GUID present", result.Path); continue; } // új objektumok (ou, user, group) felvétele, átmozgatások // - ha létezik az adott guid-ú objektum -> path ellenőrzés, átmozgatás // - ha nem létezik, létrehozás string nodePortalParentPath = syncTree.GetPortalParentPath(nodeADpath); if (!Node.Exists(nodePortalParentPath)) { // adpath: OU=OtherOrg,OU=ExampleOrg,DC=Nativ,DC=local // portalParentPath: "/Root/IMS/NATIV/ExampleOrg" EnsurePortalPath(syncTree, syncTree.GetADParentObjectPath(result.Path), RepositoryPath.GetParentPath(nodePortalParentPath)); } SyncOneADObject(result, null, (Guid)guid, objType, nodePortalParentPath, CreateNewObject, UpdateProperties, syncTree); } catch (Exception ex) { // syncing of one object of the current tree failed AdLog.LogException(ex); } } }
// adpath: OU=OtherOrg,OU=ExampleOrg,DC=Nativ,DC=local // portalParentPath: "/Root/IMS/Nativ.Local/ExampleOrg" private void EnsurePortalPath(SyncTree syncTree, string ADPath, string portalParentPath) { // portalParentPath does not exist if (!Node.Exists(portalParentPath)) { // get parent AD object string ADparentPath = syncTree.GetADParentObjectPath(ADPath); // ensurepath EnsurePortalPath(syncTree, ADparentPath, RepositoryPath.GetParentPath(portalParentPath)); } // portalParentPath exists, so AD object should be synchronized here // domain, container, orgunit using (DirectoryEntry entry = syncTree.ConnectToObject(ADPath)) { var guid = Common.GetADObjectGuid(entry, _config.GuidProp); if (!guid.HasValue) return; SyncOneADObject(null, entry, (Guid)guid, ADObjectType.AllContainers, portalParentPath, CreateNewPortalContainer, UpdatePortalContainerProperties, syncTree); } }
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); } }