Class: Cas::Utils
- Inherits:
-
Object
- Object
- Cas::Utils
- Defined in:
- lib/bcms_cas/utils.rb
Class Method Summary collapse
-
.cas_server_url ⇒ Object
Looks up the URL of the CAS server from the environment.
- .check(portlet) ⇒ Object
-
.fetch_lt_from_cas ⇒ Object
Gets a valid login_ticket from the CAS Server, which will allow us to submit directly from our CMS login forms.
-
.logout(controller, service = nil) ⇒ Object
This is a wrapper around the default behavior of the CASClient Rails filter.
-
.reset_session_and_get_referrer(controller, service) ⇒ Object
Copy/Paste from CAS Filter.
-
.service_url(portlet, page, redirect_to = nil) ⇒ Object
Calculates which URL the user should be redirect to, after completing registration on the CAS server.
Class Method Details
.cas_server_url ⇒ Object
Looks up the URL of the CAS server from the environment
64 65 66 |
# File 'lib/bcms_cas/utils.rb', line 64 def self.cas_server_url CASClient::Frameworks::Rails::Filter.config[:cas_base_url] end |
.check(portlet) ⇒ Object
48 49 50 |
# File 'lib/bcms_cas/utils.rb', line 48 def self.check(portlet) portlet.current_page.path end |
.fetch_lt_from_cas ⇒ Object
Gets a valid login_ticket from the CAS Server, which will allow us to submit directly from our CMS login forms.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bcms_cas/utils.rb', line 35 def self.fetch_lt_from_cas url = URI.parse("#{self.cas_server_url}/loginTicket") post = Net::HTTP::Post.new(url.path) post.set_form_data({'dummy'=>'data'}) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true res = https.start {|http| http.request(post) } lt = res.body lt end |
.logout(controller, service = nil) ⇒ Object
This is a wrapper around the default behavior of the CASClient Rails filter.
The only difference is that it generates a return URL that the user can click on to get back to the homepage.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bcms_cas/utils.rb', line 11 def self.logout(controller, service = nil) # Copy/Paste from Filter referer = reset_session_and_get_referrer(controller, service) # New lines client = CASClient::Frameworks::Rails::Filter.client # Adding gateway=true param to this logout URL will cause immediate redirect, which is preferable # since it means users aren't left stranded on the CAS server logout page. url = client.logout_url(referer, referer) controller.send(:redirect_to, "#{url}&gateway=true") end |
.reset_session_and_get_referrer(controller, service) ⇒ Object
Copy/Paste from CAS Filter
25 26 27 28 29 30 31 |
# File 'lib/bcms_cas/utils.rb', line 25 def self.reset_session_and_get_referrer(controller, service) referer = service || controller.request.referer st = controller.session[:cas_last_valid_ticket] delete_service_session_lookup(st) if st controller.send(:reset_session) referer end |
.service_url(portlet, page, redirect_to = nil) ⇒ Object
Calculates which URL the user should be redirect to, after completing registration on the CAS server.
53 54 55 56 57 58 59 60 61 |
# File 'lib/bcms_cas/utils.rb', line 53 def self.service_url(portlet, page, redirect_to = nil) path = page.path if page path = "" unless page goto = redirect_to || portlet.success_url || path unless goto.starts_with?("http://") goto = to_absolute_url(goto) end goto end |