ldap_controller.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Integration::LdapController < ApplicationController
  3. include Integration::ImportJobBase
  4. prepend_before_action { authentication_check && authorize! }
  5. def discover
  6. answer_with do
  7. ldap = ::Ldap.new(params)
  8. {
  9. attributes: ldap.preferences
  10. }
  11. rescue => e
  12. # workaround for issue #1114
  13. raise if !e.message.end_with?(', 48, Inappropriate Authentication')
  14. # return empty result
  15. {}
  16. end
  17. end
  18. def bind
  19. answer_with do
  20. # create single instance so
  21. # User and Group don't have to
  22. # open new connections
  23. ldap = ::Ldap.new(params)
  24. user = ::Ldap::User.new(params, ldap: ldap)
  25. group = ::Ldap::Group.new(params, ldap: ldap)
  26. {
  27. # the order of these calls is relevant!
  28. user_filter: user.filter,
  29. user_attributes: user.attributes,
  30. user_uid: user.uid_attribute,
  31. # the order of these calls is relevant!
  32. group_filter: group.filter,
  33. groups: group.list,
  34. group_uid: group.uid_attribute,
  35. }
  36. end
  37. end
  38. private
  39. def payload_dry_run
  40. {
  41. ldap_config: super
  42. }
  43. end
  44. end