从绑定连接中检索当前经过身份验证的LDAP用户的用户名

时间:2011-09-20 13:21:26

标签: ruby ldap

我正在使用ruby的net-ldap库。我正在编写一些接收连接对象的代码,成功的bind()操作已经完成,这意味着LDAP用户已经提供了用户名和密码并成功登录。

我现在想运行一些代码来检查用户是否属于特定的LDAP组。我实际上已经有了这个代码。但我想知道的是,如果LDAP中有可能找到使用当前连接进行身份验证的用户的DN或用户名。登录时已经需要用户名,但这种情况发生在我无法访问的其他代码中。以下是一些示例代码:

require 'rubygems'
require 'net-ldap'

connection_options = {
  :encryption => :simple_tls,
  :host => SERVER,
  :port => PORT,
  :base => BASE,
  :auth => {
    :username => "#{username}@#{DOMAIN}",
    :password => password,
    :method => :simple
  }
}
connection = Net::LDAP.new(connection_options)
if connection.bind
  puts "Authentication succeeded"
  # now find the username (again) given a valid connection object
end

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

有一个控件可用于发现称为授权标识请求控件的经过身份验证的标识。答案在响应中返回,称为授权标识响应控件。控件定义为here

答案 1 :(得分:0)

还有一个'我是谁'扩展手术。