gunark-rubycas-server 0.6.99.336 → 0.7.999.20090212
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +26 -5
- data/Manifest.txt +20 -10
- data/README.txt +3 -2
- data/bin/rubycas-server +5 -4
- data/bin/rubycas-server-ctl +3 -2
- data/config/hoe.rb +9 -8
- data/config.example.yml +43 -12
- data/config.ru +21 -0
- data/lib/casserver/authenticators/google.rb +54 -0
- data/lib/casserver/authenticators/sql_rest_auth.rb +77 -0
- data/lib/casserver/cas.rb +40 -27
- data/lib/casserver/conf.rb +61 -96
- data/lib/casserver/controllers.rb +38 -31
- data/lib/casserver/environment.rb +16 -11
- data/lib/casserver/localization.rb +62 -0
- data/lib/casserver/models.rb +2 -2
- data/lib/casserver/postambles.rb +12 -12
- data/lib/casserver/version.rb +2 -2
- data/lib/casserver/views.rb +12 -12
- data/lib/casserver.rb +41 -97
- data/lib/rubycas-server.rb +1 -1
- data/po/de_DE/rubycas-server.po +91 -0
- data/po/es_ES/rubycas-server.po +90 -0
- data/po/fr_FR/rubycas-server.po +90 -0
- data/po/ja_JP/rubycas-server.po +92 -0
- data/po/pl_PL/rubycas-server.po +93 -0
- data/po/ru_RU/rubycas-server.po +91 -0
- data/po/rubycas-server.pot +82 -0
- data/resources/init.d.sh +1 -1
- data/tasks/localization.rake +11 -0
- metadata +60 -15
- data/misc/basic_cas_single_signon_mechanism_diagram.png +0 -0
- data/misc/basic_cas_single_signon_mechanism_diagram.svg +0 -652
- data/website/index.html +0 -40
- data/website/index.txt +0 -3
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -138
- data/website/template.html.erb +0 -40
data/lib/casserver/conf.rb
CHANGED
@@ -1,112 +1,77 @@
|
|
1
|
-
# load configuration
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
2
|
+
conf_defaults = {
|
3
|
+
:expire_sessions => false,
|
4
|
+
:login_ticket_expiry => 5.minutes,
|
5
|
+
:service_ticket_expiry => 5.minutes, # CAS Protocol Spec, sec. 3.2.1 (recommended expiry time)
|
6
|
+
:proxy_granting_ticket_expiry => 48.hours,
|
7
|
+
:ticket_granting_ticket_expiry => 48.hours,
|
8
|
+
:log => {:file => 'casserver.log', :level => 'DEBUG'},
|
9
|
+
:uri_path => "/"
|
10
|
+
}
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
puts "\nAttempting to copy sample configuration from '#{example_conf_file}' to '#{etc_conf}'...\n"
|
20
|
-
|
21
|
-
begin
|
22
|
-
FileUtils.mkdir("/etc/rubycas-server") unless File.exists? "/etc/rubycas-server"
|
23
|
-
FileUtils.cp(example_conf_file, etc_conf)
|
24
|
-
rescue Errno::EACCES
|
25
|
-
puts "\nIt appears that you do not have permissions to create the '#{etc_conf}' file. Try running this command using sudo (as root).\n"
|
26
|
-
exit 2
|
27
|
-
rescue
|
28
|
-
puts "\nFor some reason the '#{etc_conf}' file could not be created. You'll have to copy the file manually." +
|
29
|
-
" Use '#{example_conf_file}' as a template.\n"
|
30
|
-
exit 2
|
31
|
-
end
|
32
|
-
|
33
|
-
puts "\nA sample configuration has been created for you in '#{etc_conf}'. Please edit this file to" +
|
34
|
-
" suit your needs and then run rubycas-server again.\n"
|
35
|
-
exit 1
|
12
|
+
if $CONF
|
13
|
+
$CONF.merge_defaults(conf_defaults)
|
14
|
+
else
|
15
|
+
unless $APP_NAME && $APP_ROOT
|
16
|
+
raise "Can't load the RubyCAS-Server configuration because $APP_NAME and/or $APP_ROOT are not defined."
|
36
17
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
18
|
+
|
19
|
+
require 'picnic/conf'
|
20
|
+
$CONF = Picnic::Conf.new(conf_defaults)
|
21
|
+
$CONF.load_from_file($APP_NAME, $APP_ROOT)
|
22
|
+
end
|
23
|
+
|
24
|
+
$AUTH = []
|
25
|
+
begin
|
26
|
+
# attempt to instantiate the authenticator
|
27
|
+
if $CONF[:authenticator].instance_of? Array
|
28
|
+
$CONF[:authenticator].each { |authenticator| $AUTH << authenticator[:class].constantize.new}
|
42
29
|
else
|
43
|
-
$
|
30
|
+
$AUTH << $CONF[:authenticator][:class].constantize.new
|
44
31
|
end
|
45
|
-
|
32
|
+
rescue NameError
|
46
33
|
if $CONF[:authenticator].instance_of? Array
|
47
|
-
$CONF[:authenticator].
|
48
|
-
|
49
|
-
|
50
|
-
$AUTH = []
|
51
|
-
begin
|
52
|
-
# attempt to instantiate the authenticator
|
53
|
-
if $CONF[:authenticator].instance_of? Array
|
54
|
-
$CONF[:authenticator].each { |authenticator| $AUTH << authenticator[:class].constantize.new}
|
55
|
-
else
|
56
|
-
$AUTH << $CONF[:authenticator][:class].constantize.new
|
57
|
-
end
|
58
|
-
rescue NameError
|
59
|
-
if $CONF[:authenticator].instance_of? Array
|
60
|
-
$CONF[:authenticator].each do |authenticator|
|
61
|
-
if !authenticator[:source].nil?
|
62
|
-
# config.yml explicitly names source file
|
63
|
-
require authenticator[:source]
|
64
|
-
else
|
65
|
-
# the authenticator class hasn't yet been loaded, so lets try to load it from the casserver/authenticators directory
|
66
|
-
auth_rb = authenticator[:class].underscore.gsub('cas_server/', '')
|
67
|
-
require 'casserver/'+auth_rb
|
68
|
-
end
|
69
|
-
$AUTH << authenticator[:class].constantize.new
|
70
|
-
end
|
71
|
-
else
|
72
|
-
if !$CONF[:authenticator][:source].nil?
|
34
|
+
$CONF[:authenticator].each do |authenticator|
|
35
|
+
if !authenticator[:source].nil?
|
73
36
|
# config.yml explicitly names source file
|
74
|
-
require
|
37
|
+
require authenticator[:source]
|
75
38
|
else
|
76
39
|
# the authenticator class hasn't yet been loaded, so lets try to load it from the casserver/authenticators directory
|
77
|
-
auth_rb =
|
40
|
+
auth_rb = authenticator[:class].underscore.gsub('cas_server/', '')
|
78
41
|
require 'casserver/'+auth_rb
|
79
42
|
end
|
80
|
-
|
81
|
-
$AUTH << $CONF[:authenticator][:class].constantize.new
|
43
|
+
$AUTH << authenticator[:class].constantize.new
|
82
44
|
end
|
45
|
+
else
|
46
|
+
if $CONF[:authenticator][:source]
|
47
|
+
# config.yml explicitly names source file
|
48
|
+
require $CONF[:authenticator][:source]
|
49
|
+
else
|
50
|
+
# the authenticator class hasn't yet been loaded, so lets try to load it from the casserver/authenticators directory
|
51
|
+
auth_rb = $CONF[:authenticator][:class].underscore.gsub('cas_server/', '')
|
52
|
+
require 'casserver/'+auth_rb
|
53
|
+
end
|
54
|
+
|
55
|
+
$AUTH << $CONF[:authenticator][:class].constantize.new
|
83
56
|
end
|
84
|
-
rescue
|
85
|
-
raise "Your RubyCAS-Server configuration may be invalid."+
|
86
|
-
" Please double-check check your config.yml file."+
|
87
|
-
" Make sure that you are using spaces instead of tabs for your indentation!!" +
|
88
|
-
"\n\nUNDERLYING EXCEPTION:\n#{$!}"
|
89
57
|
end
|
90
58
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
def [](key)
|
104
|
-
$CONF[key] || DEFAULTS[key]
|
105
|
-
end
|
106
|
-
module_function "[]".intern
|
107
|
-
|
108
|
-
def self.method_missing(method, *args)
|
109
|
-
self[method]
|
110
|
-
end
|
111
|
-
end
|
59
|
+
unless $CONF[:authenticator]
|
60
|
+
$stderr.puts
|
61
|
+
$stderr.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
62
|
+
$stderr.puts
|
63
|
+
$stderr.puts "You have not yet defined an authenticator for your CAS server!"
|
64
|
+
$stderr.puts "Please consult your config file for details (most likely in"
|
65
|
+
$stderr.puts "/etc/rubycas-server/config.yml)."
|
66
|
+
$stderr.puts
|
67
|
+
$stderr.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
68
|
+
exit 1
|
112
69
|
end
|
70
|
+
|
71
|
+
|
72
|
+
$CONF[:public_dir] = {
|
73
|
+
:path => "/themes",
|
74
|
+
:dir => File.expand_path(File.dirname(__FILE__))+"/themes"
|
75
|
+
}
|
76
|
+
|
77
|
+
|
@@ -1,12 +1,14 @@
|
|
1
1
|
# The #.#.# comments (e.g. "2.1.3") refer to section numbers in the CAS protocol spec
|
2
2
|
# under http://www.ja-sig.org/products/cas/overview/protocol/index.html
|
3
3
|
|
4
|
+
require 'casserver/cas'
|
5
|
+
|
4
6
|
module CASServer::Controllers
|
5
7
|
|
6
8
|
# 2.1
|
7
9
|
class Login < R '/', '/login'
|
8
10
|
include CASServer::CAS
|
9
|
-
|
11
|
+
|
10
12
|
# 2.1.1
|
11
13
|
def get
|
12
14
|
CASServer::Utils::log_controller_action(self.class, @input)
|
@@ -27,12 +29,12 @@ module CASServer::Controllers
|
|
27
29
|
|
28
30
|
if tgt and !tgt_error
|
29
31
|
@message = {:type => 'notice',
|
30
|
-
:message =>
|
32
|
+
:message => _("You are currently logged in as '%s'. If this is not you, please log in below.") % tgt.username }
|
31
33
|
end
|
32
34
|
|
33
35
|
if @input['redirection_loop_intercepted']
|
34
36
|
@message = {:type => 'mistake',
|
35
|
-
:message =>
|
37
|
+
:message => _("The client and server are unable to negotiate authentication. Please try logging in again later.")}
|
36
38
|
end
|
37
39
|
|
38
40
|
begin
|
@@ -49,12 +51,12 @@ module CASServer::Controllers
|
|
49
51
|
elsif @gateway
|
50
52
|
$LOG.error("This is a gateway request but no service parameter was given!")
|
51
53
|
@message = {:type => 'mistake',
|
52
|
-
:message => "The server cannot fulfill this gateway request because no service parameter was given."}
|
54
|
+
:message => _("The server cannot fulfill this gateway request because no service parameter was given.")}
|
53
55
|
end
|
54
56
|
rescue URI::InvalidURIError
|
55
57
|
$LOG.error("The service '#{@service}' is not a valid URI!")
|
56
58
|
@message = {:type => 'mistake',
|
57
|
-
:message => "The target service your browser supplied appears to be invalid. Please contact your system administrator for help."}
|
59
|
+
:message => _("The target service your browser supplied appears to be invalid. Please contact your system administrator for help.")}
|
58
60
|
end
|
59
61
|
|
60
62
|
lt = generate_login_ticket
|
@@ -71,8 +73,8 @@ module CASServer::Controllers
|
|
71
73
|
# The optional 'submitToURI' parameter can be given to explicitly set the
|
72
74
|
# action for the form, otherwise the server will try to guess this for you.
|
73
75
|
if @input.has_key? 'onlyLoginForm'
|
74
|
-
if env['HTTP_HOST']
|
75
|
-
guessed_login_uri = "http#{env['HTTPS'] && env['HTTPS'] == 'on' ? 's' : ''}://#{env['REQUEST_URI']}#{self / '/login'}"
|
76
|
+
if @env['HTTP_HOST']
|
77
|
+
guessed_login_uri = "http#{@env['HTTPS'] && @env['HTTPS'] == 'on' ? 's' : ''}://#{@env['REQUEST_URI']}#{self / '/login'}"
|
76
78
|
else
|
77
79
|
guessed_login_uri = nil
|
78
80
|
end
|
@@ -83,7 +85,7 @@ module CASServer::Controllers
|
|
83
85
|
render :login_form
|
84
86
|
else
|
85
87
|
@status = 500
|
86
|
-
"Could not guess the CAS login URI. Please supply a submitToURI parameter with your request."
|
88
|
+
_("Could not guess the CAS login URI. Please supply a submitToURI parameter with your request.")
|
87
89
|
end
|
88
90
|
else
|
89
91
|
render :login
|
@@ -122,9 +124,9 @@ module CASServer::Controllers
|
|
122
124
|
@lt = generate_login_ticket.ticket
|
123
125
|
|
124
126
|
if $CONF[:authenticator].instance_of? Array
|
125
|
-
$AUTH.each_index {|auth_index| $AUTH[auth_index].configure(
|
127
|
+
$AUTH.each_index {|auth_index| $AUTH[auth_index].configure($CONF.authenticator[auth_index])}
|
126
128
|
else
|
127
|
-
$AUTH[0].configure(
|
129
|
+
$AUTH[0].configure($CONF.authenticator)
|
128
130
|
end
|
129
131
|
|
130
132
|
$LOG.debug("Logging in with username: #{@username}, lt: #{@lt}, service: #{@service}, auth: #{$AUTH}")
|
@@ -138,7 +140,7 @@ module CASServer::Controllers
|
|
138
140
|
:username => @username,
|
139
141
|
:password => @password,
|
140
142
|
:service => @service,
|
141
|
-
:request => env
|
143
|
+
:request => @env
|
142
144
|
)
|
143
145
|
if credentials_are_valid
|
144
146
|
extra_attributes.merge!(auth.extra_attributes) unless auth.extra_attributes.blank?
|
@@ -159,17 +161,17 @@ module CASServer::Controllers
|
|
159
161
|
# 3.6 (ticket-granting cookie)
|
160
162
|
tgt = generate_ticket_granting_ticket(@username, extra_attributes)
|
161
163
|
|
162
|
-
if
|
163
|
-
expires =
|
164
|
+
if $CONF.expire_sessions
|
165
|
+
expires = $CONF.ticket_granting_ticket_expiry.to_i.from_now
|
164
166
|
expiry_info = " It will expire on #{expires}."
|
165
167
|
else
|
166
168
|
expiry_info = " It will not expire."
|
167
169
|
end
|
168
170
|
|
169
|
-
if
|
171
|
+
if $CONF.expire_sessions
|
170
172
|
@cookies[:tgt] = {
|
171
173
|
:value => tgt.to_s,
|
172
|
-
:expires => Time.now +
|
174
|
+
:expires => Time.now + $CONF.ticket_granting_ticket_expiry
|
173
175
|
}
|
174
176
|
else
|
175
177
|
@cookies[:tgt] = tgt.to_s
|
@@ -179,7 +181,7 @@ module CASServer::Controllers
|
|
179
181
|
|
180
182
|
if @service.blank?
|
181
183
|
$LOG.info("Successfully authenticated user '#{@username}' at '#{tgt.client_hostname}'. No service param was given, so we will not redirect.")
|
182
|
-
@message = {:type => 'confirmation', :message => "You have successfully logged in."}
|
184
|
+
@message = {:type => 'confirmation', :message => _("You have successfully logged in.")}
|
183
185
|
else
|
184
186
|
@st = generate_service_ticket(@service, @username, tgt)
|
185
187
|
begin
|
@@ -189,12 +191,13 @@ module CASServer::Controllers
|
|
189
191
|
return redirect(service_with_ticket, :status => 303) # response code 303 means "See Other" (see Appendix B in CAS Protocol spec)
|
190
192
|
rescue URI::InvalidURIError
|
191
193
|
$LOG.error("The service '#{@service}' is not a valid URI!")
|
192
|
-
@message = {:type => 'mistake',
|
194
|
+
@message = {:type => 'mistake',
|
195
|
+
:message => _("The target service your browser supplied appears to be invalid. Please contact your system administrator for help.")}
|
193
196
|
end
|
194
197
|
end
|
195
198
|
else
|
196
199
|
$LOG.warn("Invalid credentials given for user '#{@username}'")
|
197
|
-
@message = {:type => 'mistake', :message => "Incorrect username or password."}
|
200
|
+
@message = {:type => 'mistake', :message => _("Incorrect username or password.")}
|
198
201
|
@status = 401
|
199
202
|
end
|
200
203
|
|
@@ -233,18 +236,18 @@ module CASServer::Controllers
|
|
233
236
|
pgt.destroy
|
234
237
|
end
|
235
238
|
|
236
|
-
if
|
239
|
+
if $CONF.enable_single_sign_out
|
237
240
|
$LOG.debug("Deleting Service/Proxy Tickets for '#{tgt}' for user '#{tgt.username}'")
|
238
241
|
tgt.service_tickets.each do |st|
|
239
242
|
send_logout_notification_for_service_ticket(st)
|
240
243
|
# TODO: Maybe we should do some special handling if send_logout_notification_for_service_ticket fails?
|
241
|
-
#
|
242
|
-
$LOG.debug "Deleting #{st.class} #{st.ticket.inspect}."
|
244
|
+
# (the above method returns false if the POST results in a non-200 HTTP response).
|
245
|
+
$LOG.debug "Deleting #{st.class.name.demodulize} #{st.ticket.inspect}."
|
243
246
|
st.destroy
|
244
247
|
end
|
245
248
|
end
|
246
249
|
|
247
|
-
$LOG.debug("Deleting
|
250
|
+
$LOG.debug("Deleting #{tgt.class.name.demodulize} '#{tgt}' for user '#{tgt.username}'")
|
248
251
|
tgt.destroy
|
249
252
|
end
|
250
253
|
|
@@ -253,10 +256,10 @@ module CASServer::Controllers
|
|
253
256
|
$LOG.warn("User tried to log out without a valid ticket-granting ticket.")
|
254
257
|
end
|
255
258
|
|
256
|
-
@message = {:type => 'confirmation', :message => "You have successfully logged out."}
|
259
|
+
@message = {:type => 'confirmation', :message => _("You have successfully logged out.")}
|
257
260
|
|
258
261
|
@message[:message] <<
|
259
|
-
" Please click on the following link to continue:" if @continue_url
|
262
|
+
_(" Please click on the following link to continue:") if @continue_url
|
260
263
|
|
261
264
|
@lt = generate_login_ticket
|
262
265
|
|
@@ -363,7 +366,7 @@ module CASServer::Controllers
|
|
363
366
|
|
364
367
|
@extra_attributes = t.ticket_granting_ticket.extra_attributes || {}
|
365
368
|
end
|
366
|
-
|
369
|
+
|
367
370
|
@status = response_status_from_error(@error) if @error
|
368
371
|
|
369
372
|
render :proxy_validate
|
@@ -406,7 +409,7 @@ module CASServer::Controllers
|
|
406
409
|
CASServer::Utils::log_controller_action(self.class, @input)
|
407
410
|
$LOG.error("Tried to use login ticket dispenser with get method!")
|
408
411
|
@status = 422
|
409
|
-
"To generate a login ticket, you must make a POST request."
|
412
|
+
_("To generate a login ticket, you must make a POST request.")
|
410
413
|
end
|
411
414
|
|
412
415
|
# Renders a page with a login ticket (and only the login ticket)
|
@@ -415,7 +418,7 @@ module CASServer::Controllers
|
|
415
418
|
CASServer::Utils::log_controller_action(self.class, @input)
|
416
419
|
lt = generate_login_ticket
|
417
420
|
|
418
|
-
$LOG.debug("Dispensing login ticket #{lt} to host #{(env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_HOST'] || env['REMOTE_ADDR']).inspect}")
|
421
|
+
$LOG.debug("Dispensing login ticket #{lt} to host #{(@env['HTTP_X_FORWARDED_FOR'] || @env['REMOTE_HOST'] || @env['REMOTE_ADDR']).inspect}")
|
419
422
|
|
420
423
|
@lt = lt.ticket
|
421
424
|
|
@@ -426,13 +429,17 @@ module CASServer::Controllers
|
|
426
429
|
class Themes < R '/themes/(.+)'
|
427
430
|
MIME_TYPES = {'.css' => 'text/css', '.js' => 'text/javascript',
|
428
431
|
'.jpg' => 'image/jpeg'}
|
429
|
-
PATH =
|
432
|
+
PATH = $CONF.themes_dir || File.expand_path(File.dirname(__FILE__))+'/../themes'
|
430
433
|
|
431
|
-
def get(path)
|
434
|
+
def get(path)
|
435
|
+
headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || "text/plain"
|
432
436
|
unless path.include? ".." # prevent directory traversal attacks
|
433
|
-
|
437
|
+
headers['X-Sendfile'] = "#{PATH}/#{path}"
|
438
|
+
data = File.read(headers['X-Sendfile'])
|
439
|
+
headers['Content-Length'] = data.size.to_s # Rack Camping adapter chokes without this
|
440
|
+
return data
|
434
441
|
else
|
435
|
-
|
442
|
+
status = "403"
|
436
443
|
"403 - Invalid path"
|
437
444
|
end
|
438
445
|
end
|
@@ -1,26 +1,31 @@
|
|
1
1
|
$: << File.dirname(File.expand_path(__FILE__))
|
2
2
|
|
3
3
|
# Try to load local version of Picnic if possible (for development purposes)
|
4
|
-
|
5
|
-
|
4
|
+
alt_picic_paths = []
|
5
|
+
alt_picic_paths << File.dirname(File.expand_path(__FILE__))+"/../../../picnic/lib"
|
6
|
+
alt_picic_paths << File.dirname(File.expand_path(__FILE__))+"/../../vendor/picnic/lib"
|
6
7
|
|
7
8
|
begin
|
9
|
+
require 'active_record'
|
10
|
+
rescue LoadError
|
11
|
+
require 'rubygems'
|
12
|
+
require 'active_record'
|
13
|
+
end
|
14
|
+
|
15
|
+
if alt_picic_paths.any?{|path| File.exists? "#{path}/picnic.rb" }
|
16
|
+
alt_picic_paths.each{|path| $: << path}
|
8
17
|
require 'picnic'
|
9
|
-
|
10
|
-
# make sure that the LoadError was about picnic and not something else
|
11
|
-
raise e unless e.to_s =~ /picnic/
|
12
|
-
|
18
|
+
else
|
13
19
|
require 'rubygems'
|
14
20
|
|
15
21
|
# make things backwards-compatible for rubygems < 0.9.0
|
16
|
-
|
22
|
+
if respond_to?(:require_gem)
|
23
|
+
puts "WARNING: aliasing gem to require_gem in #{__FILE__} -- you should update your RubyGems system!"
|
17
24
|
alias gem require_gem
|
18
25
|
end
|
19
|
-
|
20
|
-
gem 'picnic'
|
21
|
-
|
26
|
+
|
22
27
|
require 'picnic'
|
23
28
|
end
|
24
29
|
|
25
30
|
# used for serializing user extra_attributes (see #service_validate in views.rb)
|
26
|
-
require 'yaml'
|
31
|
+
require 'yaml'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "gettext"
|
2
|
+
require "gettext/cgi"
|
3
|
+
|
4
|
+
module CASServer
|
5
|
+
include GetText
|
6
|
+
bindtextdomain("rubycas-server", :path => File.join(File.dirname(File.expand_path(__FILE__)), "../locale"))
|
7
|
+
|
8
|
+
def service(*a)
|
9
|
+
GetText.locale = determine_locale
|
10
|
+
#puts GetText.locale.inspect
|
11
|
+
super(*a)
|
12
|
+
end
|
13
|
+
|
14
|
+
def determine_locale
|
15
|
+
lang = ($CONF[:default_locale] || "en")
|
16
|
+
lang = @input['lang'] unless @input['lang'].blank?
|
17
|
+
lang ||= @cookies['lang'] unless @cookies['lang'].blank?
|
18
|
+
lang ||= @env.HTTP_ACCEPT_LANGUAGE unless @env.HTTP_ACCEPT_LANGUAGE.blank?
|
19
|
+
lang ||= @env.HTTP_USER_AGENT =~ /[^a-z]([a-z]{2}(-[a-z]{2})?)[^a-z]/i &&
|
20
|
+
lang = $~[1] unless @env.HTTP_USER_AGENT.blank?
|
21
|
+
@cookies['lang'] = lang
|
22
|
+
|
23
|
+
lang.gsub!('_','-')
|
24
|
+
|
25
|
+
# TODO: Need to confirm that this method of splitting the accepted
|
26
|
+
# language string is correct.
|
27
|
+
if lang =~ /[,;\|]/
|
28
|
+
langs = lang.split(/[,;\|]/)
|
29
|
+
else
|
30
|
+
langs = [lang]
|
31
|
+
end
|
32
|
+
|
33
|
+
# TODO: This method of selecting the desired language might not be
|
34
|
+
# standards-compliant. For example, http://www.w3.org/TR/ltli/
|
35
|
+
# suggests that de-de and de-*-DE might be acceptable identifiers
|
36
|
+
# for selecting various wildcards. The algorithm below does not
|
37
|
+
# currently support anything like this.
|
38
|
+
|
39
|
+
available = available_locales
|
40
|
+
|
41
|
+
# Try to pick a locale exactly matching the desired identifier, otherwise
|
42
|
+
# fall back to locale without region (i.e. given "en-US; de-DE", we would
|
43
|
+
# first look for "en-US", then "en", then "de-DE", then "de").
|
44
|
+
|
45
|
+
chosen_lang = nil
|
46
|
+
langs.each do |l|
|
47
|
+
a = available.find{|a| a == l || a =~ Regexp.new("#{l}-\w*")}
|
48
|
+
if a
|
49
|
+
chosen_lang = a
|
50
|
+
break
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
chosen_lang = "en" if chosen_lang.blank?
|
55
|
+
|
56
|
+
return chosen_lang
|
57
|
+
end
|
58
|
+
|
59
|
+
def available_locales
|
60
|
+
(Dir.glob(File.join(File.dirname(File.expand_path(__FILE__)), "../locale/[a-z]*")).map{|path| File.basename(path)} << "en").uniq.collect{|l| l.gsub('_','-')}
|
61
|
+
end
|
62
|
+
end
|
data/lib/casserver/models.rb
CHANGED
data/lib/casserver/postambles.rb
CHANGED
@@ -9,11 +9,11 @@ module CASServer
|
|
9
9
|
# TODO: verify the certificate's validity
|
10
10
|
# example of how to do this is here: http://pablotron.org/download/ruri-20050331.rb
|
11
11
|
|
12
|
-
cert_path =
|
13
|
-
key_path =
|
12
|
+
cert_path = $CONF.ssl_cert
|
13
|
+
key_path = $CONF.ssl_key || $CONF.ssl_cert
|
14
14
|
# look for the key in the ssl_cert if no ssl_key is specified
|
15
15
|
|
16
|
-
webrick_options = {:BindAddress => "0.0.0.0", :Port =>
|
16
|
+
webrick_options = {:BindAddress => "0.0.0.0", :Port => $CONF.port}
|
17
17
|
|
18
18
|
unless cert_path.nil? && key_path.nil?
|
19
19
|
raise "'#{cert_path}' is not a valid ssl certificate. Your 'ssl_cert' configuration" +
|
@@ -41,9 +41,9 @@ module CASServer
|
|
41
41
|
end
|
42
42
|
|
43
43
|
CASServer.create
|
44
|
-
s.mount "#{
|
44
|
+
s.mount "#{$CONF.uri_path}", WEBrick::CampingHandler, CASServer
|
45
45
|
|
46
|
-
puts "\n** CASServer is running at http#{webrick_options[:SSLEnable] ? 's' : ''}://#{Socket.gethostname}:#{
|
46
|
+
puts "\n** CASServer is running at http#{webrick_options[:SSLEnable] ? 's' : ''}://#{Socket.gethostname}:#{$CONF.port}#{$CONF.uri_path} and logging to '#{$CONF.log[:file]}'\n\n"
|
47
47
|
|
48
48
|
# This lets Ctrl+C shut down your server
|
49
49
|
trap(:INT) do
|
@@ -79,19 +79,19 @@ module CASServer
|
|
79
79
|
|
80
80
|
CASServer.create
|
81
81
|
|
82
|
-
puts "\n** CASServer is starting. Look in '#{
|
82
|
+
puts "\n** CASServer is starting. Look in '#{$CONF.log[:file]}' for further notices."
|
83
83
|
|
84
|
-
settings = {:host => "0.0.0.0", :log_file =>
|
84
|
+
settings = {:host => "0.0.0.0", :log_file => $CONF.log[:file], :cwd => $CASSERVER_HOME}
|
85
85
|
|
86
86
|
# need to close all IOs before daemonizing
|
87
87
|
$LOG.close if $DAEMONIZE
|
88
88
|
|
89
89
|
begin
|
90
90
|
config = Mongrel::Configurator.new settings do
|
91
|
-
daemonize :log_file =>
|
91
|
+
daemonize :log_file => $CONF.log[:file], :cwd => $CASSERVER_HOME if $DAEMONIZE
|
92
92
|
|
93
|
-
listener :port =>
|
94
|
-
uri
|
93
|
+
listener :port => $CONF.port do
|
94
|
+
uri $CONF.uri_path, :handler => Mongrel::Camping::CampingHandler.new(CASServer)
|
95
95
|
setup_signals
|
96
96
|
end
|
97
97
|
end
|
@@ -112,7 +112,7 @@ module CASServer
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
puts "\n** CASServer is running at http://localhost:#{
|
115
|
+
puts "\n** CASServer is running at http://localhost:#{$CONF.port}#{$CONF.uri_path} and logging to '#{$CONF.log[:file]}'"
|
116
116
|
config.join
|
117
117
|
|
118
118
|
clear_pid_file
|
@@ -137,7 +137,7 @@ module CASServer
|
|
137
137
|
|
138
138
|
private
|
139
139
|
def check_log_writable
|
140
|
-
log_file =
|
140
|
+
log_file = $CONF.log['file']
|
141
141
|
begin
|
142
142
|
f = open(log_file, 'w')
|
143
143
|
rescue
|