simple_ldap_authenticator 1.0.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +3 -1
- data/README +10 -12
- data/lib/simple_ldap_authenticator.rb +37 -35
- metadata +89 -52
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 370835649201c04c545cb53d363385e36b1d34ae4f3a1f08dd91b7f889725866
|
4
|
+
data.tar.gz: 9d3118b82945916bd3043b22304777891943ad7ee450b4855b0bfe09e816af55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0fce93068f8fb5d2e38f304860c6a4e7334a7bb408d0d3a75e41f5ff218c72107062dec33de8fd3455317296b98f6580bac7cb8a1c72c9ada4e0b5cec4d96715
|
7
|
+
data.tar.gz: c5b333d7c4b0359867a3176c0edb49fa1911cf329ebf41676049fa9999eb51bc57e931680a86c91e40cdee60112d3d57cbe9bdfe506e898b4f4ac32160429d98
|
data/LICENSE
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2006-2022 Jeremy Evans
|
2
|
+
|
3
|
+
test/ldapserver.rb Copyright (c) 2006-2011 by Francis Cianfrocca and other contributors.
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README
CHANGED
@@ -4,19 +4,17 @@ SimpleLdapAuthenticator
|
|
4
4
|
Allows for simple authentication to an LDAP server with a minimum of
|
5
5
|
configuration. Requires either Ruby/LDAP or Net::LDAP.
|
6
6
|
|
7
|
-
Usage
|
7
|
+
Example Usage:
|
8
|
+
|
8
9
|
require 'simple_ldap_authenticator'
|
10
|
+
require 'logger'
|
11
|
+
|
9
12
|
SimpleLdapAuthenticator.servers = %w'dc1.domain.com dc2.domain.com'
|
10
13
|
SimpleLdapAuthenticator.use_ssl = true
|
11
|
-
SimpleLdapAuthenticator.login_format = '%s
|
12
|
-
SimpleLdapAuthenticator.logger =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
SimpleLdapAuthenticator.valid?(params[:username], \
|
17
|
-
params[:password])
|
18
|
-
session[:username] = params[:username]
|
19
|
-
end
|
20
|
-
end
|
14
|
+
SimpleLdapAuthenticator.login_format = '%s@domain.com'
|
15
|
+
SimpleLdapAuthenticator.logger = Logger.new($stdout)
|
16
|
+
|
17
|
+
SimpleLdapAuthenticator.valid?(username, password)
|
18
|
+
# => true or false (or raise if there is an issue connecting to the server)
|
21
19
|
|
22
|
-
github: http://github.com/jeremyevans/simple_ldap_authenticator
|
20
|
+
github: http://github.com/jeremyevans/simple_ldap_authenticator
|
@@ -14,34 +14,33 @@
|
|
14
14
|
# * servers = ['dc1.domain.com', 'dc2.domain.com'] # names/addresses of LDAP servers to use
|
15
15
|
# * use_ssl = true # for logging in via LDAPS
|
16
16
|
# * port = 3289 # instead of 389 for LDAP or 636 for LDAPS
|
17
|
-
# * logger =
|
17
|
+
# * logger = Logger.new($stdout) # for logging authentication successes/failures
|
18
18
|
#
|
19
|
-
# The class is used as a
|
19
|
+
# The class is used as a singleton, you are not supposed to create an
|
20
20
|
# instance of it. For example:
|
21
21
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# session[:username] = params[:username]
|
31
|
-
# end
|
32
|
-
# end
|
22
|
+
# require 'simple_ldap_authenticator'
|
23
|
+
#
|
24
|
+
# SimpleLdapAuthenticator.servers = %w'dc1.domain.com dc2.domain.com'
|
25
|
+
# SimpleLdapAuthenticator.use_ssl = true
|
26
|
+
# SimpleLdapAuthenticator.login_format = '%s@domain.com'
|
27
|
+
#
|
28
|
+
# SimpleLdapAuthenticator.valid?(username, password)
|
29
|
+
# # => true or false (or raise if there is an issue connecting to the server)
|
33
30
|
class SimpleLdapAuthenticator
|
31
|
+
@servers = ['127.0.0.1']
|
32
|
+
@use_ssl = false
|
33
|
+
@login_format = '%s'
|
34
|
+
|
34
35
|
class << self
|
35
|
-
|
36
|
-
|
37
|
-
@login_format = '%s'
|
38
|
-
attr_accessor :servers, :use_ssl, :port, :login_format, :logger, :connection, :ldap_library
|
36
|
+
attr_accessor :servers, :use_ssl, :login_format, :logger, :ldap_library
|
37
|
+
attr_writer :port, :connection
|
39
38
|
|
40
39
|
# Load the required LDAP library, either 'ldap' or 'net/ldap'
|
41
40
|
def load_ldap_library
|
42
41
|
return if @ldap_library_loaded
|
43
|
-
if ldap_library
|
44
|
-
if ldap_library == 'net/ldap'
|
42
|
+
if @ldap_library
|
43
|
+
if @ldap_library == 'net/ldap'
|
45
44
|
require 'net/ldap'
|
46
45
|
else
|
47
46
|
require 'ldap'
|
@@ -51,10 +50,10 @@ class SimpleLdapAuthenticator
|
|
51
50
|
begin
|
52
51
|
require 'ldap'
|
53
52
|
require 'ldap/control'
|
54
|
-
ldap_library = 'ldap'
|
53
|
+
@ldap_library = 'ldap'
|
55
54
|
rescue LoadError
|
56
55
|
require 'net/ldap'
|
57
|
-
ldap_library = 'net/ldap'
|
56
|
+
@ldap_library = 'net/ldap'
|
58
57
|
end
|
59
58
|
end
|
60
59
|
@ldap_library_loaded = true
|
@@ -92,34 +91,37 @@ class SimpleLdapAuthenticator
|
|
92
91
|
|
93
92
|
# Check the validity of a login/password combination
|
94
93
|
def valid?(login, password)
|
95
|
-
|
94
|
+
login = login.to_s
|
95
|
+
password = password.to_s
|
96
|
+
connection = self.connection
|
97
|
+
if password == '' || password.include?("\0") || login.include?("\0")
|
96
98
|
false
|
97
99
|
elsif ldap_library == 'net/ldap'
|
98
|
-
connection.authenticate(login_format % login
|
100
|
+
connection.authenticate(login_format % login, password)
|
99
101
|
begin
|
100
102
|
if connection.bind
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
rescue Net::LDAP::
|
109
|
-
logger.info("Error attempting to authenticate #{login
|
103
|
+
logger.info("Authenticated #{login} by #{server}") if logger
|
104
|
+
true
|
105
|
+
else
|
106
|
+
logger.info("Error attempting to authenticate #{login} by #{server}: #{connection.get_operation_result.code} #{connection.get_operation_result.message}") if logger
|
107
|
+
switch_server unless connection.get_operation_result.code == 49
|
108
|
+
false
|
109
|
+
end
|
110
|
+
rescue Net::LDAP::Error, SocketError, SystemCallError => error
|
111
|
+
logger.info("Error attempting to authenticate #{login} by #{server}: #{error.message}") if logger
|
110
112
|
switch_server
|
111
113
|
false
|
112
114
|
end
|
113
115
|
else
|
114
116
|
connection.unbind if connection.bound?
|
115
117
|
begin
|
116
|
-
connection.bind(login_format % login
|
118
|
+
connection.bind(login_format % login, password)
|
117
119
|
connection.unbind
|
118
|
-
logger.info("Authenticated #{login
|
120
|
+
logger.info("Authenticated #{login} by #{server}") if logger
|
119
121
|
true
|
120
122
|
rescue LDAP::ResultError => error
|
121
123
|
connection.unbind if connection.bound?
|
122
|
-
logger.info("Error attempting to authenticate #{login
|
124
|
+
logger.info("Error attempting to authenticate #{login} by #{server}: #{error.message}") if logger
|
123
125
|
switch_server unless error.message == 'Invalid credentials'
|
124
126
|
false
|
125
127
|
end
|
metadata
CHANGED
@@ -1,72 +1,109 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_ldap_authenticator
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 1.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Jeremy Evans
|
14
|
-
autorequire:
|
8
|
+
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
date: 2024-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest-global_expectations
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-ldap
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
23
70
|
email: code@jeremyevans.net
|
24
71
|
executables: []
|
25
|
-
|
26
72
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
73
|
+
extra_rdoc_files:
|
29
74
|
- LICENSE
|
30
|
-
files:
|
31
|
-
- README
|
75
|
+
files:
|
32
76
|
- LICENSE
|
77
|
+
- README
|
33
78
|
- lib/simple_ldap_authenticator.rb
|
34
|
-
|
35
|
-
homepage:
|
79
|
+
homepage:
|
36
80
|
licenses: []
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
81
|
+
metadata:
|
82
|
+
bug_tracker_uri: https://github.com/jeremyevans/simple_ldap_authenticator/issues
|
83
|
+
changelog_uri: https://github.com/jeremyevans/simple_ldap_authenticator/blob/master/CHANGELOG
|
84
|
+
mailing_list_uri: https://github.com/jeremyevans/simple_ldap_authenticator/discussions
|
85
|
+
source_code_uri: https://github.com/jeremyevans/simple_ldap_authenticator
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- "--inline-source"
|
89
|
+
- "--line-numbers"
|
42
90
|
- README
|
43
91
|
- lib
|
44
|
-
require_paths:
|
92
|
+
require_paths:
|
45
93
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
|
48
|
-
requirements:
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
49
96
|
- - ">="
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
version: "0"
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
58
101
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
64
104
|
requirements: []
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
signing_key:
|
69
|
-
specification_version: 3
|
105
|
+
rubygems_version: 3.5.16
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
70
108
|
summary: Easy authentication to an LDAP server(s)
|
71
109
|
test_files: []
|
72
|
-
|