示例#1
0
        private void CreateNewPortalGroup(DirectoryEntry entry, string parentPath, Guid guid, SyncTree syncTree)
        {
            try
            {
                AdLog.LogADObject(string.Format("New portal group - creating under {0}", parentPath), entry.Path);
                var newGroup = new Group(Node.LoadNode(parentPath));

                UpdatePortalGroupProperties(entry, newGroup, syncTree);

                Common.UpdateLastSync(newGroup, guid);
                //newGroup.Save(); - update lastsync already saves node

                if (_portalGroups != null)
                {
                    if (!_portalGroups.ContainsKey(guid.ToString()))
                    {
                        _portalGroups.Add(guid.ToString(), newGroup.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
        }
示例#2
0
        private void CreateNewPortalUser(DirectoryEntry entry, string parentPath, Guid guid, SyncTree syncTree)
        {
            try
            {
                AdLog.LogADObject(string.Format("New portal user - creating under {0}", parentPath), entry.Path);
                var newUser = new User(Node.LoadNode(parentPath), _config.UserType);

                // user actions
                UpdatePortalUserProperties(entry, newUser, syncTree);

                Common.UpdateLastSync(newUser, guid);
                //newUser.Save(); - update lastsync already saves node

                if (_portalUsers != null)
                {
                    if (!_portalUsers.ContainsKey(guid.ToString()))
                    {
                        _portalUsers.Add(guid.ToString(), newUser.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
        }
示例#3
0
        private void CreateNewPortalOrgUnit(DirectoryEntry entry, string parentPath, Guid guid, SyncTree syncTree)
        {
            try
            {
                AdLog.LogADObject(string.Format("New portal orgunit - creating under {0}", parentPath), entry.Path);
                OrganizationalUnit newOu = new OrganizationalUnit(Node.LoadNode(parentPath));

                UpdatePortalOrgUnitProperties(entry, newOu, syncTree);

                Common.UpdateLastSync(newOu, guid);
                //newOu.Save(); - update lastsync already saves node

                if (_portalContainers != null)
                {
                    if (!_portalContainers.ContainsKey(guid.ToString()))
                    {
                        _portalContainers.Add(guid.ToString(), newOu.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
        }
示例#4
0
        // gets members of an AD group and returns the corresponding list of <Guid, ADObjectType> objects
        private Dictionary <Guid, ADGroupMember> GetADGroupMembers(DirectoryEntry group, SyncTree syncTree)
        {
            var members     = new Dictionary <Guid, ADGroupMember>();
            var memberCount = group.Properties["member"].Count;

            AdLog.LogADObject(string.Format("Group contains {0} member(s).", memberCount), group.Path);
            for (int i = 0; i < memberCount; i++)
            {
                string sMemberDN = group.Properties["member"][i].ToString();

                var objSyncTree = GetSyncTreeForObject(sMemberDN);
                if (objSyncTree == null)
                {
                    AdLog.LogWarning(string.Format("AD group contains an object that is not contained in any of the synctrees, group's synctree will be used to retrieve the object (group: {0}, object: {1})", group.Path, sMemberDN));
                    objSyncTree = syncTree;
                }

                using (DirectoryEntry oADMember = objSyncTree.ConnectToObject(sMemberDN))
                {
                    if (oADMember != null)
                    {
                        var guid = Common.GetADObjectGuid(oADMember, _config.GuidProp);
                        if (guid != null)
                        {
                            var userNameProp  = oADMember.Properties[_config.UserNameProp];
                            var userNameValue = userNameProp == null ? null : userNameProp.Value;
                            if (userNameValue == null)
                            {
                                AdLog.LogError(string.Format("Property {0} of AD group member \"{1}\" is missing or value is null", _config.UserNameProp, sMemberDN));
                                continue;
                            }

                            members.Add(
                                ((Guid)guid),
                                new ADGroupMember()
                            {
                                objType        = Common.GetADObjectType(oADMember, _config.NovellSupport),
                                Path           = oADMember.Path,
                                SamAccountName = userNameValue.ToString()
                            });
                        }
                    }
                    else
                    {
                        AdLog.LogWarning(string.Format("AD group member could not be retrieved (group: {0}, object: {1})", group.Path, sMemberDN));
                    }
                }
            }
            return(members);
        }
示例#5
0
        private void CreateNewPortalDomain(DirectoryEntry entry, string parentPath, Guid guid, SyncTree syncTree)
        {
            try
            {
                AdLog.LogADObject(string.Format("New portal domain - creating under {0}", parentPath), entry.Path);
                Domain newNode = new Domain(Node.LoadNode(parentPath));

                UpdatePortalDomainProperties(entry, newNode, syncTree);

                Common.UpdateLastSync(newNode, guid);
                //newNode.Save();  - update lastsync already saves node
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
        }
示例#6
0
        private void CreateNewPortalFolder(DirectoryEntry entry, string parentPath, Guid guid, SyncTree syncTree)
        {
            try
            {
                AdLog.LogADObject(string.Format("New portal folder - creating under {0}", parentPath), entry.Path);
                //Folder newNode = new Folder(Node.LoadNode(parentPath));
                //Node newNode = new GenericContent(Node.LoadNode(parentPath), "ADFolder");
                var newNode = new ADFolder(Node.LoadNode(parentPath));

                UpdatePortalFolderProperties(entry, newNode, syncTree);

                Common.UpdateLastSync(newNode, guid);
                //newNode.Save();  - update lastsync already saves node

                if (!_portalContainers.ContainsKey(guid.ToString()))
                {
                    _portalContainers.Add(guid.ToString(), newNode.Id);
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
        }
示例#7
0
        /* ==================================================================================== AD -> portal : Main algorithms */
        // sync one object
        // két helyről hívhatjuk:
        // - SyncObjectsFromAD --> innen SearchResult objektumot kapunk
        // - SyncObjectsFromAD/EnsurePath --> innen Entryt kapunk
        //      - utóbbiból helyes működésnél csak létre kell hozni új objektumot, de ha már létezik az objektum, akkor
        //        moveoljuk, ne keletkezzen két azonos GUID-ú objektum a portálon
        private void SyncOneADObject(SearchResult result, DirectoryEntry ADentry,
                                     Guid guid,
                                     ADObjectType objType,
                                     string nodePortalParentPath,
                                     Action <DirectoryEntry, string, Guid, SyncTree> CreateNewObject,
                                     Action <DirectoryEntry, Node, SyncTree> UpdateProperties,
                                     SyncTree syncTree)
        {
            //bool validResult;
            //var node = GetNodeByGuid(guid, objType, out validResult);
            Node   node    = null;
            string guidStr = guid.ToString();

            switch (objType)
            {
            case ADObjectType.AllContainers:
                node = (_portalContainers.ContainsKey(guidStr)) ? Node.LoadNode(_portalContainers[guidStr]) : null;
                break;

            case ADObjectType.User:
                node = (_portalUsers.ContainsKey(guidStr)) ? Node.LoadNode(_portalUsers[guidStr]) : null;
                break;

            case ADObjectType.Group:
                node = (_portalGroups.ContainsKey(guidStr)) ? Node.LoadNode(_portalGroups[guidStr]) : null;
                break;

            default:
                break;
            }
            if (node != null)
            {
                // existing portal object
                try
                {
                    bool isNodeSynced = false;

                    // check path, move object if necessary
                    if (RepositoryPath.GetParentPath(node.Path) != nodePortalParentPath)
                    {
                        AdLog.LogADObject(string.Format("Moving object from {0} to {1}", node.Path, nodePortalParentPath), result.Path);
                        Node.Move(node.Path, nodePortalParentPath);

                        // reload node for further processing (set properties)
                        node         = Node.LoadNode(node.Id);
                        isNodeSynced = true;
                    }

                    if (ADentry != null)
                    {
                        // ensurepath-ból jön, mindenképp szinkronizáljuk
                        UpdateProperties(ADentry, node, syncTree);
                        AdLog.LogADObject(String.Format("Saving synced portal object: {0}", node.Path), ADentry.Path);
                        Common.UpdateLastSync(node, null);
                        //node.Save(); - update lastsync already saves node
                    }
                    else
                    {
                        // syncobjectsből jövünk, csak resultunk van (entrynk nincs)

                        // set properties and lastsync date - csak akkor szinkronizálunk, ha lastmod > x
                        // (ha az objektum át lett mozgatva, a lastmod is változik AD-ben)
                        if (_config.AlwaysSyncObjects || Common.IsPortalObjectInvalid(node, result, _config.NovellSupport))
                        {
                            using (var entry = result.GetDirectoryEntry())
                            {
                                UpdateProperties(entry, node, syncTree);
                                isNodeSynced = true;
                            }
                        }

                        if (isNodeSynced)
                        {
                            AdLog.LogADObject(String.Format("Saving synced portal object: {0}", node.Path), result.Path);
                            Common.UpdateLastSync(node, null);
                            //node.Save(); - update lastsync already saves node
                        }
                    }
                }
                catch (Exception ex)
                {
                    AdLog.LogException(ex);
                    // log: adott objektum szinkronizálása nem sikerült
                    if (result != null)
                    {
                        AdLog.LogErrorADObject("Syncing of AD object not successful.", result.Path);
                    }
                }
            }
            else
            {
                if (ADentry != null)
                {
                    // ensurepath-ból jövünk
                    CreateNewObject(ADentry, nodePortalParentPath, guid, syncTree);
                }
                else
                {
                    // syncobjectsből jövünk, csak resultunk van
                    // new portal object
                    using (var entry = result.GetDirectoryEntry())
                    {
                        CreateNewObject(entry, nodePortalParentPath, guid, syncTree);
                    }
                }
            }
        }