Class: Gloo::WebSvr::Session
- Inherits:
-
Object
- Object
- Gloo::WebSvr::Session
- Defined in:
- lib/gloo/web_svr/session.rb
Constant Summary collapse
- SESSION_CONTAINER =
'session'.freeze
Instance Method Summary collapse
-
#add_session_for_response(headers) ⇒ Object
If there is session data, encrypt and add it to the response.
-
#cookie_expires ⇒ Object
Get the expiration time for the session cookie.
-
#cookie_path ⇒ Object
Get the path for the session cookie.
-
#decode_decrypt(data) ⇒ Object
Decode and decrypt the session data.
-
#encrypt_encode(data) ⇒ Object
Encrypt and encode the session data.
-
#initialize(engine, server_obj) ⇒ Session
constructor
Set up the web server.
-
#iv ⇒ Object
Get the initialization vector for the cipher.
-
#key ⇒ Object
Get the key for the encryption cipher.
-
#secure_cookie? ⇒ Boolean
Should the session cookie be secure?.
-
#session_name ⇒ Object
Get the session cookie name.
-
#set_session_data_for_request(env) ⇒ Object
Get the session data from the encrypted cookie.
Constructor Details
#initialize(engine, server_obj) ⇒ Session
Set up the web server.
27 28 29 30 31 32 |
# File 'lib/gloo/web_svr/session.rb', line 27 def initialize( engine, server_obj ) @engine = engine @log = @engine.log @server_obj = server_obj end |
Instance Method Details
#add_session_for_response(headers) ⇒ Object
If there is session data, encrypt and add it to the response. Once done, clear out the session data.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/gloo/web_svr/session.rb', line 74 def add_session_for_response( headers ) # Are we using sessions? if @server_obj.use_session? # Build and add encrypted session data data = @server_obj.get_session_data unless data.empty? data = encrypt_encode( data ) session_hash = { value: data, path: , expires: , http_only: true } if session_hash[ :secure ] = true end Rack::Utils.( headers, session_name, session_hash ) end # Clear out session data @server_obj.clear_session_data end return headers end |
#cookie_expires ⇒ Object
Get the expiration time for the session cookie.
154 155 156 |
# File 'lib/gloo/web_svr/session.rb', line 154 def return @server_obj. end |
#cookie_path ⇒ Object
Get the path for the session cookie.
147 148 149 |
# File 'lib/gloo/web_svr/session.rb', line 147 def return @server_obj. end |
#decode_decrypt(data) ⇒ Object
Decode and decrypt the session data.
116 117 118 119 120 121 |
# File 'lib/gloo/web_svr/session.rb', line 116 def decode_decrypt( data ) return nil unless data && key && iv data = Gloo::Objs::Cipher.decrypt( data, key, iv ) return JSON.parse( data ) end |
#encrypt_encode(data) ⇒ Object
Encrypt and encode the session data.
109 110 111 |
# File 'lib/gloo/web_svr/session.rb', line 109 def encrypt_encode( data ) return Gloo::Objs::Cipher.encrypt( data.to_json, key, iv ) end |
#iv ⇒ Object
Get the initialization vector for the cipher.
140 141 142 |
# File 'lib/gloo/web_svr/session.rb', line 140 def iv return @server_obj.encryption_iv end |
#key ⇒ Object
Get the key for the encryption cipher.
133 134 135 |
# File 'lib/gloo/web_svr/session.rb', line 133 def key return @server_obj.encryption_key end |
#secure_cookie? ⇒ Boolean
Should the session cookie be secure?
161 162 163 |
# File 'lib/gloo/web_svr/session.rb', line 161 def return @server_obj. end |
#session_name ⇒ Object
Get the session cookie name.
126 127 128 |
# File 'lib/gloo/web_svr/session.rb', line 126 def session_name return @server_obj.session_name end |
#set_session_data_for_request(env) ⇒ Object
Get the session data from the encrypted cookie. Add it to the session container.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gloo/web_svr/session.rb', line 43 def set_session_data_for_request( env ) begin = Rack::Utils.( env ) # Are we using sessions? if @server_obj.use_session? data = [ session_name ] if data data = decode_decrypt( data ) return unless data data.each do |key, value| @server_obj.set_session_var( key, value ) end end end rescue => e @engine.log_exception e end end |