simple_ldap_authenticator 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README +10 -12
  3. data/lib/simple_ldap_authenticator.rb +20 -20
  4. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a0cd12219f55450a7360afd838042eeeb7c96914fa01e7f573246c8de9bec8c
4
- data.tar.gz: 38e42cc1bd4bc35bf8f5d7f71317d53bf0aa816041a5198aaaa8abe06bddc954
3
+ metadata.gz: 370835649201c04c545cb53d363385e36b1d34ae4f3a1f08dd91b7f889725866
4
+ data.tar.gz: 9d3118b82945916bd3043b22304777891943ad7ee450b4855b0bfe09e816af55
5
5
  SHA512:
6
- metadata.gz: fc4aa226b58a7d8889e3049ba134c194466951e4691a9a3be58c083460dec02295632a49cfe8bd274612d8fe684426d1b0c02f3eec6d2a312a2e26eca4cf1d4f
7
- data.tar.gz: 6d95e78ff27cce08a1f7cebd9c95499701efffcdae602243079763ed085936215255318586d4187d5e0f4e2c9e60a8dfed829436f1c6f9e8ff8d9243e150dd10
6
+ metadata.gz: 0fce93068f8fb5d2e38f304860c6a4e7334a7bb408d0d3a75e41f5ff218c72107062dec33de8fd3455317296b98f6580bac7cb8a1c72c9ada4e0b5cec4d96715
7
+ data.tar.gz: c5b333d7c4b0359867a3176c0edb49fa1911cf329ebf41676049fa9999eb51bc57e931680a86c91e40cdee60112d3d57cbe9bdfe506e898b4f4ac32160429d98
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 is fairly simple:
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 @domain.com'
12
- SimpleLdapAuthenticator.logger = RAILS_DEFAULT_LOGGER
13
- class LoginController < ApplicationController
14
- def login
15
- return redirect_to(:action=>'try_again') unless \
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/tree/master
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 = RAILS_DEFAULT_LOGGER # for logging authentication successes/failures
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
- # require 'simple_ldap_authenticator'
23
- # SimpleLdapAuthenticator.servers = %w'dc1.domain.com dc2.domain.com'
24
- # SimpleLdapAuthenticator.use_ssl = true
25
- # SimpleLdapAuthenticator.login_format = '%s@domain.com'
26
- # SimpleLdapAuthenticator.logger = RAILS_DEFAULT_LOGGER
27
- # class LoginController < ApplicationController
28
- # def login
29
- # return redirect_to(:action=>'try_again') unless SimpleLdapAuthenticator.valid?(params[:username], params[:password])
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,37 @@ class SimpleLdapAuthenticator
94
91
 
95
92
  # Check the validity of a login/password combination
96
93
  def valid?(login, password)
97
- if password.to_s == ''
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.to_s, password.to_s)
100
+ connection.authenticate(login_format % login, password)
101
101
  begin
102
102
  if connection.bind
103
- logger.info("Authenticated #{login.to_s} by #{server}") if logger
103
+ logger.info("Authenticated #{login} by #{server}") if logger
104
104
  true
105
105
  else
106
- logger.info("Error attempting to authenticate #{login.to_s} by #{server}: #{connection.get_operation_result.code} #{connection.get_operation_result.message}") if logger
106
+ logger.info("Error attempting to authenticate #{login} by #{server}: #{connection.get_operation_result.code} #{connection.get_operation_result.message}") if logger
107
107
  switch_server unless connection.get_operation_result.code == 49
108
108
  false
109
109
  end
110
110
  rescue Net::LDAP::Error, SocketError, SystemCallError => error
111
- logger.info("Error attempting to authenticate #{login.to_s} by #{server}: #{error.message}") if logger
111
+ logger.info("Error attempting to authenticate #{login} by #{server}: #{error.message}") if logger
112
112
  switch_server
113
113
  false
114
114
  end
115
115
  else
116
116
  connection.unbind if connection.bound?
117
117
  begin
118
- connection.bind(login_format % login.to_s, password.to_s)
118
+ connection.bind(login_format % login, password)
119
119
  connection.unbind
120
- logger.info("Authenticated #{login.to_s} by #{server}") if logger
120
+ logger.info("Authenticated #{login} by #{server}") if logger
121
121
  true
122
122
  rescue LDAP::ResultError => error
123
123
  connection.unbind if connection.bound?
124
- logger.info("Error attempting to authenticate #{login.to_s} by #{server}: #{error.message}") if logger
124
+ logger.info("Error attempting to authenticate #{login} by #{server}: #{error.message}") if logger
125
125
  switch_server unless error.message == 'Invalid credentials'
126
126
  false
127
127
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_ldap_authenticator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-19 00:00:00.000000000 Z
11
+ date: 2024-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-global_expectations
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description:
69
+ description:
70
70
  email: code@jeremyevans.net
71
71
  executables: []
72
72
  extensions: []
@@ -76,14 +76,14 @@ files:
76
76
  - LICENSE
77
77
  - README
78
78
  - lib/simple_ldap_authenticator.rb
79
- homepage:
79
+ homepage:
80
80
  licenses: []
81
81
  metadata:
82
82
  bug_tracker_uri: https://github.com/jeremyevans/simple_ldap_authenticator/issues
83
83
  changelog_uri: https://github.com/jeremyevans/simple_ldap_authenticator/blob/master/CHANGELOG
84
84
  mailing_list_uri: https://github.com/jeremyevans/simple_ldap_authenticator/discussions
85
85
  source_code_uri: https://github.com/jeremyevans/simple_ldap_authenticator
86
- post_install_message:
86
+ post_install_message:
87
87
  rdoc_options:
88
88
  - "--inline-source"
89
89
  - "--line-numbers"
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.3.7
106
- signing_key:
105
+ rubygems_version: 3.5.16
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: Easy authentication to an LDAP server(s)
109
109
  test_files: []