Exemplo n.º 1
0
        private void SetOldSetting(MappingFields field, string value)
        {
            if (LdapMapping == null)
            {
                LdapMapping = new Dictionary <MappingFields, string>();
            }

            if (string.IsNullOrEmpty(value))
            {
                if (LdapMapping.ContainsKey(field))
                {
                    LdapMapping.Remove(field);
                }
                return;
            }

            if (LdapMapping.ContainsKey(field))
            {
                LdapMapping[field] = value;
            }
            else
            {
                LdapMapping.Add(field, value);
            }
        }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            var settings = obj as LdapSettings;

            return(settings != null &&
                   EnableLdapAuthentication == settings.EnableLdapAuthentication &&
                   StartTls == settings.StartTls &&
                   Ssl == settings.Ssl &&
                   (string.IsNullOrEmpty(Server) &&
                    string.IsNullOrEmpty(settings.Server) ||
                    Server == settings.Server) &&
                   (string.IsNullOrEmpty(UserDN) &&
                    string.IsNullOrEmpty(settings.UserDN) ||
                    UserDN == settings.UserDN) &&
                   PortNumber == settings.PortNumber &&
                   UserFilter == settings.UserFilter &&
                   LoginAttribute == settings.LoginAttribute &&
                   LdapMapping.Count == settings.LdapMapping.Count &&
                   LdapMapping.All(pair => settings.LdapMapping.ContainsKey(pair.Key) &&
                                   pair.Value == settings.LdapMapping[pair.Key]) &&
                   AccessRights.Count == settings.AccessRights.Count &&
                   AccessRights.All(pair => settings.AccessRights.ContainsKey(pair.Key) &&
                                    pair.Value == settings.AccessRights[pair.Key]) &&
                   GroupMembership == settings.GroupMembership &&
                   (string.IsNullOrEmpty(GroupDN) &&
                    string.IsNullOrEmpty(settings.GroupDN) ||
                    GroupDN == settings.GroupDN) &&
                   GroupFilter == settings.GroupFilter &&
                   UserAttribute == settings.UserAttribute &&
                   GroupAttribute == settings.GroupAttribute &&
                   (string.IsNullOrEmpty(Login) &&
                    string.IsNullOrEmpty(settings.Login) ||
                    Login == settings.Login) &&
                   Authentication == settings.Authentication);
        }
Exemplo n.º 3
0
        private string GetOldSetting(MappingFields field)
        {
            if (LdapMapping == null)
            {
                LdapMapping = new Dictionary <MappingFields, string>();
            }

            if (LdapMapping.ContainsKey(field))
            {
                return(LdapMapping[field]);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates an existing LDAP mapping
        /// </summary>
        /// <param name="mapping"></param>
        /// <returns></returns>
        public async Task <IdentityResult> UpdateLdapMappingAsync(LdapMapping mapping)
        {
            Ensure.Argument.NotNull(mapping, "ldapMapping");

            var result = await DeleteLdapMappingAsync(mapping.Id);

            if (!result.Succeeded)
            {
                return(result);
            }

            // clear the id since this will be a new entry
            mapping.Id = 0;

            return(await AddLdapMappingAsync(mapping));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a new LDAP mapping
        /// </summary>
        /// <param name="mapping"></param>
        /// <returns></returns>
        public async Task <IdentityResult> AddLdapMappingAsync(LdapMapping mapping)
        {
            Ensure.Argument.NotNull(mapping, "ldapMapping");
            Ensure.Argument.Is(mapping.Id == 0, "Id cannot be supplied when adding new LDAP mappings");
            IdentityResult result;

            try
            {
                _db.LdapMappings.Add(mapping);
                await _db.SaveChangesAsync();

                result = IdentityResult.Success;
            }
            catch (Exception ex)
            {
                result = IdentityResult.Failed(new IdentityError()
                {
                    Description = ex.Message
                });
            }

            return(result);
        }