1
 def authenticate(username, password)
        require 'net-ldap'
        ldap = Net::LDAP.new
        ldap.host = 'server.local'
        ldap.port = 389
        ldap.base = 'cn=users, dc=server, dc=local'
        ldap.auth username, password
        if ldap.bind
            puts "authentication succeeded"
            else
            puts "authentication failed"
        end

The above is the code i use in my method and i am not sure why my attempts fail. I am trying to authenticate user. I could not find where i am going wrong? It puts authentication failed every time. why? please help me.

9
  • Are you initializing username and password anywhere? Commented Apr 18, 2013 at 7:14
  • I have edited my code. I get the username and password as shown. Commented Apr 18, 2013 at 7:16
  • Can you try commenting out ldap.base = 'cn=users, dc=server, dc=local'? Net::LDAP initializes base, and the default base value might just work. Commented Apr 18, 2013 at 7:19
  • I have tried and that too results the same. Commented Apr 18, 2013 at 7:22
  • Is your local ldap server running? Commented Apr 18, 2013 at 7:22

1 Answer 1

1

First up see if the computer you are using can talk to the LDAP server

telnet server.local 389

Obviously you want to be replacing server.local with your actual server details. If you can't log into the server this way then port 389 isn't open and you may need to be running on the SSL port 636. Try the previous command with 636 rather than 389 to see if that is the case.

If you are unable to telnet into the server on either of those ports you've either got a firewall rule blocking you from talking to it, LDAP is configured on a non standard port or something else is seriously wrong.

A working port 636 will probably mean you need to run something like the following.

require "net-ldap"
ldap = Net::LDAP.new(
    host: "server.local"
    port: 636
    encryption: :simple_tls
)
ldap.auth username, password

Failing all of that an error message is going to be pretty useful so try running

if ldap.bind
    # Yay!
else
    puts ldap.get_operation_result
end

With some results from this maybe we can help you a bit more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.