ldap_controller.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ldap = ::Ldap.new(params)
  10. render json: {
  11. result: 'ok',
  12. attributes: ldap.preferences,
  13. }
  14. rescue => e
  15. # workaround for issue #1114
  16. if e.message.end_with?(', 48, Inappropriate Authentication')
  17. result = {
  18. result: 'ok',
  19. attributes: {},
  20. }
  21. else
  22. logger.error e
  23. result = {
  24. result: 'failed',
  25. message: e.message,
  26. }
  27. end
  28. render json: result
  29. end
  30. def bind
  31. # create single instance so
  32. # User and Group don't have to
  33. # open new connections
  34. ldap = ::Ldap.new(params)
  35. user = ::Ldap::User.new(params, ldap: ldap)
  36. group = ::Ldap::Group.new(params, ldap: ldap)
  37. render json: {
  38. result: 'ok',
  39. # the order of these calls is relevant!
  40. user_filter: user.filter,
  41. user_attributes: user.attributes,
  42. user_uid: user.uid_attribute,
  43. # the order of these calls is relevant!
  44. group_filter: group.filter,
  45. groups: group.list,
  46. group_uid: group.uid_attribute,
  47. }
  48. rescue => e
  49. logger.error e
  50. render json: {
  51. result: 'failed',
  52. message: e.message,
  53. }
  54. end
  55. end