Class: CASClient::Tickets::Storage::LocalDirTicketStore
- Inherits:
-
AbstractTicketStore
- Object
- AbstractTicketStore
- CASClient::Tickets::Storage::LocalDirTicketStore
- Defined in:
- lib/casclient/tickets/storage.rb
Overview
A Ticket Store that keeps it’s tickets in a directory on the local filesystem. Service tickets are stored under tmp/sessions by default and Proxy Granting Tickets and their IOUs are stored in tmp/cas_pgt.pstore This Ticket Store works fine for small sites but will most likely have concurrency problems under heavy load. It also requires that all your worker processes have access to a shared file system.
This ticket store takes the following config parameters :storage_dir - The directory to store data in. Defaults to Rails.root/tmp :service_session_lookup_dir - The directory to store Service Ticket/Session ID files in. Defaults to :storage_dir/sessions :pgt_store_path - The location to store the pgt PStore file. Defaults to :storage_dir/cas_pgt.pstore
Instance Attribute Summary
Attributes inherited from AbstractTicketStore
Instance Method Summary collapse
-
#cleanup_service_session_lookup(st) ⇒ Object
Removes a stored relationship between a ServiceTicket and a local Rails session id.
-
#initialize(config = {}) ⇒ LocalDirTicketStore
constructor
A new instance of LocalDirTicketStore.
-
#read_service_session_lookup(st) ⇒ Object
Returns the local Rails session ID corresponding to the given ServiceTicket.
- #retrieve_pgt(pgt_iou) ⇒ Object
- #save_pgt_iou(pgt_iou, pgt) ⇒ Object
-
#store_service_session_lookup(st, controller) ⇒ Object
Creates a file in tmp/sessions linking a SessionTicket with the local Rails session id.
Methods inherited from AbstractTicketStore
#get_session_for_service_ticket, #process_single_sign_out
Constructor Details
#initialize(config = {}) ⇒ LocalDirTicketStore
Returns a new instance of LocalDirTicketStore.
72 73 74 75 76 77 78 |
# File 'lib/casclient/tickets/storage.rb', line 72 def initialize(config={}) config ||= {} default_tmp_dir = defined?(Rails.root) ? "#{Rails.root}/tmp" : "#{Dir.pwd}/tmp" @tmp_dir = config[:storage_dir] || default_tmp_dir @service_session_lookup_dir = config[:service_session_lookup_dir] || "#{@tmp_dir}/sessions" @pgt_store_path = config[:pgt_store_path] || "#{@tmp_dir}/cas_pgt.pstore" end |
Instance Method Details
#cleanup_service_session_lookup(st) ⇒ Object
Removes a stored relationship between a ServiceTicket and a local Rails session id. This should be called when the session is being closed.
See #store_service_session_lookup.
115 116 117 118 119 120 121 |
# File 'lib/casclient/tickets/storage.rb', line 115 def cleanup_service_session_lookup(st) raise CASException, "No service_ticket specified." unless st st = st.ticket if st.kind_of? ServiceTicket ssl_filename = filename_of_service_session_lookup(st) File.delete(ssl_filename) if File.exists?(ssl_filename) end |
#read_service_session_lookup(st) ⇒ Object
Returns the local Rails session ID corresponding to the given ServiceTicket. This is done by reading the contents of the cas_sess.<session ticket> file created in a prior call to #store_service_session_lookup.
102 103 104 105 106 107 108 |
# File 'lib/casclient/tickets/storage.rb', line 102 def read_service_session_lookup(st) raise CASException, "No service_ticket specified." unless st st = st.ticket if st.kind_of? ServiceTicket ssl_filename = filename_of_service_session_lookup(st) return File.exists?(ssl_filename) && IO.read(ssl_filename) end |
#retrieve_pgt(pgt_iou) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/casclient/tickets/storage.rb', line 132 def retrieve_pgt(pgt_iou) raise CASException, "No pgt_iou specified. Cannot retrieve the pgt." unless pgt_iou pstore = open_pstore pgt = nil pstore.transaction do pgt = pstore[pgt_iou] end raise CASException, "Invalid pgt_iou specified. Perhaps this pgt has already been retrieved?" unless pgt # TODO: need to periodically clean the storage, otherwise it will just keep growing pstore.transaction do pstore.delete pgt_iou end pgt end |
#save_pgt_iou(pgt_iou, pgt) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/casclient/tickets/storage.rb', line 123 def save_pgt_iou(pgt_iou, pgt) # TODO: pstore contents should probably be encrypted... pstore = open_pstore pstore.transaction do pstore[pgt_iou] = pgt end end |
#store_service_session_lookup(st, controller) ⇒ Object
Creates a file in tmp/sessions linking a SessionTicket with the local Rails session id. The file is named cas_sess.<session ticket> and its text contents is the corresponding Rails session id. Returns the filename of the lookup file created.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/casclient/tickets/storage.rb', line 85 def store_service_session_lookup(st, controller) raise CASException, "No service_ticket specified." unless st raise CASException, "No controller specified." unless controller sid = controller.request.[:id] || controller.session.session_id st = st.ticket if st.kind_of? ServiceTicket f = File.new(filename_of_service_session_lookup(st), 'w') f.write(sid) f.close return f.path end |