ldap_controller.rb 1.3 KB

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