Skip to content

Commit 06148ff

Browse files
Roberto Kleinzuk
Roberto Klein
authored andcommitted
Supporting unauthorized xml requests
1 parent 9054a6e commit 06148ff

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/casclient/frameworks/rails/filter.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def filter(controller)
110110
return true
111111
else
112112
log.warn("Ticket #{st.ticket.inspect} failed validation -- #{vr.failure_code}: #{vr.failure_message}")
113-
redirect_to_cas_for_authentication(controller)
113+
unauthorized!(controller, vr)
114114
return false
115115
end
116116
else # no service ticket was present in the request
@@ -128,7 +128,7 @@ def filter(controller)
128128
end
129129
end
130130

131-
redirect_to_cas_for_authentication(controller)
131+
unauthorized!(controller)
132132
return false
133133
end
134134
end
@@ -181,6 +181,18 @@ def logout(controller, service = nil)
181181
controller.send(:redirect_to, client.logout_url(referer))
182182
end
183183

184+
def unauthorized!(controller, vr = nil)
185+
if controller.params[:format] == "xml"
186+
if vr
187+
controller.send(:render, :xml => "<errors><error>#{vr.failure_message}</error></errors>", :status => 401)
188+
else
189+
controller.send(:head, 401)
190+
end
191+
else
192+
redirect_to_cas_for_authentication(controller)
193+
end
194+
end
195+
184196
def redirect_to_cas_for_authentication(controller)
185197
redirect_url = login_url(controller)
186198

0 commit comments

Comments
 (0)