Class: Rmobio::Cas::MobioCasFilter

Inherits:
CASClient::Frameworks::Rails::Filter
  • Object
show all
Defined in:
lib/rmobio/cas.rb

Class Method Summary collapse

Class Method Details

.configure(config) ⇒ Object

Override configure so we use our cas client



129
130
131
132
133
134
# File 'lib/rmobio/cas.rb', line 129

def self.configure(config)
  @@config = config
  @@config[:logger] = RAILS_DEFAULT_LOGGER unless @@config[:logger]
  @@client = Rmobio::Cas::Client.new(config)
  @@log = client.log
end

.filter(controller) ⇒ Object

Here’s where we override the filter



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rmobio/cas.rb', line 137

def self.filter(controller)
  RAILS_DEFAULT_LOGGER.debug 'CAS: Starting filter...' unless not defined? RAILS_DEFAULT_LOGGER
  
  # Figure out if we should execute the filter based on configuration
  @req_domain = Rmobio::Utils.get_domain(controller.request.url)
  @included_domains = MOBIO_CONFIG['cas_filter_included_domains']
  @run_filter = nil
  
  if @req_domain and @included_domains
    @included_domains.each do |domain|
      if domain.match(@req_domain)
        RAILS_DEFAULT_LOGGER.debug "CAS: #{@req_domain} matches inclusion #{domain}, " +
          "continuing with filter..." unless not defined? RAILS_DEFAULT_LOGGER
        @run_filter = true
      end
    end
  end
  
  # We didn't find a match
  if @run_filter.nil?
    return
  end
  
  @handset_id = controller.params[:handsetid]
  
  # handsetid gets appended to request uri, we need to remove it for 
  # service validation to work
  controller.params.delete('handsetid')
  
  # Call filter on the base class
  CASClient::Frameworks::Rails::Filter.filter(controller)  
  
  # Now let's put the handsetid back into the request in case we do a redirect
  controller.params[:handsetid] = @handset_id
  
  # Use the overloaded cas client to retrieve uuid. This should only
  # happen after service ticket validation.
  if not @@client.xml_response.nil?
    @uuid = @@client.xml_response.uuid
  end
  
  # Setup the uuid and handset_id session variables
  if not @uuid.nil? and not @uuid == '' and not @handset_id.nil? and not @handset_id == ''
    controller.session[:uuid] = @uuid
    controller.session[:handset_id] = @handset_id
    RAILS_DEFAULT_LOGGER.debug 'CAS: Stored cas uuid: ' + @uuid + ' and handset_id: ' + @handset_id +
      ' into the session.' unless not defined? RAILS_DEFAULT_LOGGER
    return true
  else
    # Should only happen on initial redirect
    RAILS_DEFAULT_LOGGER.debug 'CAS: MobioCasFilter cannot read the uuid/handset_id ' +
      'attributes for the user!' unless not defined? RAILS_DEFAULT_LOGGER
    return false
  end
end