2017-04-19 10:09:54 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2018-04-26 08:55:53 +00:00
|
|
|
require_dependency 'ldap'
|
|
|
|
require_dependency 'ldap/user'
|
|
|
|
require_dependency 'ldap/group'
|
2017-04-19 10:09:54 +00:00
|
|
|
|
|
|
|
class Integration::LdapController < ApplicationController
|
2017-08-14 11:56:23 +00:00
|
|
|
include Integration::ImportJobBase
|
|
|
|
|
2020-03-19 09:39:51 +00:00
|
|
|
prepend_before_action { authentication_check && authorize! }
|
2017-04-19 10:09:54 +00:00
|
|
|
|
|
|
|
def discover
|
2018-01-08 15:27:23 +00:00
|
|
|
answer_with do
|
2019-06-27 18:26:28 +00:00
|
|
|
|
|
|
|
ldap = ::Ldap.new(params)
|
|
|
|
|
|
|
|
{
|
|
|
|
attributes: ldap.preferences
|
|
|
|
}
|
|
|
|
rescue => e
|
|
|
|
# workaround for issue #1114
|
|
|
|
raise if !e.message.end_with?(', 48, Inappropriate Authentication')
|
|
|
|
|
|
|
|
# return empty result
|
|
|
|
{}
|
|
|
|
|
2017-05-31 11:36:25 +00:00
|
|
|
end
|
2017-04-19 10:09:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def bind
|
2018-01-08 15:27:23 +00:00
|
|
|
answer_with do
|
|
|
|
# create single instance so
|
|
|
|
# User and Group don't have to
|
|
|
|
# open new connections
|
|
|
|
ldap = ::Ldap.new(params)
|
|
|
|
user = ::Ldap::User.new(params, ldap: ldap)
|
|
|
|
group = ::Ldap::Group.new(params, ldap: ldap)
|
|
|
|
|
|
|
|
{
|
|
|
|
# the order of these calls is relevant!
|
|
|
|
user_filter: user.filter,
|
|
|
|
user_attributes: user.attributes,
|
|
|
|
user_uid: user.uid_attribute,
|
|
|
|
|
|
|
|
# the order of these calls is relevant!
|
2018-12-19 17:31:51 +00:00
|
|
|
group_filter: group.filter,
|
|
|
|
groups: group.list,
|
|
|
|
group_uid: group.uid_attribute,
|
2018-01-08 15:27:23 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2017-04-19 10:09:54 +00:00
|
|
|
|
2018-01-08 15:27:23 +00:00
|
|
|
private
|
2017-04-19 10:09:54 +00:00
|
|
|
|
2018-01-08 15:27:23 +00:00
|
|
|
def payload_dry_run
|
|
|
|
{
|
|
|
|
ldap_config: super
|
2017-04-19 10:09:54 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|