Skip to content

Commit

Permalink
Initial commit:
Browse files Browse the repository at this point in the history
* Removing net/ntlm and adding as dependency
* Creating files to bundle it as a gem
* Using net/ldap to search for user on AD
  • Loading branch information
dtsato committed Mar 2, 2010
1 parent aee5b80 commit 05b080b
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 831 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
## MAC OS
.DS_Store

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## VIM
*.swp

## PROJECT::GENERAL
coverage
rdoc
pkg
36 changes: 0 additions & 36 deletions README

This file was deleted.

67 changes: 67 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
= Rack-ntlm

== Description

Rack middleware for transparent authentication with NTLM.

This is a fork from lukefx/rack-ntlm on Github. This makes the Rack middleware a gem and uses net/ldap to search the user against an ActiveDirectory server.

This is work in progress, so contributions are welcome.

== Known Limitations (TO-DOs):

* Due to the user-provided password not being available on the NTLM Type3 message, this middleware is only verifying the existence of the user on AD, and not binding as that user (which would require password)
* Failure on the NTLM authentication or LDAP search will simply return 401 with a response body saying "You are not authorized to see this page"

== Dependencies

* rubyntlm (gem install rubyntlm)
* net/ldap (gem install net-ldap)
== Usage (with Rails):

On your config/environment.rb:

config.gem 'rubyntlm', :lib => 'net/ntlm'
config.gem 'net-ldap', :lib => 'net/ldap'
config.gem 'rack-ntlm'

config.middleware.use "Rack::Ntlm", {
:uri_pattern => /\/login/ # (default = /\//) (any URL)
:host => '<Active Directory hostname>',
:port => 389, # default = 389
:base => 'Base namespace for LDAP search',
:search_filter => '(dn=%1)' # default = (sAMAccountName=%1)
:auth => {
:username => '<username to bind to LDAP>',
:password => '<password to bind to LDAP>'
}
}

Then run:

rake gems:install
rake gems:unpack (optional, if you want to vendor the gem)

== Example

When a client needs to authenticate itself to a proxy or server using the NTLM scheme then the following 4-way handshake takes place (only parts of the request and status line and the relevant headers are shown here; "C" is the client, "S" the server):

1: C --> S GET ...

2: C <-- S 401 Unauthorized
WWW-Authenticate: NTLM

3: C --> S GET ...
Authorization: NTLM <base64-encoded type-1-message>

4: C <-- S 401 Unauthorized
WWW-Authenticate: NTLM <base64-encoded type-2-message>

5: C --> S GET ...
Authorization: NTLM <base64-encoded type-3-message>

6: C <-- S 200 Ok

== Copyright

Copyright (c) 2009-2010 [Rack-Ntlm], released under the MIT license
28 changes: 27 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "rack-ntlm"
gem.summary = %Q{Rack middleware for transparent authentication with NTLM}
gem.description = %Q{Rack middleware for transparent authentication with NTLM. This is a fork from lukefx/rack-ntlm on Github. This makes the Rack middleware a gem and uses net/ldap to search the user against an ActiveDirectory server. This is work in progress, so contributions are welcome.}
gem.email = "dtsato@gmail.com"
gem.homepage = "http://github.com/dtsato/rack-ntlm"
gem.authors = ["Danilo Sato"]

gem.has_rdoc = true
gem.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
gem.extra_rdoc_files = ["README.rdoc"]

gem.test_files = Dir['test/**/*'] + Dir['test/*']

gem.add_dependency('rubyntlm', '>= 0.1.1')
gem.add_dependency('net-ldap', '>= 0.0.5')
end

Jeweler::GemcutterTasks.new

rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end

desc 'Default: run unit tests.'
task :default => :test

Expand All @@ -18,6 +44,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Rack-ntlm'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
Loading

0 comments on commit 05b080b

Please sign in to comment.