Class: Spid::Rack::Slo::SloEnv

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

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ SloEnv

Returns a new instance of SloEnv.



25
26
27
28
# File 'lib/spid/rack/slo.rb', line 25

def initialize(env)
  @env = env
  @request = ::Rack::Request.new(env)
end

Instance Attribute Details

#envObject (readonly)

:nodoc:



22
23
24
# File 'lib/spid/rack/slo.rb', line 22

def env
  @env
end

#requestObject (readonly)

Returns the value of attribute request.



23
24
25
# File 'lib/spid/rack/slo.rb', line 23

def request
  @request
end

Instance Method Details

#clear_sessionObject



34
35
36
# File 'lib/spid/rack/slo.rb', line 34

def clear_session
  request.session["spid"] = {}
end

#idp_initiated?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/spid/rack/slo.rb', line 121

def idp_initiated?
  !saml_request.nil?
end

#relay_stateObject



80
81
82
83
84
85
# File 'lib/spid/rack/slo.rb', line 80

def relay_state
  if request_relay_state.nil?
    return Spid.configuration.default_relay_state_path
  end
  session["relay_state"][relay_state_param]
end

#relay_state_paramObject



69
70
71
# File 'lib/spid/rack/slo.rb', line 69

def relay_state_param
  request.params["RelayState"]
end

#request_relay_stateObject



73
74
75
76
77
78
# File 'lib/spid/rack/slo.rb', line 73

def request_relay_state
  if !relay_state_param.nil? ||
     relay_state_param != ""
    session["relay_state"][relay_state_param]
  end
end

#responseObject



62
63
64
65
66
67
# File 'lib/spid/rack/slo.rb', line 62

def response
  @relay_state = relay_state unless idp_initiated?
  validate_session
  return response_idp_initiated if idp_initiated?
  response_sp_initiated
end

#response_idp_initiatedObject



50
51
52
53
54
55
56
# File 'lib/spid/rack/slo.rb', line 50

def response_idp_initiated
  [
    200,
    {},
    responser.response
  ]
end

#response_sp_initiatedObject



42
43
44
45
46
47
48
# File 'lib/spid/rack/slo.rb', line 42

def response_sp_initiated
  [
    302,
    { "Location" => @relay_state },
    responser.response
  ]
end

#responserObject



125
126
127
128
129
130
131
132
133
134
# File 'lib/spid/rack/slo.rb', line 125

def responser
  @responser ||=
    begin
      if idp_initiated?
        idp_initiated_slo_request
      else
        sp_initiated_slo_response
      end
    end
end

#saml_requestObject



117
118
119
# File 'lib/spid/rack/slo.rb', line 117

def saml_request
  request.params["SAMLRequest"]
end

#saml_responseObject



113
114
115
# File 'lib/spid/rack/slo.rb', line 113

def saml_response
  request.params["SAMLResponse"]
end

#sessionObject



30
31
32
# File 'lib/spid/rack/slo.rb', line 30

def session
  request.session["spid"]
end

#store_session_failureObject



38
39
40
# File 'lib/spid/rack/slo.rb', line 38

def store_session_failure
  session["errors"] = responser.errors
end

#valid_get?Boolean

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/spid/rack/slo.rb', line 87

def valid_get?
  request.get? &&
    Spid.configuration.slo_binding == Spid::BINDINGS_HTTP_REDIRECT
end

#valid_http_verb?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/spid/rack/slo.rb', line 97

def valid_http_verb?
  valid_post? || valid_get?
end

#valid_path?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/spid/rack/slo.rb', line 101

def valid_path?
  request.path == Spid.configuration.slo_path
end

#valid_post?Boolean

Returns:

  • (Boolean)


92
93
94
95
# File 'lib/spid/rack/slo.rb', line 92

def valid_post?
  request.post? &&
    Spid.configuration.slo_binding == Spid::BINDINGS_HTTP_POST
end

#valid_request?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/spid/rack/slo.rb', line 109

def valid_request?
  valid_path? && valid_http_verb?
end

#valid_response?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/spid/rack/slo.rb', line 105

def valid_response?
  responser.valid?
end

#validate_sessionObject



58
59
60
# File 'lib/spid/rack/slo.rb', line 58

def validate_session
  valid_response? ? clear_session : store_session_failure
end