Module: Aker::Cas::ServiceUrl

Included in:
ServiceMode
Defined in:
lib/aker/cas/service_url.rb

Overview

Provides logic for reconstructing the full requested URL from a rack request.

If used as a mixin, the host class must have a #request accessor. It may optionally also have a #attempted_path accessor.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.service_url(request, attempted_path = nil) ⇒ String

Builds the service URL that should be used for the given request. This is the requested URL (or the attempted_path, if given), sans any service ticket.

Parameters:

  • request (Rack::Request)
  • attempted_path (String) (defaults to: nil)

Returns:

  • (String)

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aker/cas/service_url.rb', line 35

def self.service_url(request, attempted_path=nil)
  requested = URI.parse(
    if attempted_path
      url = "#{request.scheme}://#{request.host}"

      unless [ ["https", 443], ["http", 80] ].include?([request.scheme, request.port])
        url << ":#{request.port}"
      end

      url << attempted_path
    else
      request.url
    end
                       )
  if requested.query
    requested.query.gsub!(/(&?)ticket=ST-[^&]+(&?)/) do
      if [$1, $2].uniq == ['&'] # in the middle
        '&'
      else
        nil
      end
    end
    requested.query = nil if requested.query.empty?
  end
  requested.to_s
end

Instance Method Details

#service_urlString

The service URL supplied to the CAS login page. This is the requested URL, sans any service ticket.

Returns:

  • (String)

20
21
22
23
24
25
# File 'lib/aker/cas/service_url.rb', line 20

def service_url
  ServiceUrl.service_url(
    request,
    (attempted_path if self.respond_to?(:attempted_path))
  )
end