diff --git a/lib/gitlab/ldap/adapter.rb b/lib/gitlab/ldap/adapter.rb
index 7bdcb4b974319517e9d39be586d58f8984ff3da5..e36616f0e666833ef64c54a21a26b7d1d8d35e70 100644
--- a/lib/gitlab/ldap/adapter.rb
+++ b/lib/gitlab/ldap/adapter.rb
@@ -77,6 +77,10 @@ module Gitlab
         users(*args).first
       end
 
+      def dn_matches_filter?(dn, filter)
+        ldap_search(base: dn, filter: filter, scope: Net::LDAP::SearchScope_BaseObject, attributes: %w{dn}).any?
+      end
+
       def ldap_search(*args)
         results = ldap.search(*args)
 
diff --git a/spec/lib/gitlab/ldap/ldap_adapter_spec.rb b/spec/lib/gitlab/ldap/ldap_adapter_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..c3f07334431721028c5d5789290ef1ea38d5b6d5
--- /dev/null
+++ b/spec/lib/gitlab/ldap/ldap_adapter_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe Gitlab::LDAP::Adapter do
+  let(:adapter) { Gitlab::LDAP::Adapter.new }
+
+  describe :dn_matches_filter? do
+    let(:ldap) { double(:ldap) }
+    subject { adapter.dn_matches_filter?(:dn, :filter) }
+    before { adapter.stub(ldap: ldap) }
+
+    context "when the search is successful" do
+      context "and the result is non-empty" do
+        before { ldap.stub(search: [:foo]) }
+
+        it { should be_true }
+      end
+
+      context "and the result is empty" do
+        before { ldap.stub(search: []) }
+
+        it { should be_false }
+      end
+    end
+
+    context "when the search encounters an error" do
+      before { ldap.stub(search: nil, get_operation_result: double(code: 1, message: 'some error')) }
+
+      it { should be_false }
+    end
+  end
+end