@@ -23,6 +23,7 @@ def filter(controller)
2323 end
2424
2525 last_st = controller . session [ :cas_last_valid_ticket ]
26+ last_st_service = controller . session [ :cas_last_valid_ticket_service ]
2627
2728 if single_sign_out ( controller )
2829 controller . send ( :render , :text => "CAS Single-Sign-Out request intercepted." )
@@ -31,17 +32,17 @@ def filter(controller)
3132
3233 st = read_ticket ( controller )
3334
34- is_new_session = true
35+ # is_new_session = true
3536
3637 if st && last_st &&
37- last_st . ticket == st . ticket &&
38- last_st . service == st . service
38+ last_st == st . ticket &&
39+ last_st_service == st . service
3940 # warn() rather than info() because we really shouldn't be re-validating the same ticket.
4041 # The only situation where this is acceptable is if the user manually does a refresh and
4142 # the same ticket happens to be in the URL.
4243 log . warn ( "Re-using previously validated ticket since the ticket id and service are the same." )
43- st = last_st
44- is_new_session = false
44+ # st = last_st
45+ return true
4546 elsif last_st &&
4647 !config [ :authenticate_on_every_request ] &&
4748 controller . session [ client . username_session_key ]
@@ -54,61 +55,70 @@ def filter(controller)
5455 # it will almost certainly break POST request, AJAX calls, etc.
5556 log . debug "Existing local CAS session detected for #{ controller . session [ client . username_session_key ] . inspect } . " +
5657 "Previous ticket #{ last_st . ticket . inspect } will be re-used."
57- st = last_st
58- is_new_session = false
58+ # st = last_st
59+ return true
5960 end
6061
6162 if st
6263 client . validate_service_ticket ( st ) unless st . has_been_validated?
63- vr = st . response
6464
6565 if st . is_valid?
66- if is_new_session
67- log . info ( "Ticket #{ st . ticket . inspect } for service #{ st . service . inspect } belonging to user #{ vr . user . inspect } is VALID." )
68- controller . session [ client . username_session_key ] = vr . user . dup
69- controller . session [ client . extra_attributes_session_key ] = HashWithIndifferentAccess . new ( vr . extra_attributes ) if vr . extra_attributes
66+ # if is_new_session
67+ log . info ( "Ticket #{ st . ticket . inspect } for service #{ st . service . inspect } belonging to user #{ st . user . inspect } is VALID." )
68+ controller . session [ client . username_session_key ] = st . user . dup
69+ controller . session [ client . extra_attributes_session_key ] = HashWithIndifferentAccess . new ( st . extra_attributes ) if st . extra_attributes
7070
71- if vr . extra_attributes
72- log . debug ( "Extra user attributes provided along with ticket #{ st . ticket . inspect } : #{ vr . extra_attributes . inspect } ." )
71+ if st . extra_attributes
72+ log . debug ( "Extra user attributes provided along with ticket #{ st . ticket . inspect } : #{ st . extra_attributes . inspect } ." )
7373 end
7474
7575 # RubyCAS-Client 1.x used :casfilteruser as it's username session key,
7676 # so we need to set this here to ensure compatibility with configurations
7777 # built around the old client.
78- controller . session [ :casfilteruser ] = vr . user
78+ controller . session [ :casfilteruser ] = st . user
7979
8080 if config [ :enable_single_sign_out ]
81- @@ client. ticket_store . store_service_session_lookup ( st , controller )
81+ client . ticket_store . store_service_session_lookup ( st , controller )
8282 end
83- end
83+ # end
8484
8585 # Store the ticket in the session to avoid re-validating the same service
8686 # ticket with the CAS server.
87- controller . session [ :cas_last_valid_ticket ] = st
87+ controller . session [ :cas_last_valid_ticket ] = st . ticket
88+ controller . session [ :cas_last_valid_ticket_service ] = st . service
8889
89- if vr . pgt_iou
90- unless controller . session [ :cas_pgt ] && controller . session [ :cas_pgt ] . ticket && controller . session [ :cas_pgt ] . iou == vr . pgt_iou
90+ if st . pgt_iou
91+ unless controller . session [ :cas_pgt ] && controller . session [ :cas_pgt ] . ticket && controller . session [ :cas_pgt ] . iou == st . pgt_iou
9192 log . info ( "Receipt has a proxy-granting ticket IOU. Attempting to retrieve the proxy-granting ticket..." )
92- pgt = client . retrieve_proxy_granting_ticket ( vr . pgt_iou )
93+ pgt = client . retrieve_proxy_granting_ticket ( st . pgt_iou )
9394
9495 if pgt
9596 log . debug ( "Got PGT #{ pgt . ticket . inspect } for PGT IOU #{ pgt . iou . inspect } . This will be stored in the session." )
9697 controller . session [ :cas_pgt ] = pgt
9798 # For backwards compatibility with RubyCAS-Client 1.x configurations...
9899 controller . session [ :casfilterpgt ] = pgt
99100 else
100- log . error ( "Failed to retrieve a PGT for PGT IOU #{ vr . pgt_iou } !" )
101+ log . error ( "Failed to retrieve a PGT for PGT IOU #{ st . pgt_iou } !" )
101102 end
102103 else
103- log . info ( "PGT is present in session and PGT IOU #{ vr . pgt_iou } matches the saved PGT IOU. Not retrieving new PGT." )
104+ log . info ( "PGT is present in session and PGT IOU #{ st . pgt_iou } matches the saved PGT IOU. Not retrieving new PGT." )
104105 end
105106
106107 end
107108
109+ log . debug '################'
110+ log . debug '################'
111+ controller . session . each do |v |
112+ log . debug v . inspect
113+ end
114+ log . debug '################'
115+ log . debug '################'
116+
117+
108118 return true
109119 else
110- log . warn ( "Ticket #{ st . ticket . inspect } failed validation -- #{ vr . failure_code } : #{ vr . failure_message } " )
111- unauthorized! ( controller , vr )
120+ log . warn ( "Ticket #{ st . ticket . inspect } failed validation -- #{ st . failure_code } : #{ st . failure_message } " )
121+ unauthorized! ( controller , st )
112122 return false
113123 end
114124 else # no service ticket was present in the request
0 commit comments