Created
August 5, 2020 02:55
-
-
Save HarlemSquirrel/a7895f3cb30d2ab837b9b1e9a2b7eb48 to your computer and use it in GitHub Desktop.
A demonstration of the DN and base issue detailed in activeldap/activeldap#185
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# A demonstration of the DN and base issue detailed in | |
# https://github.com/activeldap/activeldap/issues/185 | |
# Due to how requires are handled, we need to do some directory | |
# trickery to require our local copy of the source code. | |
base_dir = File.expand_path(File.dirname(__FILE__)) | |
top_dir = File.expand_path(File.join(base_dir, "..")) | |
lib_dir = File.join(top_dir, "lib") | |
$LOAD_PATH.unshift(File.join __dir__, 'lib') | |
require 'active_ldap' | |
class LdapGroup < ActiveLdap::Base | |
setup_connection host: 'localhost', | |
port: 1389, | |
base: 'dc=example,dc=org', | |
method: :plain, | |
bind_dn: 'cn=admin,dc=example,dc=org', | |
password: 'admin' | |
ldap_mapping dn_attribute: 'cn', | |
prefix: 'ou=groups', | |
classes: %w[groupOfNames], | |
scope: :sub | |
end | |
group1 = LdapGroup.new( | |
dn: 'cn=new_group1,ou=sub_ou,ou=groups,dc=example,dc=org', | |
cn: 'new_group1' | |
) | |
puts "\n\n-- Group 1 --", | |
"Base: #{group1.base}", | |
"\nLDIF", group1.to_ldif, | |
"\nBase: #{group1.base}" | |
group2 = LdapGroup.new( | |
cn: 'new_group2', | |
dn: 'cn=new_group2,ou=sub_ou,ou=groups,dc=example,dc=org' | |
) | |
puts "\n\n-- Group 2 --", | |
"Base: #{group2.base}", | |
"\nLDIF", | |
group2.to_ldif, | |
"\nBase: #{group2.base}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment