rack-auth-krb 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/goliath/rack/auth/krb/basic_and_nego.rb +17 -6
- data/lib/rack/auth/krb/basic_and_nego.rb +23 -10
- data/rack-auth-krb.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -55,3 +55,16 @@ class DumpHeaders < Goliath::API
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
+
Enable authentication only for a subset of paths
|
59
|
+
============
|
60
|
+
You can specify a list of paths for the ones you only want the authentication process to be enabled.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
use Rack::Auth::Krb::BasicAndNego, 'my realm', 'my keytab', "http@hostname", ["/", "/oauth/authorize"]
|
64
|
+
```
|
65
|
+
|
66
|
+
or
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
use Goliath::Rack::Auth::Krb::BasicAndNego, 'my realm', 'my keytab', "http@hostname", ["/", "/oauth/authorize"]
|
70
|
+
```
|
@@ -8,21 +8,32 @@ module Goliath
|
|
8
8
|
module Krb
|
9
9
|
class BasicAndNego
|
10
10
|
include Goliath::Rack::AsyncMiddleware
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
# Initialize BasicAndNego configuration
|
13
|
+
# @param realm [String] Kerberos realm
|
14
|
+
# @param keytab [String] Kerberos keytab
|
15
|
+
# @param service [String] Kerberos service (may be nil)
|
16
|
+
# @param paths_only [String] Allows to request an authentication process only for specified paths
|
17
|
+
def initialize(app, realm, keytab, service=nil, paths_only=[])
|
13
18
|
@app = app
|
14
19
|
@realm = realm
|
15
20
|
@keytab = keytab
|
16
21
|
@service = service
|
22
|
+
@paths_only = paths_only
|
17
23
|
end
|
18
24
|
|
19
25
|
def call(env)
|
20
|
-
a =
|
21
|
-
a.process_request
|
26
|
+
a = nil
|
22
27
|
|
23
|
-
|
28
|
+
if @paths_only.empty? or @paths_only.include?(env["PATH_INFO"])
|
29
|
+
a = ::BasicAndNego::Processor.new(env, env.logger, @realm, @keytab, @service)
|
30
|
+
a.process_request
|
31
|
+
return a.response if a.response
|
32
|
+
end
|
33
|
+
|
34
|
+
new_headers = (a.nil?) ? {} : a.headers
|
24
35
|
|
25
|
-
super(env,
|
36
|
+
super(env, new_headers)
|
26
37
|
end
|
27
38
|
|
28
39
|
def post_process(env, status, headers, body, additional_headers)
|
@@ -5,27 +5,40 @@ module Rack
|
|
5
5
|
module Auth
|
6
6
|
module Krb
|
7
7
|
class BasicAndNego
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
# Initialize BasicAndNego configuration
|
10
|
+
# @param realm [String] Kerberos realm
|
11
|
+
# @param keytab [String] Kerberos keytab
|
12
|
+
# @param service [String] Kerberos service (may be nil)
|
13
|
+
# @param paths_only [String] Allows to request an authentication process only for specified paths
|
14
|
+
def initialize(app, realm, keytab, service=nil, paths_only=[])
|
10
15
|
@app = app
|
11
16
|
@realm = realm
|
12
17
|
@keytab = keytab
|
13
18
|
@service = service
|
19
|
+
@paths_only = paths_only
|
14
20
|
end
|
15
21
|
|
16
22
|
def call(env)
|
17
|
-
# Either user rack.logger if defined or create on
|
18
|
-
# logger defaulting to rack.errors
|
19
|
-
#
|
20
|
-
logger = env['rack.logger'] || ::Logger.new(env['rack.errors'])
|
21
|
-
a = ::BasicAndNego::Processor.new(env, logger, @realm, @keytab, @service)
|
22
|
-
a.process_request
|
23
23
|
|
24
|
-
|
24
|
+
a = nil
|
25
|
+
|
26
|
+
if @paths_only.empty? or @paths_only.include?(env["PATH_INFO"])
|
27
|
+
# Either user rack.logger if defined or create on
|
28
|
+
# logger defaulting to rack.errors
|
29
|
+
logger = env['rack.logger'] || ::Logger.new(env['rack.errors'])
|
30
|
+
a = ::BasicAndNego::Processor.new(env, logger, @realm, @keytab, @service)
|
31
|
+
a.process_request
|
32
|
+
return a.response if a.response
|
33
|
+
end
|
25
34
|
|
26
35
|
status, headers, body = @app.call(env)
|
27
36
|
|
28
|
-
|
37
|
+
if a
|
38
|
+
headers.merge!(a.headers)
|
39
|
+
end
|
40
|
+
|
41
|
+
[status, headers, body]
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
data/rack-auth-krb.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-auth-krb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|