Project

General

Profile

Patch #3358 » 07_ldap_sync.patch

Jérémy Lal, 2009-07-14 16:29

View differences:

redmine-0.9.0.new/app/controllers/my_controller.rb 2009-07-14 15:18:01.514861128 +0200
59 59
      @user.pref.attributes = params[:pref]
60 60
      @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
61 61
      if @user.save
62
        if @user.auth_source and @user.auth_source.respond_to?('update')
63
          @user.auth_source.update(@user.login, @user.firstname, @user.lastname, @user.mail)
64
        end
62 65
        @user.pref.save
63 66
        @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
64 67
        set_language_if_valid @user.language
redmine-0.9.0.new/app/models/auth_source_ldap.rb 2009-07-14 15:18:01.514861128 +0200
80 80
  rescue  LDAP::Error => text
81 81
    raise "LDAP Auth Error: " + text
82 82
  end
83
  
84
  def update(login, firstname, lastname, mail)
85
    ldap_con = initialize_ldap_con(self.account, self.account_password)
86
    entry = [
87
      LDAP.mod(LDAP::LDAP_MOD_REPLACE, self.attr_firstname, [firstname]),
88
      LDAP.mod(LDAP::LDAP_MOD_REPLACE, self.attr_lastname, [lastname]),
89
      LDAP.mod(LDAP::LDAP_MOD_REPLACE, self.attr_mail, [mail])
90
    ]
91
    if self.filter.empty?
92
      filter = self.attr_login + "=" + encode(login)
93
    else
94
      filter = self.filter.gsub("$login", encode(login))
95
    end
96
    ldap_con.modify(filter + "," + self.base_dn, entry)
97
  rescue  LDAP::Error => text
98
    raise "LDAP Auth Error: " + text
99
  end
83 100

  
84 101
  # test the connection to the LDAP
85 102
  def test_connection
redmine-0.9.0.new/app/models/user.rb 2009-07-14 16:18:47.845859827 +0200
102 102
      return nil if !user.active?
103 103
      if user.auth_source
104 104
        # user has an external authentication method
105
        return nil unless user.auth_source.authenticate(login, password)
105
        attrs = user.auth_source.authenticate(login, password)
106
        return nil unless attrs
107
        # synchronise db with ldap
108
        user.update_attributes(attrs[0])
106 109
      else
107 110
        # authentication with local password
108 111
        return nil unless User.hash_password(password) == user.hashed_password        
(4-4/9)