예제 #1
0
 /// <summary>
 /// ######### ########## ##### LDAP.
 /// </summary>
 private void InsertLDAPGroups(List <LdapGroup> ldapElements)
 {
     foreach (var ldapElement in ldapElements)
     {
         var entity     = new LDAPElement(CurrentUserConnection);
         var conditions = new Dictionary <string, object> {
             { "LDAPEntryId", ldapElement.Id },
             { "Type", (int)Core.DB.SysAdminUnitType.Team }
         };
         lock (_lockObject) {
             if (!entity.FetchFromDB(conditions))
             {
                 entity.SetDefColumnValues();
                 entity.SetColumnValue("Type", (int)Core.DB.SysAdminUnitType.Team);
                 entity.SetColumnValue("IsActive", true);
                 entity.SetColumnValue("LDAPEntryId", ldapElement.Id);
             }
             else if (entity.Name == ldapElement.Name && entity.LDAPEntryDN == ldapElement.Dn)
             {
                 continue;
             }
             entity.SetColumnValue("Name", ldapElement.Name);
             entity.SetColumnValue("LDAPEntryDN", ldapElement.Dn);
             entity.Save();
         }
     }
 }
예제 #2
0
        /// <summary>
        /// ######### ########## ############# LDAP.
        /// </summary>
        private void InsertLDAPUsers(List <LdapUser> ldapElements, Guid ldapGroupId)
        {
            var activeLdapElements = ldapElements.Where(item => item.IsActive).ToList();

            foreach (var ldapElement in activeLdapElements)
            {
                var entity     = new LDAPElement(CurrentUserConnection);
                var conditions = new Dictionary <string, object> {
                    { "LDAPEntryId", ldapElement.Id },
                    { "Type", (int)Core.DB.SysAdminUnitType.User }
                };
                lock (_lockObject) {
                    if (!entity.FetchFromDB(conditions))
                    {
                        entity.SetDefColumnValues();
                        entity.SetColumnValue("Type", (int)Core.DB.SysAdminUnitType.User);
                        entity.SetColumnValue("IsActive", true);
                        entity.SetColumnValue("LDAPEntryId", ldapElement.Id);
                    }
                    entity.SetColumnValue("Name", ldapElement.Name);
                    entity.SetColumnValue("FullName", ldapElement.FullName);
                    entity.SetColumnValue("Company", ldapElement.Company);
                    entity.SetColumnValue("Email", ldapElement.Email);
                    entity.SetColumnValue("Phone", ldapElement.Phone);
                    entity.SetColumnValue("JobTitle", ldapElement.JobTitle);
                    entity.SetColumnValue("LDAPEntryDN", ldapElement.Dn);
                    entity.Save();
                    Guid ldapUserId      = entity.PrimaryColumnValue;
                    var  esqLdapLElement = new EntitySchemaQuery(CurrentUserConnection.EntitySchemaManager, "LDAPUserInLDAPGroup");
                    esqLdapLElement.AddColumn("LDAPUser");
                    esqLdapLElement.Filters.Add(esqLdapLElement.CreateFilterWithParameters(
                                                    FilterComparisonType.Equal, "LDAPUser", ldapUserId));
                    esqLdapLElement.Filters.Add(esqLdapLElement.CreateFilterWithParameters(
                                                    FilterComparisonType.Equal, "LDAPGroup", ldapGroupId));
                    var collection = esqLdapLElement.GetEntityCollection(CurrentUserConnection);
                    if (collection.Count == 0)
                    {
                        var userInLDAPGroupEntity = new Terrasoft.Configuration.LDAPUserInLDAPGroup(CurrentUserConnection);
                        userInLDAPGroupEntity.SetDefColumnValues();
                        userInLDAPGroupEntity.SetColumnValue("LDAPUserId", ldapUserId);
                        userInLDAPGroupEntity.SetColumnValue("LDAPGroupId", ldapGroupId);
                        userInLDAPGroupEntity.Save();
                    }
                }
            }
        }
예제 #3
0
        private void DeactivateDeletedLDAPGroups(List <LdapGroup> ldapElements)
        {
            if (!_userConnection.GetIsFeatureEnabled("DeactivateExcludedLdapUsers"))
            {
                return;
            }
            var selectLocalGroups =
                new Select(CurrentUserConnection)
                .Column("LDAPEntryId")
                .From("LDAPElement")
                .Where("Type").IsEqual(Column.Parameter((int)Core.DB.SysAdminUnitType.Team)) as Select;
            var localGroups = new List <string>();

            selectLocalGroups.ExecuteReader(dataReader => {
                localGroups.Add(dataReader.GetColumnValue <string>("LDAPEntryId"));
            });
            var existingGroups = ldapElements.Select(element => element.Id).ToList();
            var missingGroups  = localGroups.Except(existingGroups).ToList();

            _log.DebugFormat("{0} groups don't exist on server.", missingGroups.Count);
            foreach (string groupId in missingGroups)
            {
                var ldapElement = new LDAPElement(CurrentUserConnection);
                var conditions  = new Dictionary <string, object> {
                    { "LDAPEntryId", groupId }
                };
                lock (_lockObject) {
                    if (ldapElement.FetchFromDB(conditions))
                    {
                        var deleteLdapUserInGroup = new Delete(CurrentUserConnection)
                                                    .From("LDAPUserInLDAPGroup")
                                                    .Where("LDAPGroupId").IsEqual(Column.Parameter(ldapElement.Id));
                        deleteLdapUserInGroup.Execute();
                        ldapElement.SetColumnValue("IsActive", false);
                        ldapElement.Save();
                    }
                }
            }
        }