Feature #1113 » redmine_ldap_groups_import_0.9.0.patch
./app/models/auth_source_ldap.rb 2010-01-26 12:26:18.000000000 +0300 | ||
---|---|---|
21 | 21 |
class AuthSourceLdap < AuthSource |
22 | 22 |
validates_presence_of :host, :port, :attr_login |
23 | 23 |
validates_length_of :name, :host, :account_password, :maximum => 60, :allow_nil => true |
24 |
validates_length_of :account, :base_dn, :maximum => 255, :allow_nil => true |
|
24 |
validates_length_of :account, :base_dn, :group_base_dn, :maximum => 255, :allow_nil => true
|
|
25 | 25 |
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true |
26 | 26 |
validates_numericality_of :port, :only_integer => true |
27 | 27 |
|
... | ... | |
56 | 56 |
return nil unless ldap_con.bind |
57 | 57 |
# return user's attributes |
58 | 58 |
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? |
59 | ||
60 |
if self.group_base_dn != "" |
|
61 |
# Search for ldap groups that the user is in |
|
62 |
ldap_con.search( :base => self.group_base_dn, |
|
63 |
:filter => Net::LDAP::Filter.eq("uniqueMember", dn), |
|
64 |
:attributes => [ "cn" ]) do |entry| |
|
65 |
# look to see if the group exists |
|
66 |
# then add it if it doesn't |
|
67 |
|
|
68 |
@matchinggroups = Group.find(:all, :conditions => "lastname = '#{entry.cn}'") |
|
69 |
|
|
70 |
if @matchinggroups.length == 0 |
|
71 |
@group = Group.new(:lastname => "#{entry.cn}") |
|
72 | ||
73 |
unless @group.save |
|
74 |
logger.debug "group '#{entry.cn}' save didn't work" if logger && logger.debug? |
|
75 |
end |
|
76 |
end |
|
77 |
|
|
78 |
# look to see if the user is a member of the group |
|
79 |
# and add them if they are not |
|
80 |
|
|
81 |
@currentgroup = Group.find(:first, :conditions => "lastname = '#{entry.cn}'") |
|
82 |
@userdetails = User.find(:first, :conditions => "login = '#{login}'") |
|
83 | ||
84 |
if !@currentgroup.user_ids.include?(@userdetails.id) |
|
85 |
# add the user to the group |
|
86 | ||
87 |
@currentgroup.user_ids = @currentgroup.user_ids + [@userdetails.id] |
|
88 | ||
89 |
unless @currentgroup.save |
|
90 |
logger.debug "user NOT added to group" if logger && logger.debug? |
|
91 |
end |
|
92 |
end |
|
93 |
|
|
94 |
end |
|
95 |
end |
|
96 | ||
59 | 97 |
attrs |
60 | 98 |
rescue Net::LDAP::LdapError => text |
61 | 99 |
raise "LdapError: " + text |
./app/views/auth_sources/_form.rhtml 2010-01-26 11:32:27.000000000 +0300 | ||
---|---|---|
23 | 23 |
<p><label for="auth_source_base_dn"><%=l(:field_base_dn)%> <span class="required">*</span></label> |
24 | 24 |
<%= text_field 'auth_source', 'base_dn', :size => 60 %></p> |
25 | 25 | |
26 |
<p><label for="auth_source_group_base_dn"><%=l(:field_group_base_dn)%></label> |
|
27 |
<%= text_field 'auth_source', 'group_base_dn', :size => 60 %></p> |
|
28 | ||
26 | 29 |
<p><label for="auth_source_onthefly_register"><%=l(:field_onthefly)%></label> |
27 | 30 |
<%= check_box 'auth_source', 'onthefly_register' %></p> |
28 | 31 |
</div> |
./config/locales/en.yml 2010-01-26 12:28:29.000000000 +0300 | ||
---|---|---|
245 | 245 |
field_attr_firstname: Firstname attribute |
246 | 246 |
field_attr_lastname: Lastname attribute |
247 | 247 |
field_attr_mail: Email attribute |
248 |
field_group_base_dn: Base DN for groups |
|
248 | 249 |
field_onthefly: On-the-fly user creation |
249 | 250 |
field_start_date: Start |
250 | 251 |
field_done_ratio: % Done |
./db/migrate/20100125132612_add_group_base_dn_to_auth_sources.rb 2010-01-25 16:29:43.000000000 +0300 | ||
---|---|---|
1 |
class AddGroupBaseDnToAuthSources < ActiveRecord::Migration |
|
2 |
def self.up |
|
3 |
add_column :auth_sources, :group_base_dn, :string, :limit => 255 |
|
4 |
end |
|
5 | ||
6 |
def self.down |
|
7 |
remove_column :auth_sources, :group_base_dn |
|
8 |
end |
|
9 |
end |