private bool UserExistsInLdapDirectory(LdapSettings ldapSettings, LoginInfo loginInfo) { var userName = loginInfo.UserName != null?loginInfo.UserName.Trim() : loginInfo.Login; var filter = I18NHelper.FormatInvariant("(&(objectCategory={0})({1}={2}))", ldapSettings.GetEffectiveUserObjectCategoryAttribute(), ldapSettings.GetEffectiveAccountNameAttribute(), LdapHelper.EscapeLdapSearchFilter(userName)); try { var found = _authenticator.SearchLdap(ldapSettings, filter); if (found) { return(true); } _log.LogInformation(LogSourceLdap, I18NHelper.FormatInvariant("User '{0}' is not found in LDAP directory {1}", userName, ldapSettings.LdapAuthenticationUrl)); return(false); } catch (Exception ex) { _log.LogInformation(LogSourceLdap, I18NHelper.FormatInvariant("Error while searching a user in LDAP directory {0}", ldapSettings.LdapAuthenticationUrl)); _log.LogError(LogSourceLdap, ex); return(false); } }