Class: Rmobio::Cas::Client

Inherits:
CASClient::Client
  • Object
show all
Defined in:
lib/rmobio/cas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xml_responseObject

Returns the value of attribute xml_response.



68
69
70
# File 'lib/rmobio/cas.rb', line 68

def xml_response
  @xml_response
end

Instance Method Details

#add_service_to_login_url(service_url) ⇒ Object

Override to add the domain param



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rmobio/cas.rb', line 112

def (service_url)
  uri = super(service_url)
  domain = Rmobio::Utils.get_domain(service_url)
  
  if not domain.nil?
    RAILS_DEFAULT_LOGGER.debug 'CAS: Adding domain parameter ' +
      domain + '...' unless not defined? RAILS_DEFAULT_LOGGER
    param_token = uri.index("?").nil? ? '?' : '&'
    uri << param_token + 'domain=' + domain
  end
  uri.to_s
end

#request_cas_response(uri, type) ⇒ Object

We have to override this method because MobioValidationResponse is uninitialized in the base class



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rmobio/cas.rb', line 92

def request_cas_response(uri, type)
  log.debug "Requesting CAS response form URI #{uri.inspect}"

  uri = URI.parse(uri) unless uri.kind_of? URI
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = (uri.scheme == 'https')
  raw_res = https.start do |conn|
    conn.get("#{uri.path}?#{uri.query}")
  end

  # TODO: check to make sure that response code is 200 and handle errors
  # otherwise

  RAILS_DEFAULT_LOGGER.debug "CAS Responded with " + 
    "#{raw_res.inspect}:\n#{raw_res.body}" unless not defined? RAILS_DEFAULT_LOGGER

  type.new(raw_res.body)
end

#validate_service_ticket(st) ⇒ Object

Override service ticket validation so we use our XmlResponse



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rmobio/cas.rb', line 71

def validate_service_ticket(st)
  RAILS_DEFAULT_LOGGER.debug 'CAS: Starting to validate service ticket...' unless not defined? RAILS_DEFAULT_LOGGER
  uri = URI.parse(validate_url)
  h = uri.query ? query_to_hash(uri.query) : {}
  h['service'] = st.service
  h['ticket'] = st.ticket
  h['renew'] = 1 if st.renew
  h['pgtUrl'] = proxy_callback_url if proxy_callback_url
    
  # Add our domain parameter
  h['domain'] = Rmobio::Utils.get_domain(st.service)
  uri.query = hash_to_query(h)

  # Override the validation response
  st.response = request_cas_response(uri, Rmobio::Cas::MobioValidationResponse)
  @xml_response = st.response
  return st
end