gunark-rubycas-server 0.8.0.20090506 → 0.8.0.20090715
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/Manifest.txt +2 -1
- data/config/hoe.rb +1 -0
- data/config.example.yml +12 -15
- data/config.ru +9 -0
- data/lib/casserver/authenticators/sql_encrypted.rb +3 -2
- data/lib/casserver/authenticators/test.rb +1 -1
- data/lib/casserver/cas.rb +29 -28
- data/lib/casserver/conf.rb +3 -6
- data/lib/casserver/controllers.rb +20 -23
- data/lib/casserver/localization.rb +28 -8
- data/lib/casserver/models.rb +49 -7
- data/lib/casserver.rb +25 -6
- data/po/de_DE/rubycas-server.po +49 -21
- data/po/es_ES/rubycas-server.po +40 -15
- data/po/fr_FR/rubycas-server.po +43 -17
- data/po/ja_JP/rubycas-server.po +41 -15
- data/po/pl_PL/rubycas-server.po +31 -9
- data/po/pt_BR/rubycas-server.po +44 -17
- data/po/ru_RU/rubycas-server.po +30 -8
- data/po/rubycas-server.pot +33 -11
- metadata +1 -1
data/Manifest.txt
CHANGED
@@ -42,6 +42,7 @@ locale/es_ES/LC_MESSAGES/rubycas-server.mo
|
|
42
42
|
locale/fr_FR/LC_MESSAGES/rubycas-server.mo
|
43
43
|
locale/ja_JP/LC_MESSAGES/rubycas-server.mo
|
44
44
|
locale/pl_PL/LC_MESSAGES/rubycas-server.mo
|
45
|
+
locale/pt_BR/LC_MESSAGES/rubycas-server.mo
|
45
46
|
locale/ru_RU/LC_MESSAGES/rubycas-server.mo
|
46
47
|
po/de_DE/rubycas-server.po
|
47
48
|
po/es_ES/rubycas-server.po
|
@@ -51,11 +52,11 @@ po/pl_PL/rubycas-server.po
|
|
51
52
|
po/pt_BR/rubycas-server.po
|
52
53
|
po/ru_RU/rubycas-server.po
|
53
54
|
po/rubycas-server.pot
|
54
|
-
public/test
|
55
55
|
public/themes/cas.css
|
56
56
|
public/themes/notice.png
|
57
57
|
public/themes/ok.png
|
58
58
|
public/themes/simple/bg.png
|
59
|
+
public/themes/simple/favicon.png
|
59
60
|
public/themes/simple/login_box_bg.png
|
60
61
|
public/themes/simple/logo.png
|
61
62
|
public/themes/simple/theme.css
|
data/config/hoe.rb
CHANGED
data/config.example.yml
CHANGED
@@ -66,7 +66,7 @@ ssl_cert: /path/to/your/ssl.pem
|
|
66
66
|
# binaries will be downloaded and installed, so don't worry about this).
|
67
67
|
|
68
68
|
#server: mongrel
|
69
|
-
#port:
|
69
|
+
#port: 11011
|
70
70
|
|
71
71
|
|
72
72
|
# Bind the server to a specific address. Use 0.0.0.0 to listen on all
|
@@ -518,24 +518,21 @@ log:
|
|
518
518
|
|
519
519
|
# You can set various ticket expiry times (specify the value in seconds).
|
520
520
|
|
521
|
-
#
|
521
|
+
# Unused login and service tickets become unusable this many seconds after
|
522
522
|
# they are created. (Defaults to 5 minutes)
|
523
523
|
|
524
|
-
#
|
525
|
-
#
|
524
|
+
#maximum_unused_login_ticket_lifetime: 300
|
525
|
+
#maximum_unused_service_ticket_lifetime: 300
|
526
526
|
|
527
|
-
#
|
528
|
-
#
|
529
|
-
#
|
530
|
-
#
|
531
|
-
|
532
|
-
#
|
533
|
-
#
|
534
|
-
|
535
|
-
# If you would prefer that ticket-granting ticket expiry be enforced (in effect
|
536
|
-
# limiting the maximum length of a session), you can set expire_sessions to true.
|
527
|
+
# The server must periodically delete old tickets (login tickets, service tickets
|
528
|
+
# proxy-granting tickets, and ticket-granting tickets) to prevent buildup of
|
529
|
+
# stale data. This effectively limits the maximum length of a CAS session to
|
530
|
+
# the lifetime given here (in seconds). (Defaults to 48 hours)
|
531
|
+
#
|
532
|
+
# Note that this limit is not enforced on the client side; it refers only to the
|
533
|
+
# the maximum lifetime of tickets on the CAS server.
|
537
534
|
|
538
|
-
#
|
535
|
+
#maximum_session_lifetime: 172800
|
539
536
|
|
540
537
|
|
541
538
|
# If you want the usernames entered on the login page to be automatically
|
data/config.ru
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# This is the Rackup initialization script for running RubyCAS-Server under Passenger/Rack.
|
2
|
+
#
|
3
|
+
# This file doesn't really have anything to do with your server's "configuration",
|
4
|
+
# and you almost certainly don't need to modify it. Instead, a config file should
|
5
|
+
# have been created for you (probably under /etc/rubycas-server/config.yml) -- this
|
6
|
+
# is the file you'll want to modify. If for some reason the configuration file
|
7
|
+
# was not created for you, have a look at the config.example.yml template and
|
8
|
+
# go from there.
|
9
|
+
|
1
10
|
require 'rubygems'
|
2
11
|
require 'rack'
|
3
12
|
|
@@ -32,13 +32,14 @@ class CASServer::Authenticators::SQLEncrypted < CASServer::Authenticators::Base
|
|
32
32
|
CASUser.set_table_name @options[:user_table] || "users"
|
33
33
|
|
34
34
|
username_column = @options[:username_column] || "username"
|
35
|
+
encrypt_function = @options[:encrypt_function] || 'user.encrypted_password == Digest::SHA256.hexdigest("#{user.encryption_salt}::#{@password}")'
|
35
36
|
|
36
37
|
results = CASUser.find(:all, :conditions => ["#{username_column} = ?", @username])
|
37
38
|
|
38
39
|
if results.size > 0
|
39
40
|
$LOG.warn("Multiple matches found for user '#{@username}'") if results.size > 1
|
40
41
|
user = results.first
|
41
|
-
return
|
42
|
+
return eval(encrypt_function)
|
42
43
|
else
|
43
44
|
return false
|
44
45
|
end
|
@@ -73,4 +74,4 @@ class CASServer::Authenticators::SQLEncrypted < CASServer::Authenticators::Base
|
|
73
74
|
class CASUser < ActiveRecord::Base
|
74
75
|
include EncryptedPassword
|
75
76
|
end
|
76
|
-
end
|
77
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'casserver/authenticators/base'
|
2
2
|
|
3
3
|
# Dummy authenticator used for testing.
|
4
|
-
# Accepts
|
4
|
+
# Accepts any username as valid as long as the password is "testpassword"; otherwise authentication fails.
|
5
5
|
# Raises an AuthenticationError when username is "do_error" (this is useful to test the Exception
|
6
6
|
# handling functionality).
|
7
7
|
class CASServer::Authenticators::Test < CASServer::Authenticators::Base
|
data/lib/casserver/cas.rb
CHANGED
@@ -45,7 +45,7 @@ module CASServer::CAS
|
|
45
45
|
st.ticket = "ST-" + CASServer::Utils.random_string
|
46
46
|
st.service = service
|
47
47
|
st.username = username
|
48
|
-
st.
|
48
|
+
st.granted_by_tgt_id = tgt.id
|
49
49
|
st.client_hostname = @env['HTTP_X_FORWARDED_FOR'] || @env['REMOTE_HOST'] || @env['REMOTE_ADDR']
|
50
50
|
st.save!
|
51
51
|
$LOG.debug("Generated service ticket '#{st.ticket}' for service '#{st.service}'" +
|
@@ -59,8 +59,8 @@ module CASServer::CAS
|
|
59
59
|
pt.ticket = "PT-" + CASServer::Utils.random_string
|
60
60
|
pt.service = target_service
|
61
61
|
pt.username = pgt.service_ticket.username
|
62
|
-
pt.
|
63
|
-
pt.
|
62
|
+
pt.granted_by_pgt_id = pgt.id
|
63
|
+
pt.granted_by_tgt_id = pgt.service_ticket.granted_by_tgt.id
|
64
64
|
pt.client_hostname = @env['HTTP_X_FORWARDED_FOR'] || @env['REMOTE_HOST'] || @env['REMOTE_ADDR']
|
65
65
|
pt.save!
|
66
66
|
$LOG.debug("Generated proxy ticket '#{pt.ticket}' for target service '#{pt.service}'" +
|
@@ -114,21 +114,21 @@ module CASServer::CAS
|
|
114
114
|
|
115
115
|
success = false
|
116
116
|
if ticket.nil?
|
117
|
-
error = "Your login request did not include a login ticket. There may be a problem with the authentication system."
|
118
|
-
$LOG.warn
|
117
|
+
error = _("Your login request did not include a login ticket. There may be a problem with the authentication system.")
|
118
|
+
$LOG.warn "Missing login ticket."
|
119
119
|
elsif lt = LoginTicket.find_by_ticket(ticket)
|
120
120
|
if lt.consumed?
|
121
|
-
error = "The login ticket you provided has already been used up. Please try logging in again."
|
122
|
-
$LOG.warn
|
123
|
-
elsif Time.now - lt.created_on < $CONF.
|
124
|
-
$LOG.info
|
121
|
+
error = _("The login ticket you provided has already been used up. Please try logging in again.")
|
122
|
+
$LOG.warn "Login ticket '#{ticket}' previously used up"
|
123
|
+
elsif Time.now - lt.created_on < $CONF.maximum_unused_login_ticket_lifetime
|
124
|
+
$LOG.info "Login ticket '#{ticket}' successfully validated"
|
125
125
|
else
|
126
|
-
error = "
|
127
|
-
$LOG.warn
|
126
|
+
error = _("You took too long to enter your credentials. Please try again.")
|
127
|
+
$LOG.warn "Expired login ticket '#{ticket}'"
|
128
128
|
end
|
129
129
|
else
|
130
|
-
error = "The login ticket you provided is invalid.
|
131
|
-
$LOG.warn
|
130
|
+
error = _("The login ticket you provided is invalid. There may be a problem with the authentication system.")
|
131
|
+
$LOG.warn "Invalid login ticket '#{ticket}'"
|
132
132
|
end
|
133
133
|
|
134
134
|
lt.consume! if lt
|
@@ -141,13 +141,13 @@ module CASServer::CAS
|
|
141
141
|
|
142
142
|
if ticket.nil?
|
143
143
|
error = "No ticket granting ticket given."
|
144
|
-
$LOG.debug
|
144
|
+
$LOG.debug error
|
145
145
|
elsif tgt = TicketGrantingTicket.find_by_ticket(ticket)
|
146
146
|
if $CONF.expire_sessions && Time.now - tgt.created_on > $CONF.ticket_granting_ticket_expiry
|
147
147
|
error = "Your session has expired. Please log in again."
|
148
|
-
$LOG.info
|
148
|
+
$LOG.info "Ticket granting ticket '#{ticket}' for user '#{tgt.username}' expired."
|
149
149
|
else
|
150
|
-
$LOG.info
|
150
|
+
$LOG.info "Ticket granting ticket '#{ticket}' for user '#{tgt.username}' successfully validated."
|
151
151
|
end
|
152
152
|
else
|
153
153
|
error = "Invalid ticket granting ticket '#{ticket}' (no matching ticket found in the database)."
|
@@ -158,25 +158,25 @@ module CASServer::CAS
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def validate_service_ticket(service, ticket, allow_proxy_tickets = false)
|
161
|
-
$LOG.debug
|
161
|
+
$LOG.debug "Validating service/proxy ticket '#{ticket}' for service '#{service}'"
|
162
162
|
|
163
163
|
if service.nil? or ticket.nil?
|
164
164
|
error = Error.new(:INVALID_REQUEST, "Ticket or service parameter was missing in the request.")
|
165
|
-
$LOG.warn
|
165
|
+
$LOG.warn "#{error.code} - #{error.message}"
|
166
166
|
elsif st = ServiceTicket.find_by_ticket(ticket)
|
167
167
|
if st.consumed?
|
168
168
|
error = Error.new(:INVALID_TICKET, "Ticket '#{ticket}' has already been used up.")
|
169
|
-
$LOG.warn
|
169
|
+
$LOG.warn "#{error.code} - #{error.message}"
|
170
170
|
elsif st.kind_of?(CASServer::Models::ProxyTicket) && !allow_proxy_tickets
|
171
171
|
error = Error.new(:INVALID_TICKET, "Ticket '#{ticket}' is a proxy ticket, but only service tickets are allowed here.")
|
172
|
-
$LOG.warn
|
173
|
-
elsif Time.now - st.created_on > $CONF.
|
172
|
+
$LOG.warn "#{error.code} - #{error.message}"
|
173
|
+
elsif Time.now - st.created_on > $CONF.maximum_unused_service_ticket_lifetime
|
174
174
|
error = Error.new(:INVALID_TICKET, "Ticket '#{ticket}' has expired.")
|
175
|
-
$LOG.warn
|
175
|
+
$LOG.warn "Ticket '#{ticket}' has expired."
|
176
176
|
elsif !st.matches_service? service
|
177
177
|
error = Error.new(:INVALID_SERVICE, "The ticket '#{ticket}' belonging to user '#{st.username}' is valid,"+
|
178
178
|
" but the requested service '#{service}' does not match the service '#{st.service}' associated with this ticket.")
|
179
|
-
$LOG.warn
|
179
|
+
$LOG.warn "#{error.code} - #{error.message}"
|
180
180
|
else
|
181
181
|
$LOG.info("Ticket '#{ticket}' for service '#{service}' for user '#{st.username}' successfully validated.")
|
182
182
|
end
|
@@ -197,10 +197,10 @@ module CASServer::CAS
|
|
197
197
|
pt, error = validate_service_ticket(service, ticket, true)
|
198
198
|
|
199
199
|
if pt.kind_of?(CASServer::Models::ProxyTicket) && !error
|
200
|
-
if not pt.
|
200
|
+
if not pt.granted_by_pgt
|
201
201
|
error = Error.new(:INTERNAL_ERROR, "Proxy ticket '#{pt}' belonging to user '#{pt.username}' is not associated with a proxy granting ticket.")
|
202
|
-
elsif not pt.
|
203
|
-
error = Error.new(:INTERNAL_ERROR, "Proxy granting ticket '#{pt.
|
202
|
+
elsif not pt.granted_by_pgt.service_ticket
|
203
|
+
error = Error.new(:INTERNAL_ERROR, "Proxy granting ticket '#{pt.granted_by_pgt}'"+
|
204
204
|
" (associated with proxy ticket '#{pt}' and belonging to user '#{pt.username}' is not associated with a service ticket.")
|
205
205
|
end
|
206
206
|
end
|
@@ -305,10 +305,11 @@ module CASServer::CAS
|
|
305
305
|
return dirty_service if dirty_service.blank?
|
306
306
|
clean_service = dirty_service.dup
|
307
307
|
['service', 'ticket', 'gateway', 'renew'].each do |p|
|
308
|
-
clean_service.sub!(Regexp.new("
|
308
|
+
clean_service.sub!(Regexp.new("&?#{p}=[^&]*"), '')
|
309
309
|
end
|
310
310
|
|
311
|
-
clean_service.gsub!(/[
|
311
|
+
clean_service.gsub!(/[\/\?&]$/, '') # remove trailing ?, /, or &
|
312
|
+
clean_service.gsub!('?&', '?')
|
312
313
|
clean_service.gsub!(' ', '+')
|
313
314
|
|
314
315
|
$LOG.debug("Cleaned dirty service URL #{dirty_service.inspect} to #{clean_service.inspect}") if
|
data/lib/casserver/conf.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
|
2
2
|
conf_defaults = {
|
3
|
-
:
|
4
|
-
:
|
5
|
-
:
|
6
|
-
:proxy_granting_ticket_expiry => 48.hours,
|
7
|
-
:ticket_granting_ticket_expiry => 48.hours,
|
3
|
+
:maximum_unused_login_ticket_lifetime => 5.minutes,
|
4
|
+
:maximum_unused_service_ticket_lifetime => 5.minutes, # CAS Protocol Spec, sec. 3.2.1 (recommended expiry time)
|
5
|
+
:maximum_session_lifetime => 1.month, # all tickets are deleted after this period of time
|
8
6
|
:log => {:file => 'casserver.log', :level => 'DEBUG'},
|
9
7
|
:uri_path => "/"
|
10
8
|
}
|
@@ -70,7 +68,6 @@ rescue NameError
|
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
73
|
-
|
74
71
|
$CONF[:static] = {
|
75
72
|
:urls => "/themes",
|
76
73
|
:root => "#{$APP_ROOT}/public"
|
@@ -161,23 +161,23 @@ module CASServer::Controllers
|
|
161
161
|
# 3.6 (ticket-granting cookie)
|
162
162
|
tgt = generate_ticket_granting_ticket(@username, extra_attributes)
|
163
163
|
|
164
|
-
if $CONF.
|
165
|
-
expires = $CONF.
|
164
|
+
if $CONF.maximum_session_lifetime
|
165
|
+
expires = $CONF.maximum_session_lifetime.to_i.from_now
|
166
166
|
expiry_info = " It will expire on #{expires}."
|
167
167
|
else
|
168
168
|
expiry_info = " It will not expire."
|
169
169
|
end
|
170
170
|
|
171
|
-
if $CONF.
|
171
|
+
if $CONF.maximum_session_lifetime
|
172
172
|
cookies['tgt'] = {
|
173
173
|
:value => tgt.to_s,
|
174
|
-
:expires => Time.now + $CONF.
|
174
|
+
:expires => Time.now + $CONF.maximum_session_lifetime
|
175
175
|
}
|
176
176
|
else
|
177
177
|
cookies['tgt'] = tgt.to_s
|
178
178
|
end
|
179
179
|
|
180
|
-
$LOG.debug("Ticket granting cookie '#{cookies['tgt'].inspect}' granted to
|
180
|
+
$LOG.debug("Ticket granting cookie '#{cookies['tgt'].inspect}' granted to #{@username.inspect}. #{expiry_info}")
|
181
181
|
|
182
182
|
if @service.blank?
|
183
183
|
$LOG.info("Successfully authenticated user '#{@username}' at '#{tgt.client_hostname}'. No service param was given, so we will not redirect.")
|
@@ -228,25 +228,23 @@ module CASServer::Controllers
|
|
228
228
|
|
229
229
|
if tgt
|
230
230
|
CASServer::Models::TicketGrantingTicket.transaction do
|
231
|
-
|
231
|
+
$LOG.debug("Deleting Service/Proxy Tickets for '#{tgt}' for user '#{tgt.username}'")
|
232
|
+
tgt.granted_service_tickets.each do |st|
|
233
|
+
send_logout_notification_for_service_ticket(st) if $CONF.enable_single_sign_out
|
234
|
+
# TODO: Maybe we should do some special handling if send_logout_notification_for_service_ticket fails?
|
235
|
+
# (the above method returns false if the POST results in a non-200 HTTP response).
|
236
|
+
$LOG.debug "Deleting #{st.class.name.demodulize} #{st.ticket.inspect} for service #{st.service}."
|
237
|
+
st.destroy
|
238
|
+
end
|
239
|
+
|
240
|
+
pgts = CASServer::Models::ProxyGrantingTicket.find(:all,
|
232
241
|
:conditions => [CASServer::Models::Base.connection.quote_table_name(CASServer::Models::ServiceTicket.table_name)+".username = ?", tgt.username],
|
233
|
-
:include => :service_ticket)
|
242
|
+
:include => :service_ticket)
|
234
243
|
pgts.each do |pgt|
|
235
244
|
$LOG.debug("Deleting Proxy-Granting Ticket '#{pgt}' for user '#{pgt.service_ticket.username}'")
|
236
245
|
pgt.destroy
|
237
246
|
end
|
238
247
|
|
239
|
-
if $CONF.enable_single_sign_out
|
240
|
-
$LOG.debug("Deleting Service/Proxy Tickets for '#{tgt}' for user '#{tgt.username}'")
|
241
|
-
tgt.service_tickets.each do |st|
|
242
|
-
send_logout_notification_for_service_ticket(st)
|
243
|
-
# TODO: Maybe we should do some special handling if send_logout_notification_for_service_ticket fails?
|
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}."
|
246
|
-
st.destroy
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
248
|
$LOG.debug("Deleting #{tgt.class.name.demodulize} '#{tgt}' for user '#{tgt.username}'")
|
251
249
|
tgt.destroy
|
252
250
|
end
|
@@ -258,8 +256,7 @@ module CASServer::Controllers
|
|
258
256
|
|
259
257
|
@message = {:type => 'confirmation', :message => _("You have successfully logged out.")}
|
260
258
|
|
261
|
-
@message[:message]
|
262
|
-
_(" Please click on the following link to continue:") if @continue_url
|
259
|
+
@message[:message] +=_(" Please click on the following link to continue:") if @continue_url
|
263
260
|
|
264
261
|
@lt = generate_login_ticket
|
265
262
|
|
@@ -322,7 +319,7 @@ module CASServer::Controllers
|
|
322
319
|
pgt = generate_proxy_granting_ticket(@pgt_url, st)
|
323
320
|
@pgtiou = pgt.iou if pgt
|
324
321
|
end
|
325
|
-
@extra_attributes = st.
|
322
|
+
@extra_attributes = st.granted_by_tgt.extra_attributes || {}
|
326
323
|
end
|
327
324
|
|
328
325
|
@status = CASServer::Controllers.response_status_from_error(@error) if @error
|
@@ -356,7 +353,7 @@ module CASServer::Controllers
|
|
356
353
|
@username = t.username
|
357
354
|
|
358
355
|
if t.kind_of? CASServer::Models::ProxyTicket
|
359
|
-
@proxies << t.
|
356
|
+
@proxies << t.granted_by_pgt.service_ticket.service
|
360
357
|
end
|
361
358
|
|
362
359
|
if @pgt_url
|
@@ -364,7 +361,7 @@ module CASServer::Controllers
|
|
364
361
|
@pgtiou = pgt.iou if pgt
|
365
362
|
end
|
366
363
|
|
367
|
-
@extra_attributes = t.
|
364
|
+
@extra_attributes = t.granted_by_tgt.extra_attributes || {}
|
368
365
|
end
|
369
366
|
|
370
367
|
@status = CASServer::Controllers.response_status_from_error(@error) if @error
|
@@ -12,14 +12,32 @@ module CASServer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def determine_locale
|
15
|
-
|
16
|
-
|
17
|
-
lang
|
18
|
-
lang
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
|
16
|
+
source = nil
|
17
|
+
lang = case
|
18
|
+
when !input['lang'].blank?
|
19
|
+
source = "'lang' request variable"
|
20
|
+
cookies['lang'] = input['lang']
|
21
|
+
input['lang']
|
22
|
+
when !cookies['lang'].blank?
|
23
|
+
source = "'lang' cookie"
|
24
|
+
cookies['lang']
|
25
|
+
when !@env['HTTP_ACCEPT_LANGUAGE'].blank?
|
26
|
+
source = "'HTTP_ACCEPT_LANGUAGE' header"
|
27
|
+
lang = @env['HTTP_ACCEPT_LANGUAGE']
|
28
|
+
when !@env['HTTP_USER_AGENT'].blank? && @env['HTTP_USER_AGENT'] =~ /[^a-z]([a-z]{2}(-[a-z]{2})?)[^a-z]/i
|
29
|
+
source = "'HTTP_USER_AGENT' header"
|
30
|
+
$~[1]
|
31
|
+
when !$CONF['default_locale'].blank?
|
32
|
+
source = "'default_locale' config option"
|
33
|
+
$CONF[:default_locale]
|
34
|
+
else
|
35
|
+
source = "default"
|
36
|
+
"en"
|
37
|
+
end
|
38
|
+
|
39
|
+
$LOG.debug "Detected locale is #{lang.inspect} (from #{source})"
|
40
|
+
|
23
41
|
lang.gsub!('_','-')
|
24
42
|
|
25
43
|
# TODO: Need to confirm that this method of splitting the accepted
|
@@ -52,6 +70,8 @@ module CASServer
|
|
52
70
|
end
|
53
71
|
|
54
72
|
chosen_lang = "en" if chosen_lang.blank?
|
73
|
+
|
74
|
+
$LOG.debug "Chosen locale is #{chosen_lang.inspect}"
|
55
75
|
|
56
76
|
return chosen_lang
|
57
77
|
end
|
data/lib/casserver/models.rb
CHANGED
@@ -7,6 +7,26 @@ module CASServer::Models
|
|
7
7
|
self.consumed = Time.now
|
8
8
|
self.save!
|
9
9
|
end
|
10
|
+
|
11
|
+
def self.included(mod)
|
12
|
+
mod.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def cleanup(max_lifetime, max_unconsumed_lifetime)
|
17
|
+
transaction do
|
18
|
+
conditions = ["created_on < ? OR (consumed IS NULL AND created_on < ?)",
|
19
|
+
Time.now - max_lifetime,
|
20
|
+
Time.now - max_unconsumed_lifetime]
|
21
|
+
expired_tickets_count = count(:conditions => conditions)
|
22
|
+
|
23
|
+
$LOG.debug("Destroying #{expired_tickets_count} expired #{self.name.demodulize}"+
|
24
|
+
"#{'s' if expired_tickets_count > 1}.") if expired_tickets_count > 0
|
25
|
+
|
26
|
+
destroy_all(conditions)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
10
30
|
end
|
11
31
|
|
12
32
|
class Ticket < Base
|
@@ -14,12 +34,12 @@ module CASServer::Models
|
|
14
34
|
ticket
|
15
35
|
end
|
16
36
|
|
17
|
-
def self.
|
37
|
+
def self.cleanup(max_lifetime)
|
18
38
|
transaction do
|
19
|
-
conditions = ["created_on < ?", Time.now -
|
39
|
+
conditions = ["created_on < ?", Time.now - max_lifetime]
|
20
40
|
expired_tickets_count = count(:conditions => conditions)
|
21
41
|
|
22
|
-
$LOG.debug("Destroying #{expired_tickets_count} expired #{self.name.
|
42
|
+
$LOG.debug("Destroying #{expired_tickets_count} expired #{self.name.demodulize}"+
|
23
43
|
"#{'s' if expired_tickets_count > 1}.") if expired_tickets_count > 0
|
24
44
|
|
25
45
|
destroy_all(conditions)
|
@@ -36,7 +56,11 @@ module CASServer::Models
|
|
36
56
|
set_table_name 'casserver_st'
|
37
57
|
include Consumable
|
38
58
|
|
39
|
-
belongs_to :
|
59
|
+
belongs_to :granted_by_tgt,
|
60
|
+
:class_name => 'CASServer::Models::TicketGrantingTicket',
|
61
|
+
:foreign_key => :granted_by_tgt_id
|
62
|
+
has_one :proxy_granting_ticket,
|
63
|
+
:foreign_key => :created_by_st_id
|
40
64
|
|
41
65
|
def matches_service?(service)
|
42
66
|
CASServer::CAS.clean_service_url(self.service) ==
|
@@ -45,7 +69,9 @@ module CASServer::Models
|
|
45
69
|
end
|
46
70
|
|
47
71
|
class ProxyTicket < ServiceTicket
|
48
|
-
belongs_to :
|
72
|
+
belongs_to :granted_by_pgt,
|
73
|
+
:class_name => 'CASServer::Models::ProxyGrantingTicket',
|
74
|
+
:foreign_key => :granted_by_pgt_id
|
49
75
|
end
|
50
76
|
|
51
77
|
class TicketGrantingTicket < Ticket
|
@@ -53,13 +79,17 @@ module CASServer::Models
|
|
53
79
|
|
54
80
|
serialize :extra_attributes
|
55
81
|
|
56
|
-
has_many :
|
82
|
+
has_many :granted_service_tickets,
|
83
|
+
:class_name => 'CASServer::Models::ServiceTicket',
|
84
|
+
:foreign_key => :granted_by_tgt_id
|
57
85
|
end
|
58
86
|
|
59
87
|
class ProxyGrantingTicket < Ticket
|
60
88
|
set_table_name 'casserver_pgt'
|
61
89
|
belongs_to :service_ticket
|
62
|
-
has_many :
|
90
|
+
has_many :granted_proxy_tickets,
|
91
|
+
:class_name => 'CASServer::Models::ProxyTicket',
|
92
|
+
:foreign_key => :granted_by_pgt_id
|
63
93
|
end
|
64
94
|
|
65
95
|
class Error
|
@@ -220,4 +250,16 @@ module CASServer::Models
|
|
220
250
|
remove_column :casserver_tgt, :extra_attributes
|
221
251
|
end
|
222
252
|
end
|
253
|
+
|
254
|
+
class RenamePgtForeignKeys < V 0.80
|
255
|
+
def self.up
|
256
|
+
rename_column :casserver_st, :proxy_granting_ticket_id, :granted_by_pgt_id
|
257
|
+
rename_column :casserver_st, :tgt_id, :granted_by_tgt_id
|
258
|
+
end
|
259
|
+
|
260
|
+
def self.down
|
261
|
+
rename_column :casserver_st, :granted_by_pgt_id, :proxy_granting_ticket_id
|
262
|
+
rename_column :casserver_st, :granted_by_tgt_id, :tgt_id
|
263
|
+
end
|
264
|
+
end
|
223
265
|
end
|
data/lib/casserver.rb
CHANGED
@@ -28,12 +28,31 @@ require "casserver/controllers"
|
|
28
28
|
require "casserver/localization"
|
29
29
|
|
30
30
|
def CASServer.create
|
31
|
-
|
31
|
+
$LOG.info "Creating RubyCAS-Server with pid #{Process.pid}."
|
32
|
+
|
33
|
+
|
34
|
+
CASServer::Models::Base.establish_connection($CONF.database)
|
32
35
|
CASServer::Models.create_schema
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
|
37
|
+
#TODO: these warnings should eventually be deleted
|
38
|
+
if $CONF.service_ticket_expiry
|
39
|
+
$LOG.warn "The 'service_ticket_expiry' option has been renamed to 'maximum_unused_service_ticket_lifetime'. Please make the necessary change to your config file!"
|
40
|
+
$CONF.maximum_unused_service_ticket_lifetime ||= $CONF.service_ticket_expiry
|
41
|
+
end
|
42
|
+
if $CONF.login_ticket_expiry
|
43
|
+
$LOG.warn "The 'login_ticket_expiry' option has been renamed to 'maximum_unused_login_ticket_lifetime'. Please make the necessary change to your config file!"
|
44
|
+
$CONF.maximum_unused_login_ticket_lifetime ||= $CONF.login_ticket_expiry
|
45
|
+
end
|
46
|
+
if $CONF.ticket_granting_ticket_expiry || $CONF.proxy_granting_ticket_expiry
|
47
|
+
$LOG.warn "The 'ticket_granting_ticket_expiry' and 'proxy_granting_ticket_expiry' options have been renamed to 'maximum_session_lifetime'. Please make the necessary change to your config file!"
|
48
|
+
$CONF.maximum_session_lifetime ||= $CONF.ticket_granting_ticket_expiry || $CONF.proxy_granting_ticket_expiry
|
49
|
+
end
|
50
|
+
|
51
|
+
if $CONF.maximum_session_lifetime
|
52
|
+
CASServer::Models::ServiceTicket.cleanup($CONF.maximum_session_lifetime, $CONF.maximum_unused_service_ticket_lifetime)
|
53
|
+
CASServer::Models::LoginTicket.cleanup($CONF.maximum_session_lifetime, $CONF.maximum_unused_login_ticket_lifetime)
|
54
|
+
CASServer::Models::ProxyGrantingTicket.cleanup($CONF.maximum_session_lifetime)
|
55
|
+
CASServer::Models::TicketGrantingTicket.cleanup($CONF.maximum_session_lifetime)
|
56
|
+
end
|
38
57
|
end
|
39
58
|
|