protected LdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig) { _settings = settings; _ldapModuleConfig = ldapModuleConfig; //3: Do not write logs if no Logger supplied. _logger = NullLogger.Instance; }
//private bool useRootDn = false; public Task <LdapUser> TryLdapLogin(ILdapSettings ldapSettings, string userName, string password) { bool success = false; LdapUser user = null; DirectoryEntry directoryEntry = null; try { //if (useRootDn) //{ // directoryEntry = new DirectoryEntry("LDAP://" + ldapSettings.LdapServer + "/" + ldapSettings.LdapRootDN, ldapSettings.LdapDomain + "\\" + userName, password); //} //else //{ //directoryEntry = new DirectoryEntry("LDAP://" + ldapSettings.LdapServer, ldapSettings.LdapDomain + "\\" + userName, password); //} if (ldapSettings.LdapUseSsl) { directoryEntry = new DirectoryEntry("LDAP://" + ldapSettings.LdapServer, ldapSettings.LdapDomain + "\\" + userName, password, AuthenticationTypes.SecureSocketsLayer); } else { directoryEntry = new DirectoryEntry("LDAP://" + ldapSettings.LdapServer, ldapSettings.LdapDomain + "\\" + userName, password); } } catch (Exception ex) { string msg = $"Login failure for user: {userName} Exception: {ex.Message}:{ex.StackTrace}"; _log.LogError(msg); } if (directoryEntry != null) { //Bind to the native AdsObject to force authentication. try { object testobj = directoryEntry.NativeObject; success = true; } catch (Exception ex) { string msg = $"Login failure for user: {userName} Exception: {ex.Message}:{ex.StackTrace}"; _log.LogError(msg); success = false; } if (success && directoryEntry != null) { user = GetLdapUser(directoryEntry, ldapSettings, userName); } } return(Task.FromResult(user)); }
private LdapConnection GetConnection(ILdapSettings ldapSettings, bool useSsl = false) { LdapConnection conn = new LdapConnection(); if (useSsl) { // make this support ssl/tls //http://stackoverflow.com/questions/386982/novell-ldap-c-novell-directory-ldap-has-anybody-made-it-work conn.SecureSocketLayer = true; conn.UserDefinedServerCertValidationDelegate += LdapSSLCertificateValidator; } conn.Connect(ldapSettings.LdapServer, ldapSettings.LdapPort); return(conn); }
public Task <LdapUser> TryLdapLogin(ILdapSettings ldapSettings, string userName, string password) { LdapUser user = null; var isValid = ValidateUser(ldapSettings, userName, password); if (isValid) { user = new LdapUser() { CommonName = userName }; } return(Task.FromResult(user)); }
private LdapUser GetLdapUser(DirectoryEntry directoryEntry, ILdapSettings ldapSettings, string userName) { DirectorySearcher ds = new DirectorySearcher(directoryEntry); ds.Filter = "(&(sAMAccountName=" + userName + "))"; SearchResult result = ds.FindOne(); DirectoryEntry ent = null; if (result != null) { ent = result.GetDirectoryEntry(); } if (ent != null) { var user = new LdapUser(); if (ent.Properties["cn"].Value != null) { user.CommonName = ent.Properties["cn"].Value.ToString(); } else { user.CommonName = userName; } if (ent.Properties["mail"].Value != null) { user.Email = ent.Properties["mail"].Value.ToString(); } return(user); } return(null); }
private bool ValidateUser( ILdapSettings settings, string username, string password) { string userDn; switch (settings.LdapUserDNFormat) { case "username@LDAPDOMAIN": userDn = $"{username}@{settings.LdapDomain}"; break; default: userDn = $"{settings.LdapDomain}\\{username}"; break; } //string userDn = $"{settings.LdapUserDNKey}={username}"; try { using (var connection = GetConnection(settings, settings.LdapUseSsl)) { connection.Bind(userDn, password); if (connection.Bound) { return(true); } } } catch (Exception ex) { _log.LogError($"{ex.Message}:{ex.StackTrace}"); } return(false); }
public AppLdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig) : base(settings, ldapModuleConfig) { }
protected LdapAuthenticationSource(ILdapSettings settings, ICodeZeroLdapModuleConfig ldapModuleConfig) { _settings = settings; _ldapModuleConfig = ldapModuleConfig; }
protected LdapAuthenticationSource(ILdapSettings settings, IStudioXZeroLdapModuleConfig ldapModuleConfig) { this.settings = settings; this.ldapModuleConfig = ldapModuleConfig; }
public Task <LdapUser> TryLdapLogin(ILdapSettings ldapSettings, string userName, string password) { throw new NotImplementedException(); }
public MyLdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig) : base(settings, ldapModuleConfig) { _settings = settings; _ldapModuleConfig = ldapModuleConfig; }
public MyLdapAuthenticationSource(ILdapSettings settings, IStudioXZeroLdapModuleConfig ldapModuleConfig) : base(settings, ldapModuleConfig) { }
public EtkLdapAuthenticationSource(ILdapSettings settings, ISheshaLdapModuleConfig ldapModuleConfig) : base(settings, ldapModuleConfig) { }
public LdapExternalAuthenticationSource(ILdapSettings settings) { _settings = settings; }