public LdapConnection(string container) { var settings = LdapConfigurationsHelper.GetSettings(); Settings = settings ?? throw new ConfigurationErrorsException("Please check your LdapConfiguration on app / web.config"); Username = settings.Username; Password = settings.Password; Context = new PrincipalContext(ContextType.Domain, settings.Server.Replace("LDAP://", ""), container, string.IsNullOrEmpty(settings.Domain) ? Username : settings.Domain + "\\" + settings.Username, Password); if (!ValidateCredentials()) { Context = null; throw new InvalidCredentialException("Invalid credentials! Please check your configurations."); } var server = Settings.Server; if (!server.StartsWith("LDAP://")) { server = string.Concat("LDAP://", server); } DirectoryEntry = new DirectoryEntry($"{server}/{container}", string.IsNullOrEmpty(settings.Domain) ? Username : settings.Domain + "\\" + settings.Username, Password, (AuthenticationTypes)Enum.Parse(typeof(AuthenticationTypes), settings.AuthenticationType, true)); }
public static LdapSettingsElement GetSettings() { LdapSettingsElement result = null; var config = LdapConfiguration.GetConfig(); var settings = config.LdapSettings; if (settings.Count > 0) { result = settings[0]; } return(result); }
protected LdapLibRepository(LdapConnection ldapConnection) { Context = ldapConnection.Context; DirectoryEntry = ldapConnection.DirectoryEntry; Settings = ldapConnection.Settings; }