contour 0.0.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/CHANGELOG.rdoc +13 -0
- data/README.rdoc +56 -0
- data/app/controllers/contour/authentications_controller.rb +60 -0
- data/app/controllers/contour/registrations_controller.rb +16 -0
- data/app/controllers/contour/samples_controller.rb +5 -0
- data/app/controllers/contour/sessions_controller.rb +3 -0
- data/app/views/contour/authentications/_index.html.erb +25 -0
- data/app/views/contour/authentications/_menu.html.erb +25 -0
- data/app/views/contour/authentications/index.html.erb +27 -0
- data/app/views/contour/layouts/_menu.html.erb +32 -0
- data/app/views/contour/layouts/_message.html.erb +8 -0
- data/app/views/contour/layouts/application.html.erb +47 -0
- data/app/views/contour/registrations/edit.html.erb +25 -0
- data/app/views/contour/registrations/new.html.erb +37 -0
- data/app/views/contour/samples/index.html.erb +27 -0
- data/app/views/contour/sessions/new.html.erb +25 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/contour.gemspec +27 -0
- data/lib/contour.rb +36 -0
- data/lib/contour/engine.rb +8 -0
- data/lib/contour/version.rb +1 -1
- data/lib/generators/contour/install_generator.rb +38 -0
- data/lib/generators/templates/contour.rb +30 -0
- data/lib/generators/templates/devise.rb +153 -0
- data/lib/generators/templates/omniauth.rb +22 -0
- data/lib/generators/templates/omniauth_fix.rb +98 -0
- data/lib/generators/templates/rack_fix.rb +44 -0
- data/vendor/assets/images/authbuttons/cas_32.png +0 -0
- data/vendor/assets/images/authbuttons/cas_64.png +0 -0
- data/vendor/assets/images/authbuttons/facebook_32.png +0 -0
- data/vendor/assets/images/authbuttons/facebook_64.png +0 -0
- data/vendor/assets/images/authbuttons/google_apps_32.png +0 -0
- data/vendor/assets/images/authbuttons/google_apps_64.png +0 -0
- data/vendor/assets/images/authbuttons/ldap_32.png +0 -0
- data/vendor/assets/images/authbuttons/ldap_64.png +0 -0
- data/vendor/assets/images/authbuttons/linkedin_32.png +0 -0
- data/vendor/assets/images/authbuttons/linkedin_64.png +0 -0
- data/vendor/assets/images/authbuttons/openid_32.png +0 -0
- data/vendor/assets/images/authbuttons/openid_64.png +0 -0
- data/vendor/assets/images/authbuttons/twitter_32.png +0 -0
- data/vendor/assets/images/authbuttons/twitter_64.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_flat_55_fbec88_40x100.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_glass_85_dfeffc_1x400.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
- data/vendor/assets/images/redmond/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
- data/vendor/assets/images/redmond/ui-icons_217bc0_256x240.png +0 -0
- data/vendor/assets/images/redmond/ui-icons_2e83ff_256x240.png +0 -0
- data/vendor/assets/images/redmond/ui-icons_469bdd_256x240.png +0 -0
- data/vendor/assets/images/redmond/ui-icons_6da8d5_256x240.png +0 -0
- data/vendor/assets/images/redmond/ui-icons_cd0a0a_256x240.png +0 -0
- data/vendor/assets/images/redmond/ui-icons_d8e7f3_256x240.png +0 -0
- data/vendor/assets/images/redmond/ui-icons_f9bd01_256x240.png +0 -0
- data/vendor/assets/javascripts/contour.js +8 -0
- data/vendor/assets/javascripts/errors.js.coffee +10 -0
- data/vendor/assets/javascripts/external/exporting-2.1.4.src.js +673 -0
- data/vendor/assets/javascripts/external/highcharts-2.1.4.src.js +10668 -0
- data/vendor/assets/javascripts/external/jquery-ui-1.8.10.custom.min.js +782 -0
- data/vendor/assets/javascripts/external/waypoints.js +610 -0
- data/vendor/assets/javascripts/global.js.coffee +38 -0
- data/vendor/assets/javascripts/menu.js.coffee +6 -0
- data/vendor/assets/javascripts/popup.js.coffee +67 -0
- data/vendor/assets/stylesheets/authentication.css +63 -0
- data/vendor/assets/stylesheets/bluetrip-screen.css +324 -0
- data/vendor/assets/stylesheets/contour.css +15 -0
- data/vendor/assets/stylesheets/global.css +59 -0
- data/vendor/assets/stylesheets/header.css +18 -0
- data/vendor/assets/stylesheets/jquery-ui-1.8.10.custom.css +574 -0
- data/vendor/assets/stylesheets/menu.css +77 -0
- data/vendor/assets/stylesheets/message.css +27 -0
- data/vendor/assets/stylesheets/popup.css +79 -0
- metadata +114 -29
- data/README +0 -18
@@ -0,0 +1,16 @@
|
|
1
|
+
<h2>Change your password</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
<%= f.hidden_field :reset_password_token %>
|
6
|
+
|
7
|
+
<p><%= f.label :password %><br />
|
8
|
+
<%= f.password_field :password %></p>
|
9
|
+
|
10
|
+
<p><%= f.label :password_confirmation %><br />
|
11
|
+
<%= f.password_field :password_confirmation %></p>
|
12
|
+
|
13
|
+
<p><%= f.submit "Change my password" %></p>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<%= render :partial => "devise/shared/links" %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2>Forgot your password?</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Send me reset password instructions" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= render :partial => "devise/shared/links" %>
|
data/contour.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Compiling the Gem
|
2
|
+
# gem build contour.gemspec
|
3
|
+
# [sudo] gem install ./contour-x.x.x.gem
|
4
|
+
#
|
5
|
+
# gem push contour-x.x.x.gem
|
6
|
+
# gem list -r contour
|
7
|
+
# gem install contour
|
8
|
+
|
9
|
+
$:.push File.expand_path("../lib", __FILE__)
|
10
|
+
require "contour/version"
|
11
|
+
|
12
|
+
Gem::Specification.new do |s|
|
13
|
+
s.name = "contour"
|
14
|
+
s.version = Contour::VERSION.dup
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.summary = "Basic Rails framework files and assets for layout and authentication"
|
17
|
+
s.email = "remosm@gmail.com"
|
18
|
+
s.homepage = "https://github.com/remomueller"
|
19
|
+
s.authors = ["Remo Mueller"]
|
20
|
+
s.description = "Basic Rails Framework files and assets for layout and authentication"
|
21
|
+
|
22
|
+
# s.add_development_dependency "rails", "~> 3.0"
|
23
|
+
s.add_dependency("devise", "~> 1.3.4")
|
24
|
+
s.add_dependency("omniauth", "~> 0.2.6")
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
end
|
data/lib/contour.rb
CHANGED
@@ -1,5 +1,41 @@
|
|
1
|
+
require 'contour/engine' if defined?(Rails)
|
1
2
|
require 'contour/version'
|
2
3
|
|
3
4
|
module Contour
|
5
|
+
# Default Application Name
|
6
|
+
mattr_accessor :application_name
|
7
|
+
@@application_name = nil
|
8
|
+
|
9
|
+
# Default Application Version
|
10
|
+
mattr_accessor :application_version
|
11
|
+
@@application_version = nil
|
12
|
+
|
13
|
+
# Default Application Version
|
14
|
+
mattr_accessor :header_background_image
|
15
|
+
@@header_background_image = 'rails.png'
|
16
|
+
|
17
|
+
# Default Application Version
|
18
|
+
mattr_accessor :header_title_image
|
19
|
+
@@header_title_image = nil
|
4
20
|
|
21
|
+
# Default Menu Items
|
22
|
+
mattr_accessor :menu_items
|
23
|
+
@@menu_items = [
|
24
|
+
{
|
25
|
+
:name => 'Login', :id => 'auth', :display => 'not_signed_in', :position => 'right', :position_class => 'right',
|
26
|
+
:links => [{:name => 'Login', :path => 'new_user_session_path'}, {:html => "<hr>"}, {:name => 'Sign Up', :path => 'new_user_registration_path'}]
|
27
|
+
},
|
28
|
+
{
|
29
|
+
:name => 'current_user.name', :eval => true, :id => 'auth', :display => 'signed_in', :position => 'right', :position_class => 'right',
|
30
|
+
:links => [{:html => '"<div style=\"white-space:nowrap\">"+current_user.name+"</div>"', :eval => true}, {:html => '"<div class=\"small quiet\">"+current_user.email+"</div>"', :eval => true}, {:name => 'Authentications', :path => 'authentications_path'}, {:html => "<hr>"}, {:name => 'Logout', :path => 'destroy_user_session_path'}]
|
31
|
+
},
|
32
|
+
{
|
33
|
+
:name => 'Home', :id => 'home', :display => 'always', :position => 'left', :position_class => 'left',
|
34
|
+
:links => [{:name => 'Home', :path => 'root_path'}, {:html => "<hr>"}, {:name => 'About', :path => 'about_path'}]
|
35
|
+
}
|
36
|
+
]
|
37
|
+
|
38
|
+
def self.setup
|
39
|
+
yield self
|
40
|
+
end
|
5
41
|
end
|
data/lib/contour/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Contour
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates a Contour initializer"
|
7
|
+
class_option :orm
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
template "contour.rb", "config/initializers/contour.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_devise
|
14
|
+
template "devise.rb", "config/initializers/devise.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_omniauth
|
18
|
+
template "omniauth.rb", "config/initializers/omniauth.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_omniauth_fix
|
22
|
+
template "omniauth_fix.rb", "config/initializers/omniauth_fix.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_rack_fix
|
26
|
+
template "rack_fix.rb", "config/initializers/rack_fix.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
# def copy_locale
|
30
|
+
# copy_file "../../../config/locales/en.yml", "config/locales/contour.en.yml"
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# def show_readme
|
34
|
+
# readme "README" if behavior == :invoke
|
35
|
+
# end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Use to configure basic appearance of template
|
2
|
+
Contour.setup do |config|
|
3
|
+
|
4
|
+
# Enter your application name here. The name will be displayed in the title of all pages, ex: AppName - PageTitle
|
5
|
+
# config.application_name = ''
|
6
|
+
|
7
|
+
# Enter your application version here. Do not include a trailing backslash. Recommend using a predefined constant
|
8
|
+
# config.application_version = ''
|
9
|
+
|
10
|
+
# Enter your application header background image here.
|
11
|
+
# config.header_background_image = 'rails.png'
|
12
|
+
|
13
|
+
# Enter your application header title image here.
|
14
|
+
# config.header_title_image = ''
|
15
|
+
|
16
|
+
# Enter the items you wish to see in the menu
|
17
|
+
# config.menu_items = [{
|
18
|
+
# :name => 'Login', :id => 'auth', :display => 'not_signed_in', :position => 'right', :position_class => 'right',
|
19
|
+
# :links => [{:name => 'Login', :path => 'new_user_session_path'}, {:html => "<hr>"}, {:name => 'Sign Up', :path => 'new_user_registration_path'}]
|
20
|
+
# },
|
21
|
+
# {
|
22
|
+
# :name => 'current_user.name', :eval => true, :id => 'auth', :display => 'signed_in', :position => 'right', :position_class => 'right',
|
23
|
+
# :links => [{:html => '"<div style=\"white-space:nowrap\">"+current_user.name+"</div>"', :eval => true}, {:html => '"<div class=\"small quiet\">"+current_user.email+"</div>"', :eval => true}, {:name => 'Authentications', :path => 'authentications_path'}, {:html => "<hr>"}, {:name => 'Logout', :path => 'destroy_user_session_path'}]
|
24
|
+
# },
|
25
|
+
# {
|
26
|
+
# :name => 'Home', :id => 'home', :display => 'always', :position => 'left', :position_class => 'left',
|
27
|
+
# :links => [{:name => 'Home', :path => 'root_path'}, {:html => "<hr>"}, {:name => 'About', :path => 'about_path'}]
|
28
|
+
# }]
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
2
|
+
# four configuration values can also be set straight in your models.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# ==> Mailer Configuration
|
5
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
6
|
+
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
7
|
+
|
8
|
+
# Configure the class responsible to send e-mails.
|
9
|
+
# config.mailer = "Devise::Mailer"
|
10
|
+
|
11
|
+
# ==> ORM configuration
|
12
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
13
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
14
|
+
# available as additional gems.
|
15
|
+
require 'devise/orm/active_record'
|
16
|
+
|
17
|
+
# ==> Configuration for any authentication mechanism
|
18
|
+
# Configure which keys are used when authenticating an user. By default is
|
19
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
20
|
+
# authenticating an user, both parameters are required. Remember that those
|
21
|
+
# parameters are used only when authenticating and not when retrieving from
|
22
|
+
# session. If you need permissions, you should implement that in a before filter.
|
23
|
+
# config.authentication_keys = [ :email ]
|
24
|
+
|
25
|
+
# Tell if authentication through request.params is enabled. True by default.
|
26
|
+
# config.params_authenticatable = true
|
27
|
+
|
28
|
+
# Tell if authentication through HTTP Basic Auth is enabled. True by default.
|
29
|
+
# config.http_authenticatable = true
|
30
|
+
|
31
|
+
# Set this to true to use Basic Auth for AJAX requests. True by default.
|
32
|
+
# config.http_authenticatable_on_xhr = true
|
33
|
+
|
34
|
+
# The realm used in Http Basic Authentication
|
35
|
+
# config.http_authentication_realm = "Application"
|
36
|
+
|
37
|
+
# ==> Configuration for :database_authenticatable
|
38
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
39
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
40
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
41
|
+
|
42
|
+
# Define which will be the encryption algorithm. Devise also supports encryptors
|
43
|
+
# from others authentication tools as :clearance_sha1, :authlogic_sha512 (then
|
44
|
+
# you should set stretches above to 20 for default behavior) and :restful_authentication_sha1
|
45
|
+
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
46
|
+
config.encryptor = :bcrypt
|
47
|
+
|
48
|
+
# Setup a pepper to generate the encrypted password.
|
49
|
+
config.pepper = "c4ee59fb687661675e930b1394e179db1bbe9147766f161a450e5f6dcdd4110195c0496be28b5321f68a29a2c6fb5728db87b32779231dae57b4c93460406e16"
|
50
|
+
|
51
|
+
# ==> Configuration for :confirmable
|
52
|
+
# The time you want to give your user to confirm his account. During this time
|
53
|
+
# he will be able to access your application without confirming. Default is nil.
|
54
|
+
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
55
|
+
# You can use this to let your user access some features of your application
|
56
|
+
# without confirming the account, but blocking it after a certain period
|
57
|
+
# (ie 2 days).
|
58
|
+
# config.confirm_within = 2.days
|
59
|
+
|
60
|
+
# ==> Configuration for :rememberable
|
61
|
+
# The time the user will be remembered without asking for credentials again.
|
62
|
+
# config.remember_for = 2.weeks
|
63
|
+
|
64
|
+
# If true, a valid remember token can be re-used between multiple browsers.
|
65
|
+
# config.remember_across_browsers = true
|
66
|
+
|
67
|
+
# If true, extends the user's remember period when remembered via cookie.
|
68
|
+
# config.extend_remember_period = false
|
69
|
+
|
70
|
+
# ==> Configuration for :validatable
|
71
|
+
# Range for password length
|
72
|
+
# config.password_length = 6..20
|
73
|
+
|
74
|
+
# Regex to use to validate the email address
|
75
|
+
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
76
|
+
|
77
|
+
# ==> Configuration for :timeoutable
|
78
|
+
# The time you want to timeout the user session without activity. After this
|
79
|
+
# time the user will be asked for credentials again.
|
80
|
+
config.timeout_in = 8.hours
|
81
|
+
|
82
|
+
# ==> Configuration for :lockable
|
83
|
+
# Defines which strategy will be used to lock an account.
|
84
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
85
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
86
|
+
# config.lock_strategy = :failed_attempts
|
87
|
+
|
88
|
+
# Defines which strategy will be used to unlock an account.
|
89
|
+
# :email = Sends an unlock link to the user email
|
90
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
91
|
+
# :both = Enables both strategies
|
92
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
93
|
+
# config.unlock_strategy = :both
|
94
|
+
|
95
|
+
# Number of authentication tries before locking an account if lock_strategy
|
96
|
+
# is failed attempts.
|
97
|
+
# config.maximum_attempts = 20
|
98
|
+
|
99
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
100
|
+
# config.unlock_in = 1.hour
|
101
|
+
|
102
|
+
# ==> Configuration for :token_authenticatable
|
103
|
+
# Defines name of the authentication token params key
|
104
|
+
# config.token_authentication_key = :auth_token
|
105
|
+
|
106
|
+
# ==> Scopes configuration
|
107
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
108
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
109
|
+
# are using only default views.
|
110
|
+
# config.scoped_views = true
|
111
|
+
|
112
|
+
# Configure the default scope given to Warden. By default it's the first
|
113
|
+
# devise role declared in your routes.
|
114
|
+
# config.default_scope = :user
|
115
|
+
|
116
|
+
# Configure sign_out behavior.
|
117
|
+
# By default sign_out is scoped (i.e. /users/sign_out affects only :user scope).
|
118
|
+
# In case of sign_out_all_scopes set to true any logout action will sign out all active scopes.
|
119
|
+
# config.sign_out_all_scopes = false
|
120
|
+
|
121
|
+
# ==> Navigation configuration
|
122
|
+
# Lists the formats that should be treated as navigational. Formats like
|
123
|
+
# :html, should redirect to the sign in page when the user does not have
|
124
|
+
# access, but formats like :xml or :json, should return 401.
|
125
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
126
|
+
# should add them to the navigational formats lists. Default is [:html]
|
127
|
+
# config.navigational_formats = [:html, :iphone]
|
128
|
+
|
129
|
+
# ==> Warden configuration
|
130
|
+
# If you want to use other strategies, that are not (yet) supported by Devise,
|
131
|
+
# you can configure them inside the config.warden block. The example below
|
132
|
+
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
133
|
+
#
|
134
|
+
# config.warden do |manager|
|
135
|
+
# manager.oauth(:twitter) do |twitter|
|
136
|
+
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
|
137
|
+
# twitter.consumer_key = <YOUR CONSUMER KEY>
|
138
|
+
# twitter.options :site => 'http://twitter.com'
|
139
|
+
# end
|
140
|
+
# manager.default_strategies(:scope => :user).unshift :twitter_oauth
|
141
|
+
# end
|
142
|
+
end
|
143
|
+
|
144
|
+
module Devise
|
145
|
+
class FailureApp < ActionController::Metal
|
146
|
+
def http_auth
|
147
|
+
self.status = 403
|
148
|
+
self.headers["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect})
|
149
|
+
self.content_type = request.format.to_s
|
150
|
+
self.response_body = http_auth_body
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'openid/store/filesystem'
|
2
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
3
|
+
provider :google_apps, OpenID::Store::Filesystem.new('/tmp')
|
4
|
+
provider :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
|
5
|
+
provider :facebook, 'APP_ID', 'APP_SECRET'
|
6
|
+
provider :linked_in, 'CONSUMER_KEY', 'CONSUMER_SECRET'
|
7
|
+
provider :open_id, OpenID::Store::Filesystem.new('/tmp')
|
8
|
+
provider :CAS, :cas_server => 'https://www.example.com/cas'
|
9
|
+
provider :LDAP, :host => 'ldap.example.com', :port => 389, :method => :simple, :base => 'cn=users,dc=example,dc=com', :uid => 'sAMAccountName', :try_sasl => true, :sasl_mechanisms => "GSS-SPNEGO", :domain => ''
|
10
|
+
end
|
11
|
+
|
12
|
+
# This list will show the first choice as the default, and the rest as potential secondary login methods.
|
13
|
+
PROVIDERS = [:google_apps, :twitter, :facebook, :linked_in, :open_id, :CAS, :LDAP]
|
14
|
+
|
15
|
+
# LDAP
|
16
|
+
# :port (required) - The LDAP server port.
|
17
|
+
# :method (required) - May be :plain, :ssl, or :tls.
|
18
|
+
# :base (required) - The distinguished name (DN) for your organization; all users should be searchable under this base.
|
19
|
+
# :uid (required) - The LDAP attribute name for the user name in the login form. Typically AD would be 'sAMAccountName' or 'UniquePersonalIdentifier', while OpenLDAP is 'uid'. You can also use 'dn' for the user to put in the dn in the login form (but usually is too long for user to remember or know).
|
20
|
+
# :try_sasl - Try to use SASL connection to server.
|
21
|
+
# :sasl_mechanisms - Mechanisms supported are 'DIGEST-MD5' and 'GSS-SPNEGO'
|
22
|
+
# :domain - Enter to keep users from having to enter the LDAP domain, usually in the form domain\username. Backslash will be appended automatically.
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
class LDAP
|
4
|
+
|
5
|
+
def initialize(app, options = {}, &block)
|
6
|
+
super(app, options[:name] || :ldap, options.dup, &block)
|
7
|
+
@name_proc = (@options.delete(:name_proc) || Proc.new {|name| name})
|
8
|
+
@adaptor = OmniAuth::Strategies::LDAP::Adaptor.new(options)
|
9
|
+
@domain = options[:domain] # Added
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
# Reroutes directly to callback_phase instead of redirecting to callback_path
|
15
|
+
# TODO: Possibility that this could be removed in the future.
|
16
|
+
def request_phase
|
17
|
+
Rails.logger.info "Request Phase Hook"
|
18
|
+
if env['REQUEST_METHOD'] == 'GET'
|
19
|
+
get_credentials
|
20
|
+
else
|
21
|
+
session['omniauth.ldap'] = {'username' => request['username'], 'password' => request['password']}
|
22
|
+
if true
|
23
|
+
Rails.logger.info "Skipping Redirect"
|
24
|
+
callback_phase # Added
|
25
|
+
else
|
26
|
+
redirect callback_path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Includes addition of a "domain"
|
32
|
+
def callback_phase
|
33
|
+
begin
|
34
|
+
creds = session['omniauth.ldap']
|
35
|
+
session.delete 'omniauth.ldap'
|
36
|
+
@ldap_user_info = {}
|
37
|
+
begin
|
38
|
+
creds['username'] = @domain.to_s + '\\' + creds['username'] unless @domain.blank?
|
39
|
+
@adaptor.bind(:bind_dn => creds['username'], :password => creds['password'])
|
40
|
+
rescue Exception => e
|
41
|
+
Rails.logger.info "Exception #{e.inspect}"
|
42
|
+
Rails.logger.info "failed to bind with the default credentials: " + e.message
|
43
|
+
return fail!(:invalid_credentials, e)
|
44
|
+
end
|
45
|
+
|
46
|
+
@ldap_user_info = @adaptor.search(:base => @adaptor.base, :filter => Net::LDAP::Filter.eq(@adaptor.uid, creds['username'].split('\\').last.to_s),:limit => 1)
|
47
|
+
@ldap_user_info.each do |key, val|
|
48
|
+
@ldap_user_info[key] = val.first if val.class == Array and val.size == 1
|
49
|
+
end
|
50
|
+
|
51
|
+
@user_info = self.class.map_user(@@config, @ldap_user_info)
|
52
|
+
|
53
|
+
@env['REQUEST_METHOD'] = 'GET'
|
54
|
+
# @env['PATH_INFO'] = callback_path
|
55
|
+
@env['PATH_INFO'] = "#{OmniAuth.config.path_prefix.split('/').last}/#{name}/callback"
|
56
|
+
|
57
|
+
@env['omniauth.auth'] = {'provider' => 'ldap', 'uid' => @user_info['uid'], 'user_info' => @user_info, 'bla' => 5}
|
58
|
+
rescue Exception => e
|
59
|
+
Rails.logger.info "Exception #{e.inspect}"
|
60
|
+
return fail!(:invalid_credentials, e)
|
61
|
+
end
|
62
|
+
|
63
|
+
call_app!
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.map_user mapper, object
|
67
|
+
user = {}
|
68
|
+
mapper.each do |key, value|
|
69
|
+
case value
|
70
|
+
when String
|
71
|
+
if object[value.downcase.to_sym]
|
72
|
+
if object[value.downcase.to_sym].kind_of?(Array)
|
73
|
+
user[key] = object[value.downcase.to_sym].join(', ')
|
74
|
+
else
|
75
|
+
user[key] = object[value.downcase.to_sym].to_s
|
76
|
+
end
|
77
|
+
end
|
78
|
+
when Array
|
79
|
+
# value.each {|v| (user[key] = object[v.downcase.to_sym].to_s; break;) if object[v.downcase.to_sym]}
|
80
|
+
value.each {|v| (user[key] = object[v.downcase.to_sym].join(', '); break;) if object[v.downcase.to_sym]}
|
81
|
+
when Hash
|
82
|
+
value.map do |key1, value1|
|
83
|
+
pattern = key1.dup
|
84
|
+
value1.each_with_index do |v,i|
|
85
|
+
part = '';
|
86
|
+
v.each {|v1| (part = object[v1.downcase.to_sym].to_s; break;) if object[v1.downcase.to_sym]}
|
87
|
+
pattern.gsub!("%#{i}",part||'')
|
88
|
+
end
|
89
|
+
user[key] = pattern
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
user
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|