houston-devise_ldap_authenticatable 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/CHANGELOG.md +7 -0
  4. data/Gemfile +8 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +131 -0
  7. data/Rakefile +16 -0
  8. data/devise_ldap_authenticatable.gemspec +34 -0
  9. data/lib/devise_ldap_authenticatable.rb +50 -0
  10. data/lib/devise_ldap_authenticatable/exception.rb +6 -0
  11. data/lib/devise_ldap_authenticatable/ldap_adapter.rb +292 -0
  12. data/lib/devise_ldap_authenticatable/logger.rb +11 -0
  13. data/lib/devise_ldap_authenticatable/model.rb +95 -0
  14. data/lib/devise_ldap_authenticatable/routes.rb +8 -0
  15. data/lib/devise_ldap_authenticatable/schema.rb +14 -0
  16. data/lib/devise_ldap_authenticatable/strategy.rb +19 -0
  17. data/lib/devise_ldap_authenticatable/version.rb +3 -0
  18. data/lib/generators/devise_ldap_authenticatable/install_generator.rb +62 -0
  19. data/lib/generators/devise_ldap_authenticatable/templates/ldap.yml +51 -0
  20. data/spec/ldap/.gitignore +2 -0
  21. data/spec/ldap/base.ldif +73 -0
  22. data/spec/ldap/clear.ldif +26 -0
  23. data/spec/ldap/local.schema +6 -0
  24. data/spec/ldap/openldap-data/.gitignore +2 -0
  25. data/spec/ldap/openldap-data/run/.gitignore +2 -0
  26. data/spec/ldap/openldap-data/run/.gitkeep +0 -0
  27. data/spec/ldap/run-server +31 -0
  28. data/spec/ldap/server.pem +38 -0
  29. data/spec/ldap/slapd-test.conf.erb +107 -0
  30. data/spec/rails_app/Rakefile +7 -0
  31. data/spec/rails_app/app/controllers/application_controller.rb +7 -0
  32. data/spec/rails_app/app/controllers/posts_controller.rb +15 -0
  33. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  34. data/spec/rails_app/app/helpers/posts_helper.rb +2 -0
  35. data/spec/rails_app/app/models/post.rb +2 -0
  36. data/spec/rails_app/app/models/user.rb +10 -0
  37. data/spec/rails_app/app/views/layouts/application.html.erb +26 -0
  38. data/spec/rails_app/app/views/posts/index.html.erb +2 -0
  39. data/spec/rails_app/config.ru +4 -0
  40. data/spec/rails_app/config/application.rb +46 -0
  41. data/spec/rails_app/config/boot.rb +13 -0
  42. data/spec/rails_app/config/cucumber.yml +8 -0
  43. data/spec/rails_app/config/database.yml +25 -0
  44. data/spec/rails_app/config/environment.rb +5 -0
  45. data/spec/rails_app/config/environments/development.rb +21 -0
  46. data/spec/rails_app/config/environments/production.rb +46 -0
  47. data/spec/rails_app/config/environments/test.rb +34 -0
  48. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  49. data/spec/rails_app/config/initializers/devise.rb +242 -0
  50. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  51. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  52. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  53. data/spec/rails_app/config/initializers/session_store.rb +8 -0
  54. data/spec/rails_app/config/ldap.yml +22 -0
  55. data/spec/rails_app/config/ldap_with_boolean_ssl.yml +22 -0
  56. data/spec/rails_app/config/ldap_with_erb.yml +23 -0
  57. data/spec/rails_app/config/ldap_with_uid.yml +18 -0
  58. data/spec/rails_app/config/locales/devise.en.yml +58 -0
  59. data/spec/rails_app/config/locales/en.yml +5 -0
  60. data/spec/rails_app/config/routes.rb +64 -0
  61. data/spec/rails_app/config/ssl_ldap.yml +21 -0
  62. data/spec/rails_app/config/ssl_ldap_with_erb.yml +23 -0
  63. data/spec/rails_app/config/ssl_ldap_with_uid.yml +18 -0
  64. data/spec/rails_app/db/migrate/20100708120448_devise_create_users.rb +40 -0
  65. data/spec/rails_app/db/schema.rb +35 -0
  66. data/spec/rails_app/features/manage_logins.feature +35 -0
  67. data/spec/rails_app/features/step_definitions/login_steps.rb +21 -0
  68. data/spec/rails_app/features/step_definitions/web_steps.rb +219 -0
  69. data/spec/rails_app/features/support/env.rb +58 -0
  70. data/spec/rails_app/features/support/paths.rb +38 -0
  71. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  72. data/spec/rails_app/lib/tasks/cucumber.rake +53 -0
  73. data/spec/rails_app/public/404.html +26 -0
  74. data/spec/rails_app/public/422.html +26 -0
  75. data/spec/rails_app/public/500.html +26 -0
  76. data/spec/rails_app/public/images/rails.png +0 -0
  77. data/spec/rails_app/public/javascripts/application.js +2 -0
  78. data/spec/rails_app/public/javascripts/controls.js +965 -0
  79. data/spec/rails_app/public/javascripts/dragdrop.js +974 -0
  80. data/spec/rails_app/public/javascripts/effects.js +1123 -0
  81. data/spec/rails_app/public/javascripts/prototype.js +4874 -0
  82. data/spec/rails_app/public/javascripts/rails.js +118 -0
  83. data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
  84. data/spec/rails_app/script/cucumber +10 -0
  85. data/spec/rails_app/script/rails +6 -0
  86. data/spec/spec_helper.rb +47 -0
  87. data/spec/support/factories.rb +16 -0
  88. data/spec/unit/user_spec.rb +298 -0
  89. metadata +411 -0
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Rails.application.config.secret_token = '91f200017212d5529ed7dea1959a9bb36b937bdbddab9180114119a36dd9283c7f8c8d22cd299ce6c6f40e6b8121972953658ef357991b4716b7749a9b215402'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, :key => '_rails_app_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rake db:sessions:create")
8
+ # Rails.application.config.session_store :active_record_store
@@ -0,0 +1,22 @@
1
+ authorizations: &AUTHORIZATIONS
2
+ ## Authorization
3
+ group_base: ou=groups,dc=test,dc=com
4
+ required_groups:
5
+ - cn=admins,ou=groups,dc=test,dc=com
6
+ - ["authorizationRole", "cn=users,ou=groups,dc=test,dc=com"]
7
+ require_attribute:
8
+ objectClass: inetOrgPerson
9
+ authorizationRole: blogAdmin
10
+
11
+ test: &TEST
12
+ host: localhost
13
+ port: 3389
14
+ attribute: cn
15
+ base: ou=people,dc=test,dc=com
16
+ admin_user: cn=admin,dc=test,dc=com
17
+ admin_password: secret
18
+ ssl: false
19
+ <<: *AUTHORIZATIONS
20
+
21
+ development:
22
+ <<: *TEST
@@ -0,0 +1,22 @@
1
+ authorizations: &AUTHORIZATIONS
2
+ ## Authorization
3
+ group_base: ou=groups,dc=test,dc=com
4
+ required_groups:
5
+ - cn=admins,ou=groups,dc=test,dc=com
6
+ - ["authorizationRole", "cn=users,ou=groups,dc=test,dc=com"]
7
+ require_attribute:
8
+ objectClass: inetOrgPerson
9
+ authorizationRole: blogAdmin
10
+
11
+ test: &TEST
12
+ host: localhost
13
+ port: 3389
14
+ attribute: cn
15
+ base: ou=people,dc=test,dc=com
16
+ admin_user: cn=admin,dc=test,dc=com
17
+ admin_password: secret
18
+ ssl: true
19
+ <<: *AUTHORIZATIONS
20
+
21
+ development:
22
+ <<: *TEST
@@ -0,0 +1,23 @@
1
+ <% @base = "dc=test,dc=com" %>
2
+
3
+ authorizations: &AUTHORIZATIONS
4
+ ## Authorization
5
+ group_base: <%= "ou=groups,#{@base}" %>
6
+ required_groups:
7
+ - cn=admins,<%= "ou=groups,#{@base}" %>
8
+ require_attribute:
9
+ objectClass: inetOrgPerson
10
+ authorizationRole: blogAdmin
11
+
12
+ test: &TEST
13
+ host: <%= "localhost" %>
14
+ port: 3389
15
+ attribute: cn
16
+ base: <%= "ou=people,#{@base}" %>
17
+ admin_user: <%= "cn=admin,#{@base}" %>
18
+ admin_password: secret
19
+ ssl: false
20
+ <<: *AUTHORIZATIONS
21
+
22
+ development:
23
+ <<: *TEST
@@ -0,0 +1,18 @@
1
+ authorizations: &AUTHORIZATIONS
2
+ ## Authorization
3
+ group_base: ou=groups,dc=test,dc=com
4
+ required_groups:
5
+ - cn=admins,ou=groups,dc=test,dc=com
6
+ require_attribute:
7
+ objectClass: inetOrgPerson
8
+ authorizationRole: blogAdmin
9
+
10
+ test:
11
+ host: localhost
12
+ port: 3389
13
+ attribute: uid
14
+ base: ou=people,dc=test,dc=com
15
+ admin_user: cn=admin,dc=test,dc=com
16
+ admin_password: secret
17
+ ssl: false
18
+ <<: *AUTHORIZATIONS
@@ -0,0 +1,58 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
32
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
33
+ confirmations:
34
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
36
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
37
+ registrations:
38
+ signed_up: 'Welcome! You have signed up successfully.'
39
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
40
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
41
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
42
+ updated: 'You updated your account successfully.'
43
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
44
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
45
+ unlocks:
46
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
47
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
48
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
49
+ omniauth_callbacks:
50
+ success: 'Successfully authenticated from %{kind} account.'
51
+ failure: 'Could not authenticate you from %{kind} because "%{reason}".'
52
+ mailer:
53
+ confirmation_instructions:
54
+ subject: 'Confirmation instructions'
55
+ reset_password_instructions:
56
+ subject: 'Reset password instructions'
57
+ unlock_instructions:
58
+ subject: 'Unlock Instructions'
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,64 @@
1
+ RailsApp::Application.routes.draw do
2
+ devise_for :users
3
+
4
+ resources :posts
5
+
6
+ root :to => "posts#index"
7
+
8
+ # The priority is based upon order of creation:
9
+ # first created -> highest priority.
10
+
11
+ # Sample of regular route:
12
+ # match 'products/:id' => 'catalog#view'
13
+ # Keep in mind you can assign values other than :controller and :action
14
+
15
+ # Sample of named route:
16
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
17
+ # This route can be invoked with purchase_url(:id => product.id)
18
+
19
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
20
+ # resources :products
21
+
22
+ # Sample resource route with options:
23
+ # resources :products do
24
+ # member do
25
+ # get :short
26
+ # post :toggle
27
+ # end
28
+ #
29
+ # collection do
30
+ # get :sold
31
+ # end
32
+ # end
33
+
34
+ # Sample resource route with sub-resources:
35
+ # resources :products do
36
+ # resources :comments, :sales
37
+ # resource :seller
38
+ # end
39
+
40
+ # Sample resource route with more complex sub-resources
41
+ # resources :products do
42
+ # resources :comments
43
+ # resources :sales do
44
+ # get :recent, :on => :collection
45
+ # end
46
+ # end
47
+
48
+ # Sample resource route within a namespace:
49
+ # namespace :admin do
50
+ # # Directs /admin/products/* to Admin::ProductsController
51
+ # # (app/controllers/admin/products_controller.rb)
52
+ # resources :products
53
+ # end
54
+
55
+ # You can have the root of your site routed with "root"
56
+ # just remember to delete public/index.html.
57
+ # root :to => "welcome#index"
58
+
59
+ # See how all your routes lay out with "rake routes"
60
+
61
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
62
+ # Note: This route will make all actions in every controller accessible via GET requests.
63
+ # match ':controller(/:action(/:id(.:format)))'
64
+ end
@@ -0,0 +1,21 @@
1
+ authorizations: &AUTHORIZATIONS
2
+ ## Authorization
3
+ group_base: ou=groups,dc=test,dc=com
4
+ required_groups:
5
+ - cn=admins,ou=groups,dc=test,dc=com
6
+ require_attribute:
7
+ objectClass: inetOrgPerson
8
+ authorizationRole: blogAdmin
9
+
10
+ test: &TEST
11
+ host: localhost
12
+ port: 3389
13
+ attribute: cn
14
+ base: ou=people,dc=test,dc=com
15
+ admin_user: cn=admin,dc=test,dc=com
16
+ admin_password: secret
17
+ ssl: true
18
+ <<: *AUTHORIZATIONS
19
+
20
+ development:
21
+ <<: *TEST
@@ -0,0 +1,23 @@
1
+ <% @base = "dc=test,dc=com" %>
2
+
3
+ authorizations: &AUTHORIZATIONS
4
+ ## Authorization
5
+ group_base: <%= "ou=groups,#{@base}" %>
6
+ required_groups:
7
+ - cn=admins,<%= "ou=groups,#{@base}" %>
8
+ require_attribute:
9
+ objectClass: inetOrgPerson
10
+ authorizationRole: blogAdmin
11
+
12
+ test: &TEST
13
+ host: <%= "localhost" %>
14
+ port: 3389
15
+ attribute: cn
16
+ base: <%= "ou=people,#{@base}" %>
17
+ admin_user: <%= "cn=admin,#{@base}" %>
18
+ admin_password: secret
19
+ ssl: true
20
+ <<: *AUTHORIZATIONS
21
+
22
+ development:
23
+ <<: *TEST
@@ -0,0 +1,18 @@
1
+ authorizations: &AUTHORIZATIONS
2
+ ## Authorization
3
+ group_base: ou=groups,dc=test,dc=com
4
+ required_groups:
5
+ - cn=admins,ou=groups,dc=test,dc=com
6
+ require_attribute:
7
+ objectClass: inetOrgPerson
8
+ authorizationRole: blogAdmin
9
+
10
+ test:
11
+ host: localhost
12
+ port: 3389
13
+ attribute: uid
14
+ base: ou=people,dc=test,dc=com
15
+ admin_user: cn=admin,dc=test,dc=com
16
+ admin_password: secret
17
+ ssl: true
18
+ <<: *AUTHORIZATIONS
@@ -0,0 +1,40 @@
1
+ class DeviseCreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ t.string :uid
23
+
24
+ # t.confirmable
25
+ # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
26
+ # t.token_authenticatable
27
+
28
+ t.timestamps
29
+ end
30
+
31
+ add_index :users, :email, :unique => true
32
+ add_index :users, :reset_password_token, :unique => true
33
+ # add_index :users, :confirmation_token, :unique => true
34
+ # add_index :users, :unlock_token, :unique => true
35
+ end
36
+
37
+ def self.down
38
+ drop_table :users
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20100708120448) do
15
+
16
+ create_table "users", :force => true do |t|
17
+ t.string "email", :default => "", :null => false
18
+ t.string "encrypted_password", :default => "", :null => false
19
+ t.string "reset_password_token"
20
+ t.datetime "reset_password_sent_at"
21
+ t.datetime "remember_created_at"
22
+ t.integer "sign_in_count", :default => 0
23
+ t.datetime "current_sign_in_at"
24
+ t.datetime "last_sign_in_at"
25
+ t.string "current_sign_in_ip"
26
+ t.string "last_sign_in_ip"
27
+ t.string "uid"
28
+ t.datetime "created_at", :null => false
29
+ t.datetime "updated_at", :null => false
30
+ end
31
+
32
+ add_index "users", ["email"], :name => "index_users_on_email", :unique => true
33
+ add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
34
+
35
+ end
@@ -0,0 +1,35 @@
1
+ Feature: Manage logins
2
+ In order to login with Devise LDAP Authenticatable
3
+ As a user
4
+ I want to login with LDAP
5
+
6
+ Background:
7
+ Given I check for SSL
8
+ Given the following logins:
9
+ | email | password |
10
+ | example.user@test.com | secret |
11
+
12
+ Scenario: Login with valid user
13
+ Given I am on the login page
14
+ When I fill in "Email" with "example.user@test.com"
15
+ And I fill in "Password" with "secret"
16
+ And I press "Sign in"
17
+ Then I should see "posts#index"
18
+
19
+ Scenario: Login with invalid user
20
+ Given I am on the login page
21
+ When I fill in "Email" with "example.user@test.com"
22
+ And I fill in "Password" with "wrong"
23
+ And I press "Sign in"
24
+ Then I should see "Invalid email or password"
25
+
26
+ Scenario: Get redirected to the login page and then login
27
+ When I go to the new post page
28
+ Then I should be on the login page
29
+ When I fill in "Email" with "example.user@test.com"
30
+ And I fill in "Password" with "secret"
31
+ And I press "Sign in"
32
+ Then I should be on the new post page
33
+
34
+
35
+