Class: Spid::Rack::Sso::SsoEnv

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ SsoEnv

Returns a new instance of SsoEnv.



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

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

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



21
22
23
# File 'lib/spid/rack/sso.rb', line 21

def env
  @env
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

Instance Method Details

#log_messageObject



117
118
119
120
121
# File 'lib/spid/rack/sso.rb', line 117

def log_message
  return nil unless Spid.configuration.logging_enabled

  Spid.configuration.logger.info responser.saml_message.delete("\n")
end

#relay_stateObject



77
78
79
80
81
82
# File 'lib/spid/rack/sso.rb', line 77

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



65
66
67
# File 'lib/spid/rack/sso.rb', line 65

def relay_state_param
  request.params["RelayState"]
end

#request_relay_stateObject



69
70
71
72
73
74
75
# File 'lib/spid/rack/sso.rb', line 69

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

#responseObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/spid/rack/sso.rb', line 49

def response
  log_message
  if valid_response?
    store_session_success
  else
    store_session_failure
  end
  [
    302, { "Location" => @relay_state }, []
  ]
end

#responserObject



110
111
112
113
114
115
# File 'lib/spid/rack/sso.rb', line 110

def responser
  @responser ||= ::Spid::Sso::Response.new(
    body: saml_response,
    request_uuid: session["sso_request_uuid"]
  )
end

#saml_responseObject



61
62
63
# File 'lib/spid/rack/sso.rb', line 61

def saml_response
  request.params["SAMLResponse"]
end

#sessionObject



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

def session
  request.session["spid"]
end

#store_session_failureObject



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

def store_session_failure
  session["errors"] = responser.errors
  session.delete("attributes")
  session.delete("sso_request_uuid")
  session.delete("session_index")
end

#store_session_successObject



34
35
36
37
38
39
40
# File 'lib/spid/rack/sso.rb', line 34

def store_session_success
  session["attributes"] = responser.attributes
  session["session_index"] = responser.session_index
  session.delete("sso_request_uuid")
  session.delete("errors")
  session.delete("relay_state")
end

#valid_get?Boolean

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/spid/rack/sso.rb', line 84

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

#valid_http_verb?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/spid/rack/sso.rb', line 94

def valid_http_verb?
  valid_get? || valid_post?
end

#valid_path?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/spid/rack/sso.rb', line 98

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

#valid_post?Boolean

Returns:

  • (Boolean)


89
90
91
92
# File 'lib/spid/rack/sso.rb', line 89

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

#valid_request?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/spid/rack/sso.rb', line 106

def valid_request?
  valid_path? && valid_http_verb?
end

#valid_response?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/spid/rack/sso.rb', line 102

def valid_response?
  responser.valid?
end