Ejemplo n.º 1
0
        public DomainUserDto ProvideLogin(string login, string password)
        {
            var domainUserName = $"{login}@{_config.DomainName}";

            _connection.Connect(_config.ServerName, _config.ServerPort);

            _connection.Bind(domainUserName, password);

            var searchFilter = string.Format(_config.SearchFilter, login);

            var result = _connection.Search(
                _config.SearchBase,
                LdapConnection.SCOPE_SUB,
                searchFilter,
                _attributes,
                false
                );

            var ldapData = result.next()?.getAttributeSet();

            if (ldapData == null)
            {
                throw new AuthenticationException("Given login or password are not correct . Please try again");
            }

            var user = UserAdapter.Adapt(ldapData);

            return(user);
        }