Skip to content

Commit

Permalink
[API] Fix wierd ldap code.
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaSha authored and adrianschroeter committed Aug 22, 2013
1 parent 30a0db1 commit 4919368
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions src/api/app/models/user.rb
Expand Up @@ -242,7 +242,7 @@ def self.update_entry_ldap(login, newlogin, newemail, newpassword)
logger.debug( "Unable to connect to LDAP server" )
return "Unable to connect to LDAP server"
end
user_filter = "(#{LCONFIG['dap_search_attr']}=#{login})"
user_filter = "(#{CONFIG['ldap_search_attr']}=#{login})"
dn = String.new
ldap_con.search( CONFIG['ldap_search_base'], LDAP::LDAP_SCOPE_SUBTREE, user_filter ) do |entry|
dn = entry.dn
Expand Down Expand Up @@ -314,7 +314,7 @@ def self.new_entry_ldap(login, password, mail)
LDAP.mod(LDAP::LDAP_MOD_ADD,CONFIG['ldap_mail_attr'],[mail]),
]
# Added required sn attr
if defined?( CONFIG['ldap_sn_attr_required'] ) && CONFIG['ldap_sn_attr_required'] == :on
if CONFIG.has_key('ldap_sn_attr_required') && CONFIG['ldap_sn_attr_required'] == :on
entry << LDAP.mod(LDAP::LDAP_MOD_ADD,'sn',[login])
end

Expand All @@ -339,7 +339,7 @@ def self.delete_entry_ldap(login)
logger.debug( "Unable to connect to LDAP server" )
return "Unable to connect to LDAP server"
end
user_filter = "(#{LCONFIG['dap_search_attr']}=#{login})"
user_filter = "(#{CONFIG['ldap_search_attr']}=#{login})"
dn = String.new
ldap_con.search( CONFIG['ldap_search_base'], LDAP::LDAP_SCOPE_SUBTREE, user_filter ) do |entry|
dn = entry.dn
Expand All @@ -364,7 +364,7 @@ def self.ldapgroup_enabled?

# This static method tries to find a group with the given gorup_title to check whether the group is in the LDAP server.
def self.find_group_with_ldap(group)
if defined?( CONFIG['ldap_group_objectclass_attr'] )
if CONFIG.has_key?('ldap_group_objectclass_attr')
filter = "(&(#{CONFIG['ldap_group_title_attr']}=#{group})(objectclass=#{CONFIG['ldap_group_objectclass_attr']}))"
else
filter = "(#{CONFIG['ldap_group_title_attr']}=#{group})"
Expand Down Expand Up @@ -419,16 +419,16 @@ def self.render_grouplist_ldap(grouplist, user = nil)

if not user.nil?
# search user
if defined?( CONFIG['ldap_user_filter'] )
filter = "(&(#{LCONFIG['dap_search_attr']}=#{user})#{CONFIG['ldap_user_filter']})"
if CONFIG.has_key?('ldap_user_filter')
filter = "(&(#{CONFIG['ldap_search_attr']}=#{user})#{CONFIG['ldap_user_filter']})"
else
filter = "(#{LCONFIG['dap_search_attr']}=#{user})"
filter = "(#{CONFIG['ldap_search_attr']}=#{user})"
end
user_dn = String.new
user_memberof_attr = String.new
ldap_con.search( CONFIG['ldap_search_base'], LDAP::LDAP_SCOPE_SUBTREE, filter ) do |entry|
user_dn = entry.dn
if defined?( CONFIG['ldap_user_memberof_attr'] ) && entry.attrs.include?( CONFIG['ldap_user_memberof_attr'] )
if CONFIG.has_key?('ldap_user_memberof_attr') && entry.attrs.include?( CONFIG['ldap_user_memberof_attr'] )
user_memberof_attr=entry.vals(CONFIG['ldap_user_memberof_attr'])
end
end
Expand All @@ -454,7 +454,7 @@ def self.render_grouplist_ldap(grouplist, user = nil)
end

# search group
if defined?( CONFIG['ldap_group_objectclass_attr'] )
if CONFIG.has_key?('ldap_group_objectclass_attr')
filter = "(&(#{CONFIG['ldap_group_title_attr']}=#{group})(objectclass=#{CONFIG['ldap_group_objectclass_attr']}))"
else
filter = "(#{CONFIG['ldap_group_title_attr']}=#{group})"
Expand All @@ -466,7 +466,7 @@ def self.render_grouplist_ldap(grouplist, user = nil)
logger.debug( "Search group: #{filter}" )
ldap_con.search( CONFIG['ldap_group_search_base'], LDAP::LDAP_SCOPE_SUBTREE, filter ) do |entry|
group_dn = entry.dn
if defined?( CONFIG['ldap_group_member_attr'] ) && entry.attrs.include?(CONFIG['ldap_group_member_attr'])
if CONFIG.has_key?('ldap_group_member_attr') && entry.attrs.include?(CONFIG['ldap_group_member_attr'])
group_member_attr = entry.vals(CONFIG['ldap_group_member_attr'])
end
end
Expand Down Expand Up @@ -509,7 +509,7 @@ def self.change_password_ldap(login, password)
logger.debug( "Unable to connect to LDAP server" )
return "Unable to connect to LDAP server"
end
user_filter = "(#{LCONFIG['dap_search_attr']}=#{login})"
user_filter = "(#{CONFIG['ldap_search_attr']}=#{login})"
dn = String.new
ldap_con.search( CONFIG['ldap_search_base'], LDAP::LDAP_SCOPE_SUBTREE, user_filter ) do |entry|
dn = entry.dn
Expand Down Expand Up @@ -578,7 +578,7 @@ def self.find_with_ldap(login, password)
return nil
end

if defined?( CONFIG['ldap_user_filter'] )
if CONFIG.has_key?('ldap_user_filter')
user_filter = "(&(#{CONFIG['ldap_search_attr']}=#{login})#{CONFIG['ldap_user_filter']})"
else
user_filter = "(#{CONFIG['ldap_search_attr']}=#{login})"
Expand All @@ -588,7 +588,7 @@ def self.find_with_ldap(login, password)
ldap_con.search( CONFIG['ldap_search_base'], LDAP::LDAP_SCOPE_SUBTREE, user_filter ) do |entry|
dn = entry.dn
ldap_info[0] = String.new(entry[CONFIG['ldap_mail_attr']][0])
if defined?( CONFIG['ldap_authenticate'] ) && CONFIG['ldap_authenticate'] == :local
if CONFIG.has_key?('ldap_authenticate') && CONFIG['ldap_authenticate'] == :local
if entry[CONFIG['ldap_auth_attr']] then
ldap_password = entry[CONFIG['ldap_auth_attr']][0]
logger.debug( "Get auth_attr:#{ldap_password}" )
Expand Down Expand Up @@ -1358,7 +1358,7 @@ def self.initialize_ldap_con(user_name, password)
server = nil
count = 0

max_ldap_attempts = defined?( CONFIG['ldap_max_attempts'] ) ? CONFIG['ldap_max_attempts'] : 10
max_ldap_attempts = CONFIG.has_key?('ldap_max_attempts') ? CONFIG['ldap_max_attempts'] : 10

while !ping and count < max_ldap_attempts
count += 1
Expand All @@ -1374,20 +1374,20 @@ def self.initialize_ldap_con(user_name, password)

logger.debug( "Connecting to #{server} as '#{user_name}'" )
begin
if defined?( CONFIG['ldap_ssl'] ) && CONFIG['ldap_ssl'] == :on
port = defined?( CONFIG['ldap_port'] ) ? CONFIG['ldap_port'] : 636
if CONFIG.has_key?('ldap_ssl') && CONFIG['ldap_ssl'] == :on
port = CONFIG.has_key?('ldap_port') ? CONFIG['ldap_port'] : 636
conn = LDAP::SSLConn.new( server, port)
else
port = defined?( CONFIG['ldap_port'] ) ? CONFIG['ldap_port'] : 389
port = CONFIG.has_key?('ldap_port') ? CONFIG['ldap_port'] : 389
# Use LDAP StartTLS. By default start_tls is off.
if defined?( CONFIG['ldap_start_tls'] ) && CONFIG['ldap_start_tls'] == :on
if CONFIG.has_key?('ldap_start_tls') && CONFIG['ldap_start_tls'] == :on
conn = LDAP::SSLConn.new( server, port, true)
else
conn = LDAP::Conn.new( server, port)
end
end
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
if defined?( CONFIG['ldap_referrals'] ) && CONFIG['ldap_referrals'] == :off
if CONFIG.has_key?('ldap_referrals') && CONFIG['ldap_referrals'] == :off
conn.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_OFF)
end
conn.bind(user_name, password)
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/environments/production_test.rb
Expand Up @@ -28,7 +28,7 @@
# OVERRIDE with your company's ldap search base for the users who will use OBS
CONFIG['ldap_search_base'] = "OU=Organizational Unit,DC=Domain Component"
# Sam Account Name is the login name for LDAP
LCONFIG['dap_search_attr'] = "sAMAccountName"
CONFIG['ldap_search_attr'] = "sAMAccountName"
# Max number of times to attempt to contact the LDAP servers
CONFIG['max_ldap_attempts'] = 10

Expand Down

0 comments on commit 4919368

Please sign in to comment.