uchouhan-rubycas-server 1.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/CHANGELOG +289 -0
  2. data/LICENSE +26 -0
  3. data/README.md +19 -0
  4. data/Rakefile +1 -0
  5. data/bin/rubycas-server +16 -0
  6. data/bin/rubycas-server-ctl +9 -0
  7. data/lib/casserver.rb +13 -0
  8. data/lib/casserver/authenticators/active_directory_ldap.rb +19 -0
  9. data/lib/casserver/authenticators/authlogic_crypto_providers/aes256.rb +43 -0
  10. data/lib/casserver/authenticators/authlogic_crypto_providers/bcrypt.rb +92 -0
  11. data/lib/casserver/authenticators/authlogic_crypto_providers/md5.rb +34 -0
  12. data/lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb +59 -0
  13. data/lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb +50 -0
  14. data/lib/casserver/authenticators/base.rb +67 -0
  15. data/lib/casserver/authenticators/client_certificate.rb +47 -0
  16. data/lib/casserver/authenticators/google.rb +58 -0
  17. data/lib/casserver/authenticators/ldap.rb +147 -0
  18. data/lib/casserver/authenticators/ntlm.rb +88 -0
  19. data/lib/casserver/authenticators/open_id.rb +22 -0
  20. data/lib/casserver/authenticators/sql.rb +133 -0
  21. data/lib/casserver/authenticators/sql_authlogic.rb +93 -0
  22. data/lib/casserver/authenticators/sql_encrypted.rb +77 -0
  23. data/lib/casserver/authenticators/sql_md5.rb +19 -0
  24. data/lib/casserver/authenticators/sql_rest_auth.rb +85 -0
  25. data/lib/casserver/authenticators/tacc.rb +67 -0
  26. data/lib/casserver/authenticators/test.rb +21 -0
  27. data/lib/casserver/cas.rb +327 -0
  28. data/lib/casserver/localization.rb +91 -0
  29. data/lib/casserver/model.rb +269 -0
  30. data/lib/casserver/server.rb +623 -0
  31. data/lib/casserver/utils.rb +32 -0
  32. data/lib/casserver/views/_login_form.erb +41 -0
  33. data/lib/casserver/views/layout.erb +17 -0
  34. data/lib/casserver/views/login.erb +29 -0
  35. data/lib/casserver/views/proxy.builder +11 -0
  36. data/lib/casserver/views/proxy_validate.builder +26 -0
  37. data/lib/casserver/views/service_validate.builder +19 -0
  38. data/lib/casserver/views/validate.erb +1 -0
  39. data/po/de_DE/rubycas-server.po +127 -0
  40. data/po/es_ES/rubycas-server.po +123 -0
  41. data/po/fr_FR/rubycas-server.po +128 -0
  42. data/po/ja_JP/rubycas-server.po +126 -0
  43. data/po/pl_PL/rubycas-server.po +123 -0
  44. data/po/pt_BR/rubycas-server.po +123 -0
  45. data/po/ru_RU/rubycas-server.po +118 -0
  46. data/po/rubycas-server.pot +112 -0
  47. data/po/zh_CN/rubycas-server.po +113 -0
  48. data/po/zh_TW/rubycas-server.po +113 -0
  49. data/public/themes/cas.css +121 -0
  50. data/public/themes/notice.png +0 -0
  51. data/public/themes/ok.png +0 -0
  52. data/public/themes/simple/bg.png +0 -0
  53. data/public/themes/simple/favicon.png +0 -0
  54. data/public/themes/simple/login_box_bg.png +0 -0
  55. data/public/themes/simple/logo.png +0 -0
  56. data/public/themes/simple/theme.css +28 -0
  57. data/public/themes/tadnet/bg.png +0 -0
  58. data/public/themes/tadnet/button.png +0 -0
  59. data/public/themes/tadnet/favicon.png +0 -0
  60. data/public/themes/tadnet/login_box_bg.png +0 -0
  61. data/public/themes/tadnet/logo.png +0 -0
  62. data/public/themes/tadnet/theme.css +55 -0
  63. data/public/themes/urbacon/bg.png +0 -0
  64. data/public/themes/urbacon/login_box_bg.png +0 -0
  65. data/public/themes/urbacon/logo.png +0 -0
  66. data/public/themes/urbacon/theme.css +33 -0
  67. data/public/themes/warning.png +0 -0
  68. data/resources/config.example.yml +574 -0
  69. data/resources/config.ru +42 -0
  70. data/resources/custom_views.example.rb +11 -0
  71. data/resources/init.d.sh +58 -0
  72. data/rubycas-server.gemspec +40 -0
  73. data/setup.rb +1585 -0
  74. data/spec/alt_config.yml +46 -0
  75. data/spec/casserver_spec.rb +114 -0
  76. data/spec/default_config.yml +46 -0
  77. data/spec/spec.opts +4 -0
  78. data/spec/spec_helper.rb +89 -0
  79. data/tasks/bundler.rake +4 -0
  80. data/tasks/db/migrate.rake +12 -0
  81. data/tasks/localization.rake +13 -0
  82. data/tasks/spec.rake +10 -0
  83. metadata +172 -0
@@ -0,0 +1,46 @@
1
+ server: webrick
2
+ port: 6543
3
+ #ssl_cert: test.pem
4
+ uri_path: /test
5
+ #bind_address: 0.0.0.0
6
+
7
+ # database:
8
+ # adapter: mysql
9
+ # database: casserver
10
+ # username: root
11
+ # password:
12
+ # host: localhost
13
+ # reconnect: true
14
+ database:
15
+ adapter: sqlite3
16
+ database: spec/casserver_spec.db
17
+
18
+ authenticator:
19
+ class: CASServer::Authenticators::Test
20
+ password: spec_password
21
+
22
+ theme: simple
23
+
24
+ organization: "RSPEC-TEST"
25
+
26
+ infoline: "This is an rspec test."
27
+
28
+ #custom_views_file: /path/to/custom/views.rb
29
+
30
+ default_locale: en
31
+
32
+ log:
33
+ file: casserver_spec.log
34
+ level: DEBUG
35
+
36
+ #db_log:
37
+ # file: casserver_spec_db.log
38
+
39
+ enable_single_sign_out: true
40
+
41
+ #maximum_unused_login_ticket_lifetime: 300
42
+ #maximum_unused_service_ticket_lifetime: 300
43
+
44
+ #maximum_session_lifetime: 172800
45
+
46
+ #downcase_username: true
@@ -0,0 +1,114 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ $LOG = Logger.new(File.basename(__FILE__).gsub('.rb','.log'))
4
+
5
+ RSpec.configure do |config|
6
+ config.include Capybara
7
+ end
8
+
9
+ VALID_USERNAME = 'spec_user'
10
+ VALID_PASSWORD = 'spec_password'
11
+
12
+ INVALID_PASSWORD = 'invalid_password'
13
+
14
+ describe 'CASServer' do
15
+
16
+ before do
17
+ @target_service = 'http://my.app.test'
18
+ end
19
+
20
+ describe "/login" do
21
+ before do
22
+ load_server(File.dirname(__FILE__) + "/default_config.yml")
23
+ reset_spec_database
24
+ end
25
+
26
+ it "logs in successfully with valid username and password without a target service" do
27
+ visit "/login"
28
+
29
+ fill_in 'username', :with => VALID_USERNAME
30
+ fill_in 'password', :with => VALID_PASSWORD
31
+ click_button 'login-submit'
32
+
33
+ page.should have_content("You have successfully logged in")
34
+ end
35
+
36
+ it "fails to log in with invalid password" do
37
+ visit "/login"
38
+ fill_in 'username', :with => VALID_USERNAME
39
+ fill_in 'password', :with => INVALID_PASSWORD
40
+ click_button 'login-submit'
41
+
42
+ page.should have_content("Incorrect username or password")
43
+ end
44
+
45
+ it "logs in successfully with valid username and password and redirects to target service" do
46
+ visit "/login?service="+CGI.escape(@target_service)
47
+
48
+ fill_in 'username', :with => VALID_USERNAME
49
+ fill_in 'password', :with => VALID_PASSWORD
50
+
51
+ click_button 'login-submit'
52
+
53
+ page.current_url.should =~ /^#{Regexp.escape(@target_service)}\/?\?ticket=ST\-[1-9rA-Z]+/
54
+ end
55
+
56
+ it "preserves target service after invalid login" do
57
+ visit "/login?service="+CGI.escape(@target_service)
58
+
59
+ fill_in 'username', :with => VALID_USERNAME
60
+ fill_in 'password', :with => INVALID_PASSWORD
61
+ click_button 'login-submit'
62
+
63
+ page.should have_content("Incorrect username or password")
64
+ page.should have_xpath('//input[@id="service"]', :value => @target_service)
65
+ end
66
+
67
+ it "uses appropriate localization when 'lang' prameter is given" do
68
+ visit "/login?lang=pl"
69
+ page.should have_content("Użytkownik")
70
+
71
+ visit "/login?lang=pt_BR"
72
+ page.should have_content("Usuário")
73
+
74
+ visit "/login?lang=en"
75
+ page.should have_content("Username")
76
+ end
77
+
78
+ end # describe '/login'
79
+
80
+
81
+ describe '/logout' do
82
+
83
+ before do
84
+ load_server(File.dirname(__FILE__) + "/default_config.yml")
85
+ reset_spec_database
86
+ end
87
+
88
+ it "logs out successfully" do
89
+ visit "/logout"
90
+
91
+ page.should have_content("You have successfully logged out")
92
+ end
93
+
94
+ it "logs out successfully and redirects to target service" do
95
+ visit "/logout?gateway=true&service="+CGI.escape(@target_service)
96
+
97
+ page.current_url.should =~ /^#{Regexp.escape(@target_service)}\/?/
98
+ end
99
+
100
+ end # describe '/logout'
101
+
102
+ describe 'Configuration' do
103
+ it "uri_path value changes prefix of routes" do
104
+ load_server(File.dirname(__FILE__) + "/alt_config.yml")
105
+ @target_service = 'http://my.app.test'
106
+
107
+ visit "/test/login"
108
+ page.status_code.should_not == 404
109
+
110
+ visit "/test/logout"
111
+ page.status_code.should_not == 404
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,46 @@
1
+ server: webrick
2
+ port: 6543
3
+ #ssl_cert: test.pem
4
+ #uri_path: /cas
5
+ #bind_address: 0.0.0.0
6
+
7
+ # database:
8
+ # adapter: mysql
9
+ # database: casserver
10
+ # username: root
11
+ # password:
12
+ # host: localhost
13
+ # reconnect: true
14
+ database:
15
+ adapter: sqlite3
16
+ database: spec/casserver_spec.db
17
+
18
+ authenticator:
19
+ class: CASServer::Authenticators::Test
20
+ password: spec_password
21
+
22
+ theme: simple
23
+
24
+ organization: "RSPEC-TEST"
25
+
26
+ infoline: "This is an rspec test."
27
+
28
+ #custom_views_file: /path/to/custom/views.rb
29
+
30
+ default_locale: en
31
+
32
+ log:
33
+ file: casserver_spec.log
34
+ level: DEBUG
35
+
36
+ #db_log:
37
+ # file: casserver_spec_db.log
38
+
39
+ enable_single_sign_out: true
40
+
41
+ #maximum_unused_login_ticket_lifetime: 300
42
+ #maximum_unused_service_ticket_lifetime: 300
43
+
44
+ #maximum_session_lifetime: 172800
45
+
46
+ #downcase_username: true
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format nested
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,89 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'rack/test'
4
+ require 'rspec'
5
+ #require 'spec/autorun'
6
+ #require 'spec/interop/test'
7
+ require 'logger'
8
+ require 'ostruct'
9
+
10
+ require 'capybara'
11
+ require 'capybara/node'
12
+ require 'capybara/dsl'
13
+
14
+ # set test environment
15
+ set :environment, :test
16
+ set :run, false
17
+ set :raise_errors, true
18
+ set :logging, false
19
+
20
+
21
+ if Dir.getwd =~ /\/spec$/
22
+ # Avoid potential weirdness by changing the working directory to the CASServer root
23
+ FileUtils.cd('..')
24
+ end
25
+
26
+ def silence_warnings
27
+ old_verbose, $VERBOSE = $VERBOSE, nil
28
+ yield
29
+ ensure
30
+ $VERBOSE = old_verbose
31
+ end
32
+
33
+ # Ugly monkeypatch to allow us to test for correct redirection to
34
+ # external services.
35
+ #
36
+ # This will likely break in the future when Capybara or RackTest are upgraded.
37
+ class Capybara::Driver::RackTest
38
+ alias_method :original_follow_redirects!, :follow_redirects!
39
+ alias_method :original_current_url, :current_url
40
+
41
+ def current_url
42
+ if @redirected_to_external_url
43
+ @redirected_to_external_url
44
+ else
45
+ original_current_url
46
+ end
47
+ end
48
+
49
+ def follow_redirects!
50
+ if response['Location'] =~ /^http:/
51
+ @redirected_to_external_url = response['Location']
52
+ else
53
+ original_follow_redirects!
54
+ end
55
+ end
56
+ end
57
+
58
+ # This called in specs' `before` block.
59
+ # Due to the way Sinatra applications are loaded,
60
+ # we're forced to delay loading of the server code
61
+ # until the start of each test so that certain
62
+ # configuraiton options can be changed (e.g. `uri_path`)
63
+ def load_server(config_file)
64
+ ENV['CONFIG_FILE'] = config_file
65
+
66
+ silence_warnings do
67
+ load File.dirname(__FILE__) + '/../lib/casserver/server.rb'
68
+ end
69
+
70
+ CASServer::Server.enable(:raise_errors)
71
+ CASServer::Server.disable(:show_exceptions)
72
+
73
+ #Capybara.current_driver = :selenium
74
+ Capybara.app = CASServer::Server
75
+ end
76
+
77
+ # Deletes the sqlite3 database specified in the app's config
78
+ # and runs the db:migrate rake tasks to rebuild the database schema.
79
+ def reset_spec_database
80
+ raise "Cannot reset the spec database because config[:database][:database] is not defined." unless
81
+ CASServer::Server.config[:database] && CASServer::Server.config[:database][:database]
82
+
83
+ FileUtils.rm_f(CASServer::Server.config[:database][:database])
84
+
85
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
86
+ ActiveRecord::Base.logger.level = Logger::ERROR
87
+ ActiveRecord::Migration.verbose = false
88
+ ActiveRecord::Migrator.migrate("db/migrate")
89
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ namespace :bundler do
3
+ Bundler::GemHelper.install_tasks(:name => 'rubycas-server')
4
+ end
@@ -0,0 +1,12 @@
1
+ namespace :db do
2
+ desc "bring your CAS server database schema up to date (options CONFIG=/path/to/config.yml)"
3
+ task :migrate do |t|
4
+ $: << File.dirname(__FILE__) + "/../../lib"
5
+
6
+ require 'casserver/server'
7
+
8
+ CASServer::Model::Base.logger = Logger.new(STDOUT)
9
+ ActiveRecord::Migration.verbose = true
10
+ ActiveRecord::Migrator.migrate("db/migrate")
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ namespace :localization do
2
+ desc 'Scans the code for translatable strings and generates/updates the .po files'
3
+ task :po do
4
+ require 'gettext/utils'
5
+ GetText.update_pofiles("rubycas-server", Dir.glob("{lib,bin}/**/*.{rb}"), "rubycas-server ")
6
+ end
7
+
8
+ desc 'Creates .mo files from .po files and puts them in the locale dir'
9
+ task :mo do
10
+ require 'gettext/utils'
11
+ GetText.create_mofiles(true, "po", "locale")
12
+ end
13
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,10 @@
1
+ #begin
2
+ require 'rspec/core/rake_task'
3
+ desc 'Run RSpecs to confirm that all functionality is working as expected'
4
+ RSpec::Core::RakeTask.new('spec') do |t|
5
+ t.rspec_opts = ['--colour', '--format nested']
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+ #rescue LoadError
9
+ # puts "Hiding spec tasks because RSpec is not available"
10
+ #end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uchouhan-rubycas-server
3
+ version: !ruby/object:Gem::Version
4
+ hash: 114
5
+ prerelease: true
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - a
10
+ version: 1.0.a
11
+ platform: ruby
12
+ authors:
13
+ - Umang Chouhan
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-04 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email:
24
+ - uchouhan@optimiscorp.com
25
+ executables:
26
+ - rubycas-server
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - CHANGELOG
31
+ - LICENSE
32
+ - README.md
33
+ files:
34
+ - CHANGELOG
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - setup.rb
39
+ - bin/rubycas-server
40
+ - bin/rubycas-server-ctl
41
+ - lib/casserver/authenticators/active_directory_ldap.rb
42
+ - lib/casserver/authenticators/authlogic_crypto_providers/aes256.rb
43
+ - lib/casserver/authenticators/authlogic_crypto_providers/bcrypt.rb
44
+ - lib/casserver/authenticators/authlogic_crypto_providers/md5.rb
45
+ - lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb
46
+ - lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
47
+ - lib/casserver/authenticators/base.rb
48
+ - lib/casserver/authenticators/client_certificate.rb
49
+ - lib/casserver/authenticators/google.rb
50
+ - lib/casserver/authenticators/ldap.rb
51
+ - lib/casserver/authenticators/ntlm.rb
52
+ - lib/casserver/authenticators/open_id.rb
53
+ - lib/casserver/authenticators/sql.rb
54
+ - lib/casserver/authenticators/sql_authlogic.rb
55
+ - lib/casserver/authenticators/sql_encrypted.rb
56
+ - lib/casserver/authenticators/sql_md5.rb
57
+ - lib/casserver/authenticators/sql_rest_auth.rb
58
+ - lib/casserver/authenticators/tacc.rb
59
+ - lib/casserver/authenticators/test.rb
60
+ - lib/casserver/cas.rb
61
+ - lib/casserver/localization.rb
62
+ - lib/casserver/model.rb
63
+ - lib/casserver/server.rb
64
+ - lib/casserver/utils.rb
65
+ - lib/casserver.rb
66
+ - public/themes/cas.css
67
+ - public/themes/notice.png
68
+ - public/themes/ok.png
69
+ - public/themes/simple/bg.png
70
+ - public/themes/simple/favicon.png
71
+ - public/themes/simple/login_box_bg.png
72
+ - public/themes/simple/logo.png
73
+ - public/themes/simple/theme.css
74
+ - public/themes/tadnet/bg.png
75
+ - public/themes/tadnet/button.png
76
+ - public/themes/tadnet/favicon.png
77
+ - public/themes/tadnet/login_box_bg.png
78
+ - public/themes/tadnet/logo.png
79
+ - public/themes/tadnet/theme.css
80
+ - public/themes/urbacon/bg.png
81
+ - public/themes/urbacon/login_box_bg.png
82
+ - public/themes/urbacon/logo.png
83
+ - public/themes/urbacon/theme.css
84
+ - public/themes/warning.png
85
+ - po/de_DE/rubycas-server.po
86
+ - po/es_ES/rubycas-server.po
87
+ - po/fr_FR/rubycas-server.po
88
+ - po/ja_JP/rubycas-server.po
89
+ - po/pl_PL/rubycas-server.po
90
+ - po/pt_BR/rubycas-server.po
91
+ - po/ru_RU/rubycas-server.po
92
+ - po/rubycas-server.pot
93
+ - po/zh_CN/rubycas-server.po
94
+ - po/zh_TW/rubycas-server.po
95
+ - resources/config.example.yml
96
+ - resources/config.ru
97
+ - resources/custom_views.example.rb
98
+ - resources/init.d.sh
99
+ - tasks/bundler.rake
100
+ - tasks/db/migrate.rake
101
+ - tasks/localization.rake
102
+ - tasks/spec.rake
103
+ - lib/casserver/views/_login_form.erb
104
+ - lib/casserver/views/layout.erb
105
+ - lib/casserver/views/login.erb
106
+ - lib/casserver/views/validate.erb
107
+ - lib/casserver/views/proxy.builder
108
+ - lib/casserver/views/proxy_validate.builder
109
+ - lib/casserver/views/service_validate.builder
110
+ - rubycas-server.gemspec
111
+ - spec/alt_config.yml
112
+ - spec/casserver_spec.rb
113
+ - spec/default_config.yml
114
+ - spec/spec.opts
115
+ - spec/spec_helper.rb
116
+ has_rdoc: true
117
+ homepage: http://github.com/uchouhan/cas
118
+ licenses: []
119
+
120
+ post_install_message: |+
121
+
122
+ For more information on RubyCAS-Server, see http://code.google.com/p/rubycas-server
123
+
124
+ If you plan on using RubyCAS-Server with languages other than English, please cd into the
125
+ RubyCAS-Server installation directory (where the gem is installed) and type `rake localization:mo`
126
+ to build the LOCALE_LC files.
127
+
128
+ rdoc_options:
129
+ - --quiet
130
+ - --title
131
+ - RubyCAS-Server Documentation
132
+ - --opname
133
+ - index.html
134
+ - --line-numbers
135
+ - --main
136
+ - README.md
137
+ - --inline-source
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">"
153
+ - !ruby/object:Gem::Version
154
+ hash: 25
155
+ segments:
156
+ - 1
157
+ - 3
158
+ - 1
159
+ version: 1.3.1
160
+ requirements: []
161
+
162
+ rubyforge_project:
163
+ rubygems_version: 1.3.7
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Provides single sign-on authentication for web applications using the CAS protocol.
167
+ test_files:
168
+ - spec/alt_config.yml
169
+ - spec/casserver_spec.rb
170
+ - spec/default_config.yml
171
+ - spec/spec.opts
172
+ - spec/spec_helper.rb