LDAP Server not connected error

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

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 “%[email protected]” % user, pass
ldap.bind

Try that if your way fails in IRB.

Matt T.

On Jan 18, 2008 2:50 AM, Matt T. [email protected] wrote:

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/

On Jan 17, 2008 11:38 AM, Mikel L. [email protected] wrote:

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.

Matt T. wrote:

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 “%[email protected]” % user, pass
ldap.bind

Try that if your way fails in IRB.

Matt T.

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

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

On Jan 18, 2008 8:50 PM, Varun G. [email protected] wrote:

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

Mikel L. wrote:

On Jan 18, 2008 8:50 PM, Varun G. [email protected] wrote:

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

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

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 “[email protected]”, “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: [email protected]
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 T.

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.

On Jan 18, 2008 7:05 AM, Varun G. [email protected] wrote:

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 T.

Hello Matt,
Actually i made one function like this.

require ‘net/ldap’
def ldap_connect
ldap = Net::LDAP.new
ldap.host = ‘ldapservername.com
ldap.bind
end
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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs