rack-ntlm-test-service 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/README.markdown +28 -0
- data/Rakefile +3 -0
- data/lib/rack-ntlm.rb +1 -0
- data/lib/rack-ntlm/ntlm.rb +53 -0
- data/lib/rack-ntlm/version.rb +5 -0
- data/rack-ntlm.gemspec +24 -0
- data/test/rack_ntlm_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# rack-ntlm-test-service
|
2
|
+
|
3
|
+
Test that your HTTP client supports NTLM authentication.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Rack middleware: <pre>Rack::Ntlm</pre>
|
8
|
+
|
9
|
+
Arguments:
|
10
|
+
|
11
|
+
<pre>
|
12
|
+
{
|
13
|
+
:uri_pattern => /\/login/,
|
14
|
+
:auth => {
|
15
|
+
:username => 'user',
|
16
|
+
:password => 'secret'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
</pre>
|
20
|
+
|
21
|
+
|
22
|
+
# Credit to dtsato and lukefx for the original rack-ntlm gem on which this is based.
|
23
|
+
|
24
|
+
<h1>Temporary word of caution</h1>
|
25
|
+
|
26
|
+
<p>until my changes have been merged and pushed, you need to use the 'rubyntlm' gem from my github.</p>
|
27
|
+
|
28
|
+
<a href="https://github.com/johncant/rubyntlm">https://github.com/johncant/rubyntlm</a>
|
data/Rakefile
ADDED
data/lib/rack-ntlm.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack-ntlm/ntlm'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'net/ntlm'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Ntlm
|
5
|
+
|
6
|
+
def initialize(app, config = {})
|
7
|
+
@app = app
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def auth(username)
|
12
|
+
# Ignore the password. We should probably do something about this
|
13
|
+
begin
|
14
|
+
if @config[:auth]
|
15
|
+
username == @config[:auth][:username]
|
16
|
+
else
|
17
|
+
true
|
18
|
+
end
|
19
|
+
rescue => e
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
if env['PATH_INFO'] =~ @config[:uri_pattern] && (env['HTTP_AUTHORIZATION'].nil? || env['HTTP_AUTHORIZATION'] == "")
|
26
|
+
return [401, {'WWW-Authenticate' => "NTLM"}, []]
|
27
|
+
end
|
28
|
+
|
29
|
+
if /^(NTLM|Negotiate) (.+)/ =~ env["HTTP_AUTHORIZATION"]
|
30
|
+
|
31
|
+
message = Net::NTLM::Message.decode64($2)
|
32
|
+
|
33
|
+
if message.type == 1
|
34
|
+
type2 = Net::NTLM::Message::Type2.new
|
35
|
+
return [401, {"WWW-Authenticate" => "NTLM " + type2.encode64}, []]
|
36
|
+
end
|
37
|
+
|
38
|
+
if message.type == 3 && env['PATH_INFO'] =~ @config[:uri_pattern]
|
39
|
+
user = Net::NTLM::decode_utf16le(message.user)
|
40
|
+
if auth(user)
|
41
|
+
env['REMOTE_USER'] = user
|
42
|
+
else
|
43
|
+
return [401, {}, ["You are not authorized to see this page"]]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
@app.call(env)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/rack-ntlm.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack-ntlm/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack-ntlm-test-service"
|
7
|
+
s.version = Rack::Ntlm::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Luca Simone", "John Cant"]
|
10
|
+
s.email = ["info@lucasimone.info"]
|
11
|
+
s.homepage = "https://github.com/johncant/rack-ntlm-test-service"
|
12
|
+
s.summary = %q{Rack module for testing NTLM Authentication in an HTTP client}
|
13
|
+
s.description = %q{a Rack module for testing NTLM Authentication in an HTTP client}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "rubyntlm"
|
21
|
+
|
22
|
+
s.add_development_dependency "pry"
|
23
|
+
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-ntlm-test-service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luca Simone
|
9
|
+
- John Cant
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rubyntlm
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: pry
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: a Rack module for testing NTLM Authentication in an HTTP client
|
48
|
+
email:
|
49
|
+
- info@lucasimone.info
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- README.markdown
|
57
|
+
- Rakefile
|
58
|
+
- lib/rack-ntlm.rb
|
59
|
+
- lib/rack-ntlm/ntlm.rb
|
60
|
+
- lib/rack-ntlm/version.rb
|
61
|
+
- rack-ntlm.gemspec
|
62
|
+
- test/rack_ntlm_test.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
homepage: https://github.com/johncant/rack-ntlm-test-service
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Rack module for testing NTLM Authentication in an HTTP client
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|