12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- class MigrateLdapSamaccountnameToUidJob::Ldap
- attr_accessor :ldap, :ldap_config
- def initialize(ldap_config)
- @ldap_config = ldap_config
- @ldap = ::Ldap.new(ldap_config)
- end
- def perform
- log('Checking for active LDAP configuration...')
- if ldap_config.preferences.blank?
- log('Blank LDAP configuration. Exiting.')
- return
- end
- log('Checking for different LDAP uid attribute...')
- if uid_attribute_obsolete == uid_attribute_new
- log('Equal LDAP uid attributes. Exiting.')
- return
- end
- log('Starting to migrate LDAP config to new uid attribute...')
- migrate_ldap_config
- log('LDAP uid attribute migration completed.')
- end
- def uid_attribute_new
- @uid_attribute_new ||= begin
- config = {
- filter: ldap_config.preferences['user_filter']
- }
- ::Ldap::User.new(config, ldap: ldap).uid_attribute
- end
- end
- def uid_attribute_obsolete
- @uid_attribute_obsolete ||= ldap_config.preferences['user_uid']
- end
- def migrate_ldap_config
- ldap_config_new = ldap_config.preferences.merge(
- 'user_uid' => uid_attribute_new
- )
- ldap_config.update(preferences: ldap_config_new)
- end
- def log(message)
- Rails.logger.info "LDAP '#{ldap_config.name}' - #{message}"
- end
- end
|