Class: Rack::FakeCAS

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/fake_cas.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, config = {}, attributes_config = {}) ⇒ FakeCAS

Returns a new instance of FakeCAS


5
6
7
8
9
# File 'lib/rack/fake_cas.rb', line 5

def initialize(app, config={}, attributes_config={})
  @app = app
  @config = config || {}
  @attributes_config = attributes_config || {}
end

Instance Method Details

#call(env) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rack/fake_cas.rb', line 11

def call(env)
  @request = Rack::Request.new(env)
  cas_request = CASRequest.new(@request)

  if cas_request.path_matches? @config[:exclude_paths] || @config[:exclude_path]
    return @app.call(env)
  end

  case @request.path_info
  when '/login'
    username = @request.params['username']
    @request.session['cas'] = {}
    @request.session['cas']['user'] = username
    @request.session['cas']['extra_attributes'] = @attributes_config.fetch(username, {})
    redirect_to @request.params['service']

  when '/logout'
    @request.session.send respond_to?(:destroy) ? :destroy : :clear
    redirect_to "#{@request.script_name}/"

  # built-in way to get to the login page without needing to return a 401 status
  when '/fake_cas_login'
    

  else
    response = @app.call(env)

    if response[0] == 401 # access denied
      
    else
      response
    end
  end
end