public
Fork of gitmirror/webistrano
Description: My fork of the Webistrano SVN source mirror.
Homepage: http://labs.peritor.com/webistrano
Clone URL: git://github.com/timshadel/webistrano.git
Add CAS authentication as an option.

To use:
* Login with an existing admin user (like the default admin/admin)
* Create a new user with a login that matches their CAS login
* Give that user a dummy password (it won't be checked)
* Stop Webistrano
* Uncomment the CAS setting (see config/webistrano_config.rb.sample)
* Start Webistrano
* When accessing Webistrano, you should be sent to the CAS page, or you
  should be automatically logged in if you've signed in already.

Signed-off-by: Tim Shadel <github@timshadel.com>
timshadel (author)
Tue Sep 23 13:25:03 -0700 2008
commit  24a304afeabf5dcc9139e5bbb7396bdbf56b711c
tree    9284ddf2d4f083f2128d89543e050e7d2da5b0c9
parent  76b00ded89f7c92eed1883b412fa4c801a3b9df4
...
3
4
5
 
6
7
8
...
3
4
5
6
7
8
9
0
@@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
0
   include ExceptionNotifiable
0
   include AuthenticatedSystem
0
   
0
+  before_filter CASClient::Frameworks::Rails::Filter if WebistranoConfig[:authentication_method] == :cas
0
   before_filter :login_from_cookie, :login_required
0
   around_filter :set_timezone
0
 
...
26
27
28
29
30
 
 
 
 
 
 
31
32
33
...
26
27
28
 
 
29
30
31
32
33
34
35
36
37
0
@@ -26,8 +26,12 @@ class SessionsController < ApplicationController
0
     self.current_user.forget_me if logged_in?
0
     cookies.delete :auth_token
0
     reset_session
0
-    flash[:notice] = "You have been logged out."
0
-    redirect_back_or_default( home_path )
0
+    if WebistranoConfig[:authentication_method] != :cas
0
+      flash[:notice] = "You have been logged out."
0
+      redirect_back_or_default( home_path )
0
+    else
0
+      redirect_to "#{CASClient::Frameworks::Rails::Filter.config[:logout_url]}?serviceUrl=#{home_url}"
0
+    end
0
   end
0
   
0
   def version
...
1
2
3
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
0
@@ -1,6 +1,9 @@
0
 class StylesheetsController < ApplicationController
0
   
0
   skip_before_filter :login_required
0
+  if WebistranoConfig[:authentication_method] == :cas
0
+    skip_before_filter CASClient::Frameworks::Rails::Filter
0
+  end
0
   
0
   session :off
0
   
...
99
100
101
102
 
103
104
105
...
99
100
101
 
102
103
104
105
0
@@ -99,7 +99,7 @@ class User < ActiveRecord::Base
0
     end
0
     
0
     def password_required?
0
-      crypted_password.blank? || !password.blank?
0
+      WebistranoConfig[:authentication_method] != :cas && (crypted_password.blank? || !password.blank?)
0
     end
0
 
0
     
...
9
10
11
 
12
13
14
...
18
19
20
 
21
22
23
...
9
10
11
12
13
14
15
...
19
20
21
22
23
24
25
0
@@ -9,6 +9,7 @@
0
   <%= text_field 'user', 'email', :style =>'width:330px;' %>
0
 </p>
0
 
0
+<% unless WebistranoConfig[:authentication_method] == :cas -%>
0
 <p>
0
   <b>Password</b><br />
0
   <%= password_field 'user', 'password', :style =>'width:330px;' %>
0
@@ -18,6 +19,7 @@
0
   <b>Password confirmation</b><br />
0
   <%= password_field 'user', 'password_confirmation', :style =>'width:330px;' %>
0
 </p>
0
+<% end -%>
0
 
0
 <p>
0
   <b>Timezone</b><br />
...
34
35
36
 
37
38
39
...
76
77
78
 
 
 
 
 
79
80
81
...
34
35
36
37
38
39
40
...
77
78
79
80
81
82
83
84
85
86
87
0
@@ -34,6 +34,7 @@ Rails::Initializer.run do |config|
0
   # Force all environments to use the same logger level
0
   # (by default production uses :info, the others :debug)
0
   # config.log_level = :debug
0
+  
0
 
0
   # Your secret key for verifying cookie session data integrity.
0
   # If you change this key, all old sessions will become invalid!
0
@@ -76,6 +77,11 @@ end
0
 
0
 # Include your application configuration below
0
 
0
+if WebistranoConfig[:authentication_method] == :cas
0
+  cas_options = YAML::load_file(RAILS_ROOT+'/config/cas.yml')
0
+  CASClient::Frameworks::Rails::Filter.configure(cas_options[RAILS_ENV])
0
+end
0
+
0
 WEBISTRANO_VERSION = '1.4'
0
 
0
 ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:log => '%Y-%m-%d %H:%M')
...
7
8
9
 
 
 
10
11
12
...
26
27
28
29
 
30
...
7
8
9
10
11
12
13
14
15
...
29
30
31
 
32
33
0
@@ -7,6 +7,9 @@ WebistranoConfig = {
0
 
0
   # secret password for session HMAC
0
   :session_secret => 'please choose a long random string, min. 30 characters',
0
+
0
+  # Uncomment to use CAS authentication
0
+  # :authentication_method => :cas,
0
   
0
   # SMTP settings for outgoing email
0
   :smtp_delivery_method => :sendmail,
0
@@ -26,5 +29,5 @@ WebistranoConfig = {
0
   # Sender and recipient for Webistrano exceptions
0
   :exception_recipients => "team@example.com",
0
   :exception_sender_address => "webistrano@example.com"
0
-  
0
+
0
 }
...
9
10
11
12
 
13
14
15
...
95
96
97
 
 
 
 
 
98
99
100
...
9
10
11
 
12
13
14
15
...
95
96
97
98
99
100
101
102
103
104
105
0
@@ -9,7 +9,7 @@ module AuthenticatedSystem
0
     # Accesses the current user from the session.  Set it to :false if login fails
0
     # so that future calls do not hit the database.
0
     def current_user
0
-      @current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie || :false)
0
+      @current_user ||= (login_from_cas || login_from_session || login_from_basic_auth || login_from_cookie || :false)
0
     end
0
     
0
     # Store the given user in the session.
0
@@ -95,6 +95,11 @@ module AuthenticatedSystem
0
       base.send :helper_method, :current_user, :logged_in?
0
     end
0
 
0
+    # Called from #current_user.  First attempt to login by the user id from cas.
0
+    def login_from_cas
0
+      self.current_user = User.find_by_login(session[:cas_user]) if session[:cas_user]
0
+    end
0
+
0
     # Called from #current_user.  First attempt to login by the user id stored in the session.
0
     def login_from_session
0
       self.current_user = User.find_by_id(session[:user]) if session[:user]

Comments