Sha256: bcc1a9c0223b3427866a3ad9b43d09d934a0bf3430b2b4dbfc5386bfe84e973e

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

require "net-ldap"
require "delegate"

module Ddr
  module Auth
    class LdapGateway < SimpleDelegator

      SCOPE = Net::LDAP::SearchScope_SingleLevel

      def initialize
        super Net::LDAP.new(config)
      end

      # Returns a list of affiliations for a principal (person)
      # @param eppn [String] the eduPersonPrincipalName value
      # @return [Array] the list of affiliations for the principal
      def affiliations(eppn)
        filter = Net::LDAP::Filter.eq("eduPersonPrincipalName", eppn)
        result_set = search(scope: SCOPE,
                        filter: filter,
                        size: 1,
                        attributes: ["eduPersonAffiliation"])
        if result_set
          result = result_set.first
          result ? result[:edupersonaffiliation] : []
        else # error
          Rails.logger.error get_operation_result.message
          []
        end
      end

      private

      def config
        { host: ENV["LDAP_HOST"],
          port: ENV["LDAP_PORT"],
          base: ENV["LDAP_BASE"]
        }
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ddr-models-1.17.1 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.17.0 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.16.2 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.16.1 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.16.0 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.15.0 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.14.2 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.14.1 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.14.0 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.13.2 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.13.1 lib/ddr/auth/ldap_gateway.rb
ddr-models-1.13.0 lib/ddr/auth/ldap_gateway.rb