protected LdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig)
 {
     _settings         = settings;
     _ldapModuleConfig = ldapModuleConfig;
     //3: Do not write logs if no Logger supplied.
     _logger = NullLogger.Instance;
 }
Esempio n. 2
0
        //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));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 public AppLdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig)
     : base(settings, ldapModuleConfig)
 {
 }
Esempio n. 8
0
 protected LdapAuthenticationSource(ILdapSettings settings, ICodeZeroLdapModuleConfig ldapModuleConfig)
 {
     _settings         = settings;
     _ldapModuleConfig = ldapModuleConfig;
 }
Esempio n. 9
0
 protected LdapAuthenticationSource(ILdapSettings settings, IStudioXZeroLdapModuleConfig ldapModuleConfig)
 {
     this.settings         = settings;
     this.ldapModuleConfig = ldapModuleConfig;
 }
Esempio n. 10
0
 public Task <LdapUser> TryLdapLogin(ILdapSettings ldapSettings, string userName, string password)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
 public MyLdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig)
     : base(settings, ldapModuleConfig)
 {
     _settings         = settings;
     _ldapModuleConfig = ldapModuleConfig;
 }
            public MyLdapAuthenticationSource(ILdapSettings settings, IStudioXZeroLdapModuleConfig ldapModuleConfig)
                : base(settings, ldapModuleConfig)
            {

            }
Esempio n. 13
0
 public EtkLdapAuthenticationSource(ILdapSettings settings, ISheshaLdapModuleConfig ldapModuleConfig)
     : base(settings, ldapModuleConfig)
 {
 }
Esempio n. 14
0
 public LdapExternalAuthenticationSource(ILdapSettings settings)
 {
     _settings = settings;
 }