LDAP Server not connected error

V

Varun Goel

hi all i made authentication function like this
require 'net/ldap'

module LDAP

def self.authenticate(user,password)
puts user
if user == "" || password == ""
return false
end
ldap_con = Net::LDAP.new({:host => '192.168.0.3',
:auth=>{:method=>:simple,:username => user,
:password => password } } )
return true if ldap_con.bind
return false
end
end
But when i send user name and password from rhtml page it's shows error
like
No connection to server
Please help me out.
Thanks
Varun
 
M

Matt Todd

Pluck out the actual LDAP code into IRB and see if it works. I've not
had experience passing Net::LDAP.new a hash, I've only ever assigned
values to its attributes after creating the instance, like:

ldap = Net::LDAP.net
ldap.host = 'http://localhost/
ldap.auth "%s@localhost" % user, pass
ldap.bind

Try that if your way fails in IRB.

Matt Todd
 
M

Mikel Lindsaar

Pluck out the actual LDAP code into IRB and see if it works. I've not
had experience passing Net::LDAP.new a hash, I've only ever assigned
values to its attributes after creating the instance, like:

It will definitely work with the hash assignment - I do it here with
ActiveDirectory

I think Varun is missing the port setting though.

Varun, do as Matt says, try it in IRB until you get it working, also,
pass the port parameter into the hash after the address. It can't
hurt.

Regards

Mikel

http://lindsaar.net/
 
F

Francis Cianfrocca

[Note: parts of this message were removed to make it a legal post.]

It will definitely work with the hash assignment - I do it here with
ActiveDirectory

I think Varun is missing the port setting though.

Varun, do as Matt says, try it in IRB until you get it working, also,
pass the port parameter into the hash after the address. It can't
hurt.

The port setting should default to 389 if you don't set it. In addition to
the IRB suggestions, Varun should also try to telnet from his machine to
192.168.0.3, port 389 to see if he has connectivity in the first place.
 
V

Varun Goel

Matt said:
Pluck out the actual LDAP code into IRB and see if it works. I've not
had experience passing Net::LDAP.new a hash, I've only ever assigned
values to its attributes after creating the instance, like:

ldap = Net::LDAP.net
ldap.host = 'http://localhost/
ldap.auth "%s@localhost" % user, pass
ldap.bind

Try that if your way fails in IRB.

Matt Todd

Hello Matt,
Thanks for ur reply but i used ur code into irb but it's not
showing any error instead of that it's showing false.
i create function like that.
require 'net/ldap'
def ldap_connect
ldap = Net::LDAP.new
ldap.host = 'ldap://ldapservername.com'
ldap.auth "%sldap://ldapservername.com"%'username','password'
ldap.bind
end
result::::False
Will you please suggest me that what is the error.Please Help me .
Thanks
Varun
 
V

Varun Goel

Hello Matt,
Thanks for ur reply but i used ur code into irb but it's not
showing any error instead of that it's showing false.
i create function like that.
require 'net/ldap'
def ldap_connect
ldap = Net::LDAP.new
ldap.host = 'ldapservername.com'
ldap.auth "%sldapservername.com"%'username','password'
ldap.bind
end
result::::False
Will you please suggest me that what is the error.Please Help me .
Thanks
Varun

Again if i made function like this
require 'net/ldap'
def ldap_connect
ldap = Net::LDAP.new
ldap.host = 'ldapservername.com'
ldap.bind
end
result:::True
Now i got reult true plese tell me how to use this within my application
please solve this problem
Thanks
Varun
 
M

Mikel Lindsaar

Again if i made function like this
require 'net/ldap'
def ldap_connect
ldap = Net::LDAP.new
ldap.host = 'ldapservername.com'
ldap.bind
end
result:::True
Now i got reult true plese tell me how to use this within my application
please solve this problem

Your "problem" is that your username and password are incorrect in the
LDAP server. You can bind without any authentication so the Ruby
Net::LDAP connection, go read up on LDAP, it is not a Ruby problem.

Regards

Mikel
 
V

Varun Goel

Mikel said:
Your "problem" is that your username and password are incorrect in the
LDAP server. You can bind without any authentication so the Ruby
Net::LDAP connection, go read up on LDAP, it is not a Ruby problem.

Regards

Mikel

i am using the correct username and password but it's showing false and
one more thing that now how can i send username and password to ldap
server for checking and how ldap server will send the format for
username and password .
Please solve my problem
looking for ur suggestion
Thanks
varun
 
M

Matt Todd

i am using the correct username and password but it's showing false and
one more thing that now how can i send username and password to ldap
server for checking and how ldap server will send the format for
username and password .
Please solve my problem
looking for ur suggestion

The correct format for the #auth call would be as follows:

ldap.auth "(e-mail address removed)", "password"

Not:

ldap.auth "%sldap://ldapservername.com"%'username', 'password'

Note that you lack an @ sign and you've put the ldap protocol in the
string. Instead, what's required is the format: (e-mail address removed)
with username being replaced with the correct username.

This is a shorthand way to write your username... alternatively you
can supply a full DN as long as you provide the correct password too.

Experiment with it. We cannot solve your problem, we can only help you
and possibly recognize where you've made mistakes or overlooked a
small details; it is up to you to solve your issue.

Matt Todd
 
V

Varun Goel

Hello Matt,
Sorry to have u disturb but i am new to LDAP server and RAILS
also please tell me steps to setup my login with ldap can u provide me
some sample code looking for u r suggestion.
It's good to see u r response.
Thanks
Varun
And i tried what u said but it's again showing false.
 
M

Matt Todd

Hello Matt,
Sorry to have u disturb but i am new to LDAP server and RAILS
also please tell me steps to setup my login with ldap can u provide me
some sample code looking for u r suggestion.
It's good to see u r response.
Thanks
Varun
And i tried what u said but it's again showing false.

You might need to check out your configuration of the LDAP server,
which, unfortunately, I have absolutely no experience with.

There should be plenty of examples around to clarify.

I'm not sure how much more assistance I can be for you. At the very
least, what's the exact error message you're receiving?

Matt Todd
 
V

Varun Goel

Hello Matt,
Actually i made one function like this.And this function returns me true.
Then what's mean of this function means my connection to ldap server has
been establish or not.
Please guide me and if connection is established then how can i
authenticate username and password through ldap server.
Can i do like this..
filter = Net::LDAP::Filter.eq('uid', username)
ldap.search:)filter => filter) {|entry| username = entry.dn}
Please guide me i am confused in this LDAP connection.
Looking for ur reply.
Thanks
Varun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top