Find ActiveRecord Session by session_id

Hi

We are in the process of integrating a Java web application with our
existing Rails application. The user logs into the Rails application and
will at some point proceed to the Java part, now the Java application
should not ask the user to re-login and in order to do this we would
like to copy the Ruby session object over to Java by looking up the
session cookie sent by the browser and retrieving the session record
from the sessions table. (both the java and ruby applications are on the
same domain and have access to the same cookies)

Our Rails application uses ActiveRecordStore for session storage using
all default parameters. So I have a sessions table with id, session_id,
data, created_at, updated_at columns. And the session_id is the value
stored in our session cookie.

Here is the configuration from config/environment.rb:

#session key for session cookie data integrity
config.action_controller.session = {
:session_key => ‘my_app_session’,
:secret => ‘some_secret_key’
}

config.action_controller.session_store = :active_record_store

Problem:
Once a request comes to the Java server, the Java application calls the
Ruby application passing to it the session_id that it obtained from the
common session cookie. Now the PROBLEM is my session’s are based on:
ActionController::Session::AbstractStore::SessionHash and the
ActionController::Session::AbstractStore class does not support a
find_by_session_id method or any other such methods. So I am unable to
search for a particular user’s session object from amongst the many
sessions that are created for all users of my application.

Searching Google has given me this:

@user=CGI::Session::ActiveRecordStore::Session.find_by_session_id(@session_id).data[:user]

which does not work either. It throws an error saying: NameError
(uninitialized constant CGI::Session::ActiveRecordStore):

I am probably guessing that is because CGI::Session::ActiveRecordStore
is a different class than ActionController::Session::AbstractStore which
my application uses.

My question is how can I search for a session object that is associated
with a particular session_id. The sessions table is not exposed as a
Model object hence I cannot use any kind of find method on it. There is
a find method but it comes back with a 404 response code.

Any response will be greatly appreciated.

On Aug 19, 4:40 am, Engine Y. [email protected]
wrote:

Searching Google has given me this:

@user=CGI::Session::ActiveRecordStore::Session.find_by_session_id(@session_ id).data[:user]

That would have worked pre rails 2.3

which does not work either. It throws an error saying: NameError
(uninitialized constant CGI::Session::ActiveRecordStore):

I am probably guessing that is because CGI::Session::ActiveRecordStore
is a different class than ActionController::Session::AbstractStore which
my application uses.

The corresponding active record class is now
ActiveRecord::SessionStore::Session

Fred

Solved it, by using Raw SQL query to fetch the needed session object.
But decoding the base 64 encoded data gives some extra characters.