Ruby LDAP查询Novell eDirectory

时间:2016-06-29 16:47:28

标签: ruby ldap ldap-query novell

我想用Ruby连接到Novell eDirectory,但我在'open_connection'上有TimeOut。

您怎么看?

require 'net/ldap' 

    ldap = Net::LDAP.new :host => "172.21.45.60",
         :port => 686,
         :encrytion => :simple_tls,
         :auth => {
               :method => :simple,
               :username => "cn=XXX,ou=XXX,ou=XXX,o=XXX",
               :password => "XXX"
         }

    filter = Net::LDAP::Filter.eq("cn", "paul*")
    treebase = "ou=XXX,ou=XXX,o=XXX"
    attrs = ["mail", "cn", "sn", "objectclass", "loginTime"]

    ldap.search(:base => treebase, :filter => filter, :attributes => attrs) do |entry|
      puts "DN: #{entry.dn}"
      entry.each do |attribute, values|
        puts "   #{attribute}:"
        values.each do |value|
          puts "      --->#{value}"
        end
      end
    end

    p ldap.get_operation_result

错误

C:/Ruby23/lib/ruby/gems/2.3.0/gems/net-ldap-0.14.0/lib/net/ldap/connection.rb:63 :in `open_connection': Se produjo un error durante el intento de conexi¾n ya que la parte conectada no respondi¾ adecuadamente tras un periodo de tiempo, o bien se produjo un error en la conexi¾n establecida ya que el host conectado no ha p odido responder. - user specified timeout (Net::LDAP::Error)

1 个答案:

答案 0 :(得分:1)

您并未在端口686上与“172.21.45.60”建立联系。

我建议您在测试时尝试初始化为纯文本连接。

所以开始真的很简单:

require 'rubygems'
require 'net/ldap'

ldap = Net::LDAP.new :host => server_ip_address,
     :port => 389,
     :auth => {
           :method => :simple,
           :username => "cn=manager,dc=example,dc=com",
           :password => "opensesame"
     }

filter = Net::LDAP::Filter.eq( "cn", "George*" )
treebase = "dc=example,dc=com"

ldap.search( :base => treebase, :filter => filter ) do |entry|
  puts "DN: #{entry.dn}"
  entry.each do |attribute, values|
    puts "   #{attribute}:"
    values.each do |value|
      puts "      --->#{value}"
    end
  end
end

一旦有效,再添加TLS。

当我看到Ruby documentation(我不是Ruby Expert)时,会显示示例:

{
  :method => :start_tls,
  :tls_options => { :ca_file => "/etc/cafile.pem", :ssl_version => "TLSv1_1" }
}

-Jim