Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1025457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:55:52+00:00 2026-05-16T11:55:52+00:00

I am trying to get LDAP authentication to work under Rails. I have chosen

  • 0

I am trying to get LDAP authentication to work under Rails.
I have chosen net/ldap since it’s a native Ruby LDAP library.

I have tried all possible stuff, specially examples from http://net-ldap.rubyforge.org/classes/Net/LDAP.html but still unable to get it work.
Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:55:52+00:00Added an answer on May 16, 2026 at 11:55 am

    The best solution I managed to reach is a Model with the following:

    require 'net/ldap'
    
    class User < ActiveRecord::Base
    
      def after_initialize
        @config = YAML.load(ERB.new(File.read("#{Rails.root}/config/ldap.yml")).result)[Rails.env]
      end
    
      def ldap_auth(user, pass)
        ldap = initialize_ldap_con
        result = ldap.bind_as(
          :base => @config['base_dn'],
          :filter => "(#{@config['attributes']['id']}=#{user})",
          :password => pass
        )
        if result
          # fetch user DN
          get_user_dn user
          sync_ldap_with_db user
        end
        nil
      end
    
      private
      def initialize_ldap_con
        options = { :host => @config['host'],
                    :port => @config['port'],
                    :encryption => (@config['tls'] ? :simple_tls : nil),
                    :auth => { 
                      :method => :simple,
                      :username => @config['ldap_user'],
                      :password => @config['ldap_password']
                    }
                  }
        Net::LDAP.new options
      end
    
      def get_user_dn(user)
        ldap = initialize_ldap_con
        login_filter = Net::LDAP::Filter.eq @config['attributes']['id'], "#{user}"
        object_filter = Net::LDAP::Filter.eq "objectClass", "*" 
    
        ldap.search :base => @config['base_dn'],
                    :filter => object_filter & login_filter,
                    :attributes => ['dn', @config['attributes']['first_name'], @config['attributes']['last_name'], @config['attributes']['mail']] do |entry|
          logger.debug "DN: #{entry.dn}"
          entry.each do |attr, values|
            values.each do |value|
              logger.debug "#{attr} = #{value}"
            end
          end
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get ldap authentication to work on Plone version 4.2. I
I am trying get Struts 2 and Tiles to work and I am using
Trying to get this expression to work, can someone look at it and tell
I am trying to implement LDAP authentication on the ADAM LDAP server of my
I'm currently trying to implement Devise with LDAP Authentication on RAILS3. I've got it
I'm trying to build user authentication against our LDAP: settings.py: AUTHENTICATION_BACKENDS = ( 'django_auth_ldap.backend.LDAPBackend',
I'm trying to search in a LDAP server all the users that have some
I am trying to get the following connection to our LDAP working via ColdFusion,
I'm trying to get a list of users from the Active Directory, who have
I have a VSTO Outlook 2007 add-in. I am trying to get sender e-mail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.