ldap_controller.rb 1.3 KB

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