2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2020-10-27 15:36:38 +00:00
|
|
|
class MigrateLdapSamaccountnameToUidJob < ApplicationJob
|
|
|
|
|
|
|
|
def perform
|
|
|
|
Rails.logger.info 'Checking for active LDAP configuration...'
|
|
|
|
|
|
|
|
if ldap_config.blank?
|
|
|
|
Rails.logger.info 'Blank LDAP configuration. Exiting.'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
Rails.logger.info 'Checking for different LDAP uid attribute...'
|
|
|
|
if uid_attribute_obsolete == uid_attribute_new
|
|
|
|
Rails.logger.info 'Equal LDAP uid attributes. Exiting.'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
Rails.logger.info 'Starting to migrate LDAP config to new uid attribute...'
|
|
|
|
migrate_ldap_config
|
|
|
|
Rails.logger.info 'LDAP uid attribute migration completed.'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ldap
|
|
|
|
@ldap ||= ::Ldap.new(ldap_config)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ldap_config
|
|
|
|
@ldap_config ||= Import::Ldap.config
|
|
|
|
end
|
|
|
|
|
|
|
|
def uid_attribute_new
|
|
|
|
@uid_attribute_new ||= begin
|
|
|
|
config = {
|
|
|
|
filter: ldap_config['user_filter']
|
|
|
|
}
|
|
|
|
|
|
|
|
::Ldap::User.new(config, ldap: ldap).uid_attribute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def uid_attribute_obsolete
|
|
|
|
@uid_attribute_obsolete ||= ldap_config['user_uid']
|
|
|
|
end
|
|
|
|
|
|
|
|
def migrate_ldap_config
|
|
|
|
ldap_config_new = ldap_config.merge(
|
|
|
|
'user_uid' => uid_attribute_new
|
|
|
|
)
|
|
|
|
|
|
|
|
Setting.set('ldap_config', ldap_config_new)
|
|
|
|
end
|
|
|
|
end
|