Example #1
0
        public void Setup()
        {
            var appSettings = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).AppSettings;

            if (!appSettings.Settings.AllKeys.Contains("LdapUserPassword"))
            {
                _connection = new LdapServerConnection
                {
                    Server = appSettings.Settings["LdapServer"].Value
                };
            }
            else
            {
                _connection = new LdapServerConnection
                {
                    Server      = appSettings.Settings["LdapServer"].Value,
                    Credentials = new System.Net.NetworkCredential(appSettings.Settings["LdapUserName"].Value, appSettings.Settings["LdapUserPassword"].Value, appSettings.Settings["LdapUserDomain"].Value)
                };
            }

            if (_connection.Credentials != null && !string.IsNullOrEmpty(_connection.Credentials.Password))
            {
                _directoryEntry = new DirectoryEntry(_connection.ServerUrl, $"{_connection.Credentials.Domain}\\{_connection.Credentials.UserName}", _connection.Credentials.Password);
            }
            else
            {
                _directoryEntry = new DirectoryEntry(_connection.ServerUrl);
            }
        }
Example #2
0
        public void Setup()
        {
            var appSettings = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).AppSettings;

            if (!appSettings.Settings.AllKeys.Contains("LdapUserPassword"))
            {
                _connection = new LdapServerConnection
                {
                    Server = appSettings.Settings["LdapServer"].Value
                };
            }
            else
            {
                _connection = new LdapServerConnection
                {
                    Server      = appSettings.Settings["LdapServer"].Value,
                    Credentials = new System.Net.NetworkCredential(appSettings.Settings["LdapUserName"].Value, appSettings.Settings["LdapUserPassword"].Value, appSettings.Settings["LdapUserDomain"].Value)
                };
            }

            _connectionManager = new LdapConnectionManager(_connection);
        }
Example #3
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            ILdapSettingsService ldapSettings = new LdapSettingsService();

            SetLdapSettings(ldapSettings);

            ILdapServerConnection ldapServerConnection = new LdapServerConnection();
            IAccountService       accountService       = new LdapAccountService();

            ILoginService loginService = new LoginService(ldapServerConnection, accountService);
            var           response     = loginService.Login(ldapSettings);

            if (response.User == null)
            {
                lblError.Visible   = true;
                lblError.InnerText = response.ResponseMessage;
            }
            else
            {
                SignIn(response.User);
                SaveLdapConnection(ldapServerConnection);
                Response.Redirect(Global.DashboardPage);
            }
        }