ldap_lookup 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +102 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ldap_lookup.gemspec +27 -0
- data/ldaptest.rb +98 -0
- data/lib/helpers/configuration.rb +25 -0
- data/lib/ldap_lookup.rb +136 -0
- data/lib/ldap_lookup/version.rb +3 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b5b583715ad3b95d22f008c3daab7402cc11a348559c0447c7aec8d5bd4010bc
|
4
|
+
data.tar.gz: 595f735c9a167784f00c4d5b4d92dd097a51b0dbc9b7ae94399960b7d8979220
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 843e17377dd313b7c0eda8c030030bc65953cb3998d80a1a1ea8a75920f9967c119859f6b62793649d198c276aaf6d253e8c5c08f166ec8c17b8507552a1f59f
|
7
|
+
data.tar.gz: abff197d0a1631afbe7f03bf94b0c90b3cf5a8bff6f669a325f85a68aa57f422ca27249861610fc775a0c80b96bbb34cee23bf29aa748682b16ac2d1fcaa7895
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at rsmoke@umich.edu. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Rick Smoke
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# LdapLookup for Ruby
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ldap_lookup`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
### Description
|
6
|
+
This module is to be used for anonymous lookup of user attributes in the MCommunity service provide at the University of Michigan. It can be easily modifed to use other LDAP server configurations.
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
### Try it out
|
11
|
+
|
12
|
+
Requirements:
|
13
|
+
* Ruby at least 2.0.0
|
14
|
+
* Gem 'net-ldap' ~> '0.16.1'
|
15
|
+
> Install by running the following command at your command prompt_for_action
|
16
|
+
> *The Net::LDAP (aka net-ldap) gem before 0.16.0 for Ruby has a Missing SSL Certificate Validation.*
|
17
|
+
```bash
|
18
|
+
gem install net-ldap
|
19
|
+
```
|
20
|
+
|
21
|
+
To try the module out:
|
22
|
+
1. Clone the repo
|
23
|
+
2. Edit the configurations by opening ldaptest.rb and set the *CONFIGURATION BLOCK* to your environment.
|
24
|
+
```ruby
|
25
|
+
LdapLookup.configuration do |config|
|
26
|
+
config.host = < your host > # "ldap.umich.edu"
|
27
|
+
config.base = < your LDAP base > # "dc=umich,dc=edu"
|
28
|
+
config.dept_attribute = < your dept attribute > # "umichPostalAddressData"
|
29
|
+
config.group_attribute = < your group email attribute > # "umichGroupEmail"
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
3. run the ldaptest.rb script
|
34
|
+
```ruby
|
35
|
+
ruby ./ldaptest.rb
|
36
|
+
```
|
37
|
+
|
38
|
+
---
|
39
|
+
|
40
|
+
### Installation
|
41
|
+
|
42
|
+
Add this line to your application's Gemfile:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'ldap_lookup'
|
46
|
+
```
|
47
|
+
|
48
|
+
And then execute:
|
49
|
+
|
50
|
+
$ bundle
|
51
|
+
|
52
|
+
Or install it yourself as:
|
53
|
+
|
54
|
+
$ gem install ldap_lookup
|
55
|
+
|
56
|
+
In your application create a file config/initializers/ldap_lookup.rb
|
57
|
+
```ruby
|
58
|
+
LdapLookup.configuration do |config|
|
59
|
+
config.host = < your host > # "ldap.umich.edu"
|
60
|
+
config.port = < your port > # "954" port 389 is set by default
|
61
|
+
config.base = < your LDAP base > # "dc=umich,dc=edu"
|
62
|
+
config.dept_attribute = < your dept attribute > # "umichPostalAddressData"
|
63
|
+
config.group_attribute = < your group email attribute > # "umichGroupEmail"
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
---
|
68
|
+
|
69
|
+
### Methods available
|
70
|
+
|
71
|
+
get_simple_name: returns the Display Name
|
72
|
+
```
|
73
|
+
LdapLookup.get_simple_name(uniqname = nil)
|
74
|
+
```
|
75
|
+
get_dept: returns the users Department_name
|
76
|
+
```
|
77
|
+
LdapLookup.get_dept(uniqname = nil)
|
78
|
+
```
|
79
|
+
get_email: returns the users email address
|
80
|
+
```
|
81
|
+
LdapLookup.get_email(uniqname = nil)
|
82
|
+
```
|
83
|
+
is_member_of_group?: returns true/false if uniqname is a member of the specified group
|
84
|
+
```
|
85
|
+
LdapLookup.is_member_of_group?(uid = nil, group_name = nil)
|
86
|
+
```
|
87
|
+
get_email_distribution_list: Returns the list of emails that are associated to a group.
|
88
|
+
```
|
89
|
+
LdapLookup.get_email_distribution_list(group_name = nil)
|
90
|
+
```
|
91
|
+
|
92
|
+
### Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rsmoke/ldap_lookup. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
95
|
+
|
96
|
+
### License
|
97
|
+
|
98
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
99
|
+
|
100
|
+
### Code of Conduct
|
101
|
+
|
102
|
+
Everyone interacting in the LdapLookup project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ldap_lookup/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ldap_lookup"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/ldap_lookup.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ldap_lookup/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ldap_lookup"
|
8
|
+
spec.version = LdapLookup::VERSION
|
9
|
+
spec.authors = ["Rick Smoke"]
|
10
|
+
spec.email = ["rsmoke@umich.edu"]
|
11
|
+
|
12
|
+
spec.summary = %q{For anonymous lookup of user LDAP attributes.}
|
13
|
+
spec.description = %q{This module is to be used for anonymous lookup of attributes in the MCommunity service provide at the University of Michigan. It can be easily modifed to use other LDAP server configurations.}
|
14
|
+
spec.homepage = "https://github.com/rsmoke/ldap_lookup.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_dependency 'net-ldap', '~> 0.16.1'
|
27
|
+
end
|
data/ldaptest.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative 'lib/ldap_lookup'
|
4
|
+
|
5
|
+
class Ldaptest
|
6
|
+
|
7
|
+
include LdapLookup
|
8
|
+
|
9
|
+
############## CONFIGURATION BLOCK ###################
|
10
|
+
LdapLookup.configuration do |config|
|
11
|
+
config.host = "ldap.umich.edu"
|
12
|
+
config.base = "dc=umich,dc=edu"
|
13
|
+
config.dept_attribute = "umichPostalAddressData"
|
14
|
+
config.group_attribute = "umichGroupEmail"
|
15
|
+
end
|
16
|
+
#######################################################
|
17
|
+
|
18
|
+
def initialize(name=nil)
|
19
|
+
@uid = name
|
20
|
+
@group_uid = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def reset_uid
|
24
|
+
puts "Enter a valid UID"
|
25
|
+
@uid = gets.chomp.to_s
|
26
|
+
return "UID is now set to #{@uid}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset_group_uid
|
30
|
+
puts "Enter a valid group_name"
|
31
|
+
@group_uid = gets.chomp.to_s
|
32
|
+
return "group_name is now set to #{@group_uid}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def result_box(answer)
|
36
|
+
print "\e[2J\e[f"
|
37
|
+
2.times { puts " " }
|
38
|
+
puts "Your Results"
|
39
|
+
puts "======================================================"
|
40
|
+
puts " "
|
41
|
+
puts "#{answer}"
|
42
|
+
puts " "
|
43
|
+
puts "======================================================"
|
44
|
+
puts "current values:\n UID set to=> #{@uid}\n group_uid set to=> #{@group_uid}"
|
45
|
+
puts "------------------------------------------------------"
|
46
|
+
2.times { puts " " }
|
47
|
+
end
|
48
|
+
|
49
|
+
def timestamp
|
50
|
+
Time.now.asctime
|
51
|
+
end
|
52
|
+
|
53
|
+
def prompt_for_action
|
54
|
+
puts "What would you like to do?"
|
55
|
+
puts "================================="
|
56
|
+
puts "1: set new uid"
|
57
|
+
puts "2: set new group_uid"
|
58
|
+
puts "+++++++++++++++++++++++++"
|
59
|
+
puts "3: get users full name"
|
60
|
+
puts "4: get users department"
|
61
|
+
puts "5: get users email"
|
62
|
+
puts "+++++++++++++++++++++++++"
|
63
|
+
puts "6: get ldap group-name member listing"
|
64
|
+
puts "7: check if uid is member of a group"
|
65
|
+
puts "+++++++++++++++++++++++++"
|
66
|
+
puts "8: what time is it?"
|
67
|
+
puts "0: exit"
|
68
|
+
|
69
|
+
case gets.chomp.to_i
|
70
|
+
when 1 then result_box(reset_uid)
|
71
|
+
when 2 then result_box(reset_group_uid)
|
72
|
+
when 3 then result_box(LdapLookup.get_simple_name(@uid))
|
73
|
+
when 4 then result_box(LdapLookup.get_dept(@uid))
|
74
|
+
when 5 then result_box(LdapLookup.get_email(@uid))
|
75
|
+
when 6 then result_box(LdapLookup.get_email_distribution_list(@group_uid))
|
76
|
+
when 7 then result_box(LdapLookup.is_member_of_group?(@uid,@group_uid))
|
77
|
+
when 8 then result_box(timestamp)
|
78
|
+
when 0 then puts "you chose exit!"
|
79
|
+
throw(:done)
|
80
|
+
else
|
81
|
+
print "\e[2J\e[f"
|
82
|
+
puts "====> Please type 1,2,3,4,5,6,7,8 or 0 only"
|
83
|
+
2.times { puts " " }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def run
|
88
|
+
catch(:done) do
|
89
|
+
loop do
|
90
|
+
prompt_for_action
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
print "\e[2J\e[f"
|
96
|
+
print "Enter a valid UID=> "
|
97
|
+
name = gets.chomp.to_s
|
98
|
+
program1 = Ldaptest.new(name).run
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Configuration
|
2
|
+
def configuration
|
3
|
+
yield self
|
4
|
+
end
|
5
|
+
|
6
|
+
def define_setting(name, default = nil)
|
7
|
+
class_variable_set("@@#{name}", default)
|
8
|
+
|
9
|
+
define_class_method "#{name}=" do |value|
|
10
|
+
class_variable_set("@@#{name}", value)
|
11
|
+
end
|
12
|
+
|
13
|
+
define_class_method name do
|
14
|
+
class_variable_get("@@#{name}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def define_class_method(name, &block)
|
21
|
+
(class << self; self; end).instance_eval do
|
22
|
+
define_method name, &block
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/ldap_lookup.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require_relative 'helpers/configuration'
|
2
|
+
|
3
|
+
module LdapLookup
|
4
|
+
require 'net/ldap'
|
5
|
+
|
6
|
+
extend Configuration
|
7
|
+
|
8
|
+
define_setting :host
|
9
|
+
define_setting :port, "389"
|
10
|
+
define_setting :base
|
11
|
+
define_setting :dept_attribute
|
12
|
+
define_setting :group_attribute
|
13
|
+
|
14
|
+
# this was developed using guidence from this gist:
|
15
|
+
# https://gist.githubusercontent.com/jeffjohnson9046/7012167/raw/86587b9637ddc2ece7a42df774980fa9c0aac9b3/ruby-ldap-sample.rb
|
16
|
+
|
17
|
+
#######################################################################################################################
|
18
|
+
## HELPER/UTILITY METHOD
|
19
|
+
## This method interprets the response/return code from an LDAP bind operation (bind, search, add, modify, rename,
|
20
|
+
## delete). This method isn't necessarily complete, but it's a good starting point for handling the response codes
|
21
|
+
## from an LDAP bind operation.
|
22
|
+
##
|
23
|
+
## Additional details for the get_operation_result method can be found here:
|
24
|
+
## http://net-ldap.rubyforge.org/Net/LDAP.html#method-i-get_operation_result
|
25
|
+
########################################################################################################################
|
26
|
+
def self.get_ldap_response(ldap)
|
27
|
+
msg = "Response Code: #{ ldap.get_operation_result.code }, Message: #{ ldap.get_operation_result.message }"
|
28
|
+
raise msg unless ldap.get_operation_result.code == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
#######################################################################################################################
|
32
|
+
# SET UP LDAP CONNECTION
|
33
|
+
# Setting up a connection to the LDAP server using .new() does not actually send any network traffic to the LDAP
|
34
|
+
# server. When you call an operation on ldap (e.g. add or search), .bind is called implicitly. *That's* when the
|
35
|
+
# connection is made to the LDAP server. This means that each operation called on the ldap object will create its own
|
36
|
+
# network connection to the LDAP server.
|
37
|
+
#######################################################################################################################
|
38
|
+
def self.ldap_connection
|
39
|
+
ldap = Net::LDAP.new host: LdapLookup.host, # your LDAP host name or IP goes here,
|
40
|
+
port: LdapLookup.port, # your LDAP host port goes here,
|
41
|
+
base: LdapLookup.base, # the base of your AD tree goes here,
|
42
|
+
auth: {
|
43
|
+
:method => :anonymous
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# GET THE DISPLAY NAME FOR A SINGLE USER
|
48
|
+
def LdapLookup.get_simple_name(uniqname = nil)
|
49
|
+
ldap = ldap_connection
|
50
|
+
search_param = uniqname # the AD account goes here
|
51
|
+
result_attrs = ["displayName"] # Whatever you want to bring back in your result set goes here
|
52
|
+
# Build filter
|
53
|
+
search_filter = Net::LDAP::Filter.eq("uid", search_param)
|
54
|
+
# Execute search
|
55
|
+
ldap.search(filter: search_filter, attributes: result_attrs) { |item|
|
56
|
+
return item.displayName.first
|
57
|
+
}
|
58
|
+
get_ldap_response(ldap)
|
59
|
+
end
|
60
|
+
|
61
|
+
# GET THE PRIMARY DEPARTMENT FOR A SINGLE USER
|
62
|
+
def LdapLookup.get_dept(uniqname = nil)
|
63
|
+
ldap = ldap_connection
|
64
|
+
search_param = uniqname # the AD account goes here
|
65
|
+
result_attrs = [LdapLookup.dept_attribute] # Whatever you want to bring back in your result set goes here
|
66
|
+
# Build filter
|
67
|
+
search_filter = Net::LDAP::Filter.eq("uid", search_param)
|
68
|
+
# Execute search
|
69
|
+
ldap.search(filter: search_filter, attributes: result_attrs) { |item|
|
70
|
+
return dept_name = item.umichpostaladdressdata.first.split("}:{").first.split("=")[1] unless item.umichpostaladdressdata.first.nil?
|
71
|
+
}
|
72
|
+
get_ldap_response(ldap)
|
73
|
+
end
|
74
|
+
|
75
|
+
# GET THE E-MAIL ADDRESS FOR A SINGLE USER
|
76
|
+
def LdapLookup.get_email(uniqname = nil)
|
77
|
+
ldap = ldap_connection
|
78
|
+
search_param = uniqname # the AD account goes here
|
79
|
+
result_attrs = ["mail"] # Whatever you want to bring back in your result set goes here
|
80
|
+
# Build filter
|
81
|
+
search_filter = Net::LDAP::Filter.eq("uid", search_param)
|
82
|
+
# Execute search
|
83
|
+
ldap.search(filter: search_filter, attributes: result_attrs) { |item|
|
84
|
+
return item.mail.first
|
85
|
+
}
|
86
|
+
get_ldap_response(ldap)
|
87
|
+
end
|
88
|
+
|
89
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
90
|
+
# Check if the UID is a member of an LDAP group. This function returns TRUE
|
91
|
+
# if uid passed in is a member of group_name passed in. Otherwise it will
|
92
|
+
# return false.
|
93
|
+
def LdapLookup.is_member_of_group?(uid = nil, group_name = nil)
|
94
|
+
ldap = ldap_connection
|
95
|
+
# GET THE MEMBERS OF AN E-MAIL DISTRIBUTION LIST
|
96
|
+
search_param = group_name # the name of the distribution list you're looking for goes here
|
97
|
+
result_attrs = ["member"]
|
98
|
+
# Build filter
|
99
|
+
search_filter = Net::LDAP::Filter.eq("cn", search_param)
|
100
|
+
group_filter = Net::LDAP::Filter.eq("objectClass", "group")
|
101
|
+
composite_filter = Net::LDAP::Filter.join(search_filter, group_filter)
|
102
|
+
# Execute search, extracting the AD account name from each member of the distribution list
|
103
|
+
ldap.search(filter: composite_filter, attributes: result_attrs) do |item|
|
104
|
+
item.member.each do |entry|
|
105
|
+
if entry.split(",").first.split("=")[1] == uid
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
return FALSE
|
111
|
+
get_ldap_response(ldap)
|
112
|
+
end
|
113
|
+
|
114
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
115
|
+
# Get the Name email and members of an LDAP group as a hash
|
116
|
+
def LdapLookup.get_email_distribution_list(group_name = nil)
|
117
|
+
ldap = ldap_connection
|
118
|
+
result_hash = {}
|
119
|
+
member_hash = {}
|
120
|
+
# GET THE MEMBERS OF AN E-MAIL DISTRIBUTION LIST
|
121
|
+
search_param = group_name # the name of the distribution list you're looking for goes here
|
122
|
+
result_attrs = ["cn", LdapLookup.group_attribute, "member"]
|
123
|
+
# Build filter
|
124
|
+
search_filter = Net::LDAP::Filter.eq("cn", search_param)
|
125
|
+
group_filter = Net::LDAP::Filter.eq("objectClass", "group")
|
126
|
+
composite_filter = Net::LDAP::Filter.join(search_filter, group_filter)
|
127
|
+
# Execute search, extracting the AD account name from each member of the distribution list
|
128
|
+
ldap.search(filter: composite_filter, attributes: result_attrs) do |item|
|
129
|
+
result_hash["group_name"] = item.cn.first
|
130
|
+
result_hash["group_email"] = item.umichGroupEmail.first
|
131
|
+
result_hash["members"] = item.member
|
132
|
+
end
|
133
|
+
return result_hash
|
134
|
+
get_ldap_response(ldap)
|
135
|
+
end
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ldap_lookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rick Smoke
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-ldap
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.16.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.16.1
|
55
|
+
description: This module is to be used for anonymous lookup of attributes in the MCommunity
|
56
|
+
service provide at the University of Michigan. It can be easily modifed to use other
|
57
|
+
LDAP server configurations.
|
58
|
+
email:
|
59
|
+
- rsmoke@umich.edu
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- ldap_lookup.gemspec
|
73
|
+
- ldaptest.rb
|
74
|
+
- lib/helpers/configuration.rb
|
75
|
+
- lib/ldap_lookup.rb
|
76
|
+
- lib/ldap_lookup/version.rb
|
77
|
+
homepage: https://github.com/rsmoke/ldap_lookup.git
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.7.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: For anonymous lookup of user LDAP attributes.
|
101
|
+
test_files: []
|