rack-auth-ldap 0.2 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Nzk1NjVlMmE3MTg1NjE2NDllNTQyMmU4ZjM0ZTg1NzVlMWU0N2M1NA==
5
+ data.tar.gz: !binary |-
6
+ N2I2Y2YzY2JmOWMyNTBmMGUyOGQwMzFhZjJiN2E2NDI4MTcxNGQ2OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTFjZmMwNGY3MjM3ZjdlN2NlZDIxNDJhZWU0MzAxNDEzY2FkZjQ2MTllYTVj
10
+ OTNkZDFiMDFhMzMzYjM3M2Q2YzZhYzA3ZTU2YTg4MjE3YTM3NWIxYzgzNGQ0
11
+ ZDgzOWVmMmQ5MzE5MTI4ZmNkNzMwZjEzODM1MDIzOTE2MTY3ZTA=
12
+ data.tar.gz: !binary |-
13
+ M2VlNDg2ZTk1NDE1MzI3Y2RiNmFkN2M2N2ZkNTgyZmJlNmNmMGUxYWJmZWM0
14
+ NDMzYTc4ZDQzZWI1Mjk4MjNjMzI3Y2EwY2M1NzFkOTNhN2E1NmQ5YzBlMTJl
15
+ YTYyMDA2MmQ2MmVhOGVkOTczZGI2ZDQ1ZGEwZDliZThiYWEyNTQ=
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-auth-ldap (0.1)
5
+ rack
6
+ ruby-ldap
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ code_statistics (0.2.13)
12
+ diff-lcs (1.2.5)
13
+ json (1.8.1)
14
+ rack (1.5.2)
15
+ rdoc (4.1.1)
16
+ json (~> 1.4)
17
+ roodi (4.0.0)
18
+ ruby_parser (~> 3.2, >= 3.2.2)
19
+ rspec (2.14.1)
20
+ rspec-core (~> 2.14.0)
21
+ rspec-expectations (~> 2.14.0)
22
+ rspec-mocks (~> 2.14.0)
23
+ rspec-core (2.14.8)
24
+ rspec-expectations (2.14.5)
25
+ diff-lcs (>= 1.1.3, < 2.0)
26
+ rspec-mocks (2.14.6)
27
+ ruby-ldap (0.9.16)
28
+ ruby_parser (3.6.0)
29
+ sexp_processor (~> 4.1)
30
+ sexp_processor (4.4.3)
31
+ yard (0.8.7.4)
32
+ yard-rspec (0.1)
33
+ yard
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ code_statistics
40
+ rack-auth-ldap!
41
+ rdoc
42
+ roodi
43
+ rspec
44
+ yard
45
+ yard-rspec
data/README.rdoc CHANGED
@@ -5,3 +5,69 @@ Rack Middleware LDAP authentication
5
5
  == Copyright
6
6
 
7
7
  Copyright (c) 2014 Romain GEORGES. See COPYRIGHT for details.
8
+ Copyright (C) 2007, 2008, 2009, 2010 Christian Neukirchen <purl.org/net/chneukirchen> for Rack Project
9
+
10
+ == Presentation
11
+
12
+ Rack::Auth::Ldap is a basic authentication module with LDAP support
13
+ Rack::Auth::Ldap is heavily based on Rack:Auth::Basic from the Rack main Project by Christian Neukirchen
14
+
15
+ This is an additional module for Rack to authenticate users against an LDAP serveur
16
+
17
+
18
+ == Usage
19
+
20
+ === Initialise
21
+
22
+ In you config.ru, simply add :
23
+
24
+ require 'rubygems'
25
+ require 'rack'
26
+ gem 'rack-auth-ldap'
27
+ require 'rack/auth/ldap'
28
+
29
+
30
+ require File.dirname(__FILE__) + '/your_app'
31
+
32
+ use Rack::Auth::Ldap
33
+ run Sinatra::Application
34
+
35
+ this configuration activate the Basic Authencation for the entire application
36
+
37
+
38
+ === Configure
39
+
40
+ Create an ldap.yml configuration file with :
41
+
42
+ production: &ldap_defaults
43
+ hostname: localhost
44
+ basedn: ou=groups,dc=domain,dc=tld
45
+ rootdn: cn=admin,dc=domain,dc=tld
46
+ passdn: secret
47
+ auth: true
48
+ port: 389
49
+ username_ldap_attribut: uid
50
+
51
+
52
+ test:
53
+ <<: *ldap_defaults
54
+
55
+ development:
56
+ <<: *ldap_defaults
57
+
58
+
59
+ if you want to deactivate root authentication before user binding :
60
+
61
+ production: &ldap_defaults
62
+ hostname: localhost
63
+ basedn: ou=groups,dc=domain,dc=tld
64
+ auth: false
65
+ port: 389
66
+ username_ldap_attribut: uid
67
+
68
+
69
+ test:
70
+ <<: *ldap_defaults
71
+
72
+ development:
73
+ <<: *ldap_defaults
data/Rakefile CHANGED
@@ -32,8 +32,8 @@ YARD::Rake::YardocTask.new do |t|
32
32
  t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
33
33
  t.options += ['--title', "Gem Documentation"]
34
34
  t.options += ['-o', "yardoc"]
35
- t.options += ['-r', "doc/manual.rdoc"]
36
35
  end
36
+
37
37
  YARD::Config.load_plugin('yard-rspec')
38
38
 
39
39
  namespace :yardoc do
@@ -52,7 +52,6 @@ end
52
52
 
53
53
  Rake::RDocTask.new('rdoc') do |d|
54
54
  d.rdoc_files.include('doc/**/*','bin/*')
55
- d.main = 'doc/manual.rdoc'
56
55
  d.title = 'Dorsal : Yard'
57
56
  d.options << '--line-numbers' << '--diagram' << '-SHN'
58
57
  end
data/examples/config.ru CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rack'
3
3
  gem 'rack-auth-ldap'
4
4
  require 'rack/auth/ldap'
5
- require 'yaml'
5
+
6
6
 
7
7
  require File.dirname(__FILE__) + '/sinatra_example'
8
8
 
data/ldap.rb ADDED
File without changes
@@ -4,10 +4,22 @@ require 'rack/auth/abstract/handler'
4
4
  require 'rack/auth/abstract/request'
5
5
  require 'yaml'
6
6
 
7
+ # the rack module from Rack Sources
7
8
  module Rack
9
+
10
+ # the auth module from Rack Sources
8
11
  module Auth
9
12
 
10
- class Config
13
+
14
+ # class Config provide Yaml config mapping for Rack::Auth::Module
15
+ # the class map ldap configurations values
16
+ # @note this class is not provide to be used standalone
17
+ class Config
18
+
19
+ # initializer for Config class
20
+ # @param [Hash<Symbol>] options initialisation options
21
+ # @option options [Symbol] :file The YAML filename (default to ./ldap.yml, the config.ru path)
22
+ # @return [Config] object himself
11
23
  def initialize(options = { :file => './ldap.yml'})
12
24
  @values = defaults
13
25
  target = (ENV['RACK_ENV'])? ENV['RACK_ENV'] : 'test'
@@ -26,6 +38,8 @@ module Rack
26
38
  end
27
39
 
28
40
  private
41
+ # private method with default configuration values for LDAP
42
+ # @return [Hash<Symbol>] the default values of LDAP configuration
29
43
  def defaults
30
44
  return {
31
45
  :hostname => 'localhost',
@@ -42,17 +56,35 @@ module Rack
42
56
 
43
57
  end
44
58
 
45
-
59
+ # class Ldap, the main authentication component for Rack
60
+ # inherited from the default Rack::Auth::AbstractHandler
61
+ # @note please do not instantiate, this classe is reserved to Rack
62
+ # @example Usage
63
+ # # in a config.ru
64
+ # gem 'rack-auth-ldap'
65
+ # require 'rack/auth/ldap'
66
+ # use Rack::Auth::Ldap
46
67
  class Ldap < AbstractHandler
47
-
68
+
69
+ # the config read accessor
70
+ # @attr [Rack::Auth::Config] the read accessor to the LDAP Config object
48
71
  attr_reader :config
49
-
72
+
73
+ # initializer for the Ldap Class
74
+ # @note please don not instantiate without rack config.ru
75
+ # @see Rack::Auth::Ldap
76
+ # @return [Ldap] self object
77
+ # @param [Block,Proc,Lambda] app the rack application
78
+ # @param [hash<Symbol>] config_options the configurable options
79
+ # @option config_options [Symbol] :file the path to the YAML configuration file
50
80
  def initialize(app, config_options = {})
51
81
  super(app)
52
82
  @config = Config.new(config_options)
53
83
  end
54
84
 
55
-
85
+ # call wrapper to provide authentication if not
86
+ # @param [Hash] env the rack environnment variable
87
+ # @return [Array] the tri-dimensional Array [status,headers,[body]]
56
88
  def call(env)
57
89
  auth = Ldap::Request.new(env)
58
90
  return unauthorized unless auth.provided?
@@ -67,10 +99,15 @@ module Rack
67
99
 
68
100
  private
69
101
 
102
+ # forge a challange header for HTTP basic auth with the realm attribut
103
+ # @return [String] the header
70
104
  def challenge
71
105
  'Basic realm="%s"' % realm
72
106
  end
73
-
107
+
108
+ # do the LDAP connection => search => bind with the credentials get into request headers
109
+ # @param [Rack::Auth::Ldap::Request] auth a LDAP authenticator object
110
+ # @return [TrueClass,FalseClass] Boolean true/false
74
111
  def valid?(auth)
75
112
  dn = ''
76
113
  conn = LDAP::Conn.new(@config.hostname, @config.port)
@@ -92,6 +129,10 @@ module Rack
92
129
  end
93
130
 
94
131
  private
132
+
133
+ # helper to map ruby-ldap scope with internal scope symbols
134
+ # @param [Symbol] _scope a scope in [:subtree,:one]
135
+ # @return [Fixnum,Integer] the constant value form ruby-ldap
95
136
  def ldap_scope(_scope)
96
137
  res = {
97
138
  :subtree => ::LDAP::LDAP_SCOPE_SUBTREE,
@@ -102,20 +143,30 @@ module Rack
102
143
 
103
144
 
104
145
 
105
-
146
+ # Request class the LDAP credentials authenticator
147
+ # @note please do not instantiate manually, used by Rack::Auth:Ldap
106
148
  class Request < Auth::AbstractRequest
149
+
150
+ # return true if the auth scheme provide is really a basic scheme
151
+ # @return [FalseClass,TrueClass] the result
107
152
  def basic?
108
153
  !parts.first.nil? && "basic" == scheme
109
154
  end
110
155
 
156
+ # return an array of the two credentials [username,password]
157
+ # @return [Array] the couple [username,password]
111
158
  def credentials
112
159
  @credentials ||= params.unpack("m*").first.split(/:/, 2)
113
160
  end
114
-
161
+
162
+ # read accessor on the first credentials, username
163
+ # @return [String] the username
115
164
  def username
116
165
  credentials.first
117
166
  end
118
167
 
168
+ # read accessor on the last credentials, password
169
+ # @return [String] the password
119
170
  def password
120
171
  credentials.last
121
172
  end
@@ -2,10 +2,13 @@
2
2
  # -*- coding: utf-8 -*-
3
3
  # Author : Romain GEORGES
4
4
 
5
+ # the Rack module from Rack Sources
5
6
  module Rack
7
+
8
+ # the Rack::Auth module from Rack Sources
6
9
  module Auth
7
- module Ldap
8
- VERSION = "0.2"
9
- end
10
+ # the current version for Rack::Auth::Ldap => gem rack-auth-ldap
11
+ # used by gemspec
12
+ LDAP_VERSION = "1.0"
10
13
  end
11
14
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = "romain@ultragreen.net"
10
10
  s.homepage = "http://www.github.com/lecid/rack-auth-ldap"
11
11
  s.authors = ["Romain GEORGES"]
12
- s.version = Rack::Auth::Ldap::VERSION
12
+ s.version = Rack::Auth::LDAP_VERSION
13
13
  s.date = "2014-04-29"
14
14
  s.rubyforge_project = 'nowarning'
15
15
  s.description = %q{rack-auth-ldap : provide LDAP authentication for Rack middelware}
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-auth-ldap
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
5
- prerelease:
4
+ version: '1.0'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Romain GEORGES
@@ -14,7 +13,6 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: yard
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rdoc
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: roodi
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: code_statistics
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: yard-rspec
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: ruby-ldap
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ! '>='
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ! '>='
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rack
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ! '>='
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ! '>='
140
123
  - !ruby/object:Gem::Version
@@ -145,13 +128,16 @@ executables: []
145
128
  extensions: []
146
129
  extra_rdoc_files: []
147
130
  files:
131
+ - .gitignore
148
132
  - COPYRIGHT
149
133
  - Gemfile
134
+ - Gemfile.lock
150
135
  - README.rdoc
151
136
  - Rakefile
152
137
  - examples/config.ru
153
138
  - examples/ldap.yml
154
139
  - examples/sinatra_example.rb
140
+ - ldap.rb
155
141
  - lib/rack/auth/ldap.rb
156
142
  - lib/rack/auth/ldap/version.rb
157
143
  - rack-auth-ldap.gemspec
@@ -161,27 +147,26 @@ files:
161
147
  homepage: http://www.github.com/lecid/rack-auth-ldap
162
148
  licenses:
163
149
  - BSD
150
+ metadata: {}
164
151
  post_install_message:
165
152
  rdoc_options: []
166
153
  require_paths:
167
154
  - lib
168
155
  required_ruby_version: !ruby/object:Gem::Requirement
169
- none: false
170
156
  requirements:
171
157
  - - ! '>='
172
158
  - !ruby/object:Gem::Version
173
159
  version: 1.9.0
174
160
  required_rubygems_version: !ruby/object:Gem::Requirement
175
- none: false
176
161
  requirements:
177
162
  - - ! '>='
178
163
  - !ruby/object:Gem::Version
179
164
  version: '0'
180
165
  requirements: []
181
166
  rubyforge_project: nowarning
182
- rubygems_version: 1.8.29
167
+ rubygems_version: 2.2.2
183
168
  signing_key:
184
- specification_version: 3
169
+ specification_version: 4
185
170
  summary: Rack middleware providing LDAP authentication
186
171
  test_files: []
187
172
  has_rdoc: true