<commit_before>module Gitlab
  module LDAP
    class Person
      AD_USER_DISABLED = Net::LDAP::Filter.ex("userAccountControl:1.2.840.113556.1.4.803", "2")

      def self.find_by_uid(uid, adapter=nil)
        adapter ||= Gitlab::LDAP::Adapter.new
        adapter.user(config.uid, uid)
      end

      def self.find_by_dn(dn, adapter=nil)
        adapter ||= Gitlab::LDAP::Adapter.new
        adapter.user('dn', dn)
      end

      def self.ad_disabled?(dn, adapter=nil)
        adapter ||= Gitlab::LDAP::Adapter.new
        adapter.dn_matches_filter?(dn, AD_USER_DISABLED)
      end

      def initialize(entry)
        Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
        @entry = entry
      end

      def name
        entry.cn.first
      end

      def uid
        entry.send(config.uid).first
      end

      def username
        uid
      end

      def dn
        entry.dn
      end

      private

      def entry
        @entry
      end

      def adapter
        @adapter ||= Gitlab::LDAP::Adapter.new
      end

      def config
        @config ||= Gitlab.config.ldap
      end
    end
  end
end
<commit_msg>Document the Active Directory magic numbers<commit_after>module Gitlab
  module LDAP
    class Person
      # Active Directory-specific LDAP filter that checks if bit 2 of the
      # userAccountControl attribute is set.
      # Source: http://ctogonewild.com/2009/09/03/bitmask-searches-in-ldap/
      AD_USER_DISABLED = Net::LDAP::Filter.ex("userAccountControl:1.2.840.113556.1.4.803", "2")

      def self.find_by_uid(uid, adapter=nil)
        adapter ||= Gitlab::LDAP::Adapter.new
        adapter.user(config.uid, uid)
      end

      def self.find_by_dn(dn, adapter=nil)
        adapter ||= Gitlab::LDAP::Adapter.new
        adapter.user('dn', dn)
      end

      def self.ad_disabled?(dn, adapter=nil)
        adapter ||= Gitlab::LDAP::Adapter.new
        adapter.dn_matches_filter?(dn, AD_USER_DISABLED)
      end

      def initialize(entry)
        Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
        @entry = entry
      end

      def name
        entry.cn.first
      end

      def uid
        entry.send(config.uid).first
      end

      def username
        uid
      end

      def dn
        entry.dn
      end

      private

      def entry
        @entry
      end

      def adapter
        @adapter ||= Gitlab::LDAP::Adapter.new
      end

      def config
        @config ||= Gitlab.config.ldap
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10394685423993748, 'fraction_numerical': 0.016803438843298164, 'mean_word_length': 1.9459148446490218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4479763', 'n_tokens_mistral': 862, 'n_tokens_neox': 820, 'n_words': 176}