simple_ldap_authenticator 1.1.0 → 1.3.0
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 +4 -4
- data/LICENSE +1 -1
- data/README +10 -12
- data/lib/simple_ldap_authenticator.rb +24 -21
- metadata +7 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3dbf224e93ab7c30ed11038747ecaec5dc263715cb9ab03172f6a1d605bac947
|
|
4
|
+
data.tar.gz: bb5b1c047030368ea994ea55b35aee888596d5976323780109437805776a4b34
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 177e31bda9a64aa956f2f67bd484674d238fcf16c0721892dbfd7ceaf7ae0a78902accf2378879c1a8568ea29404aa2593f64d8f43187549395e1d4a165bbc9a
|
|
7
|
+
data.tar.gz: 6d627bd78c11141794af994ba7ad9876e25e5666fbda3d3fe467bb15e722351a3b9af5b2d6b023d8ee02db59a58426ceed016a55d1607ec1dd39d0a9859db586
|
data/LICENSE
CHANGED
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,22 +14,19 @@
|
|
|
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
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
|
|
34
31
|
@servers = ['127.0.0.1']
|
|
35
32
|
@use_ssl = false
|
|
@@ -94,34 +91,40 @@ class SimpleLdapAuthenticator
|
|
|
94
91
|
|
|
95
92
|
# Check the validity of a login/password combination
|
|
96
93
|
def valid?(login, password)
|
|
97
|
-
|
|
94
|
+
login = login.to_s
|
|
95
|
+
password = password.to_s
|
|
96
|
+
connection = self.connection
|
|
97
|
+
if password == '' || password.include?("\0") || login.include?("\0")
|
|
98
98
|
false
|
|
99
99
|
elsif ldap_library == 'net/ldap'
|
|
100
|
-
connection.authenticate(login_format % login
|
|
100
|
+
connection.authenticate(login_format % login, password)
|
|
101
101
|
begin
|
|
102
102
|
if connection.bind
|
|
103
|
-
logger.info("Authenticated #{login
|
|
103
|
+
logger.info("Authenticated #{login} by #{server}") if logger
|
|
104
104
|
true
|
|
105
105
|
else
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
result = connection.get_operation_result
|
|
107
|
+
if logger
|
|
108
|
+
logger.info("Error attempting to authenticate #{login} by #{server}: #{result.code} #{result.message} #{result.error_message.to_s.strip}")
|
|
109
|
+
end
|
|
110
|
+
switch_server unless result.code == 49
|
|
108
111
|
false
|
|
109
112
|
end
|
|
110
113
|
rescue Net::LDAP::Error, SocketError, SystemCallError => error
|
|
111
|
-
logger.info("Error attempting to authenticate #{login
|
|
114
|
+
logger.info("Error attempting to authenticate #{login} by #{server}: #{error.message}") if logger
|
|
112
115
|
switch_server
|
|
113
116
|
false
|
|
114
117
|
end
|
|
115
118
|
else
|
|
116
119
|
connection.unbind if connection.bound?
|
|
117
120
|
begin
|
|
118
|
-
connection.bind(login_format % login
|
|
121
|
+
connection.bind(login_format % login, password)
|
|
119
122
|
connection.unbind
|
|
120
|
-
logger.info("Authenticated #{login
|
|
123
|
+
logger.info("Authenticated #{login} by #{server}") if logger
|
|
121
124
|
true
|
|
122
125
|
rescue LDAP::ResultError => error
|
|
123
126
|
connection.unbind if connection.bound?
|
|
124
|
-
logger.info("Error attempting to authenticate #{login
|
|
127
|
+
logger.info("Error attempting to authenticate #{login} by #{server}: #{error.message}") if logger
|
|
125
128
|
switch_server unless error.message == 'Invalid credentials'
|
|
126
129
|
false
|
|
127
130
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_ldap_authenticator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Evans
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: minitest-global_expectations
|
|
@@ -66,7 +65,6 @@ dependencies:
|
|
|
66
65
|
- - ">="
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '0'
|
|
69
|
-
description:
|
|
70
68
|
email: code@jeremyevans.net
|
|
71
69
|
executables: []
|
|
72
70
|
extensions: []
|
|
@@ -76,14 +74,14 @@ files:
|
|
|
76
74
|
- LICENSE
|
|
77
75
|
- README
|
|
78
76
|
- lib/simple_ldap_authenticator.rb
|
|
79
|
-
homepage:
|
|
80
|
-
licenses:
|
|
77
|
+
homepage: http://github.com/jeremyevans/simple_ldap_authenticator
|
|
78
|
+
licenses:
|
|
79
|
+
- MIT
|
|
81
80
|
metadata:
|
|
82
81
|
bug_tracker_uri: https://github.com/jeremyevans/simple_ldap_authenticator/issues
|
|
83
82
|
changelog_uri: https://github.com/jeremyevans/simple_ldap_authenticator/blob/master/CHANGELOG
|
|
84
83
|
mailing_list_uri: https://github.com/jeremyevans/simple_ldap_authenticator/discussions
|
|
85
84
|
source_code_uri: https://github.com/jeremyevans/simple_ldap_authenticator
|
|
86
|
-
post_install_message:
|
|
87
85
|
rdoc_options:
|
|
88
86
|
- "--inline-source"
|
|
89
87
|
- "--line-numbers"
|
|
@@ -95,15 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
95
93
|
requirements:
|
|
96
94
|
- - ">="
|
|
97
95
|
- !ruby/object:Gem::Version
|
|
98
|
-
version:
|
|
96
|
+
version: 1.9.2
|
|
99
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
98
|
requirements:
|
|
101
99
|
- - ">="
|
|
102
100
|
- !ruby/object:Gem::Version
|
|
103
101
|
version: '0'
|
|
104
102
|
requirements: []
|
|
105
|
-
rubygems_version:
|
|
106
|
-
signing_key:
|
|
103
|
+
rubygems_version: 4.0.20
|
|
107
104
|
specification_version: 4
|
|
108
105
|
summary: Easy authentication to an LDAP server(s)
|
|
109
106
|
test_files: []
|