Sharing Session information between Rails (Jruby) and Java code in Tomcat/JBoss

View: New views
3 Messages — Rating Filter:   Alert me  

Sharing Session information between Rails (Jruby) and Java code in Tomcat/JBoss

by Brian Anderson-9 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Our project had a requirement that we run our Ruby application in the
same context as our Java application so that we can share
authentication data. We wanted to be able to have our users log in
once and then seamlessly hop between the Rails app and the Java app.
In order to read the java session (and check if they are logged in) we
had to do the following:

request.instance_variable_get("@session_options_with_string_keys")['java_request'].getSession(true).getAttribute('sessionBean')

We discovered this after we read the blog post at:
http://twentyseveneighteen.org/2007/11/27/jrubyonrails-on-ibm-websphere-application-server-using-ibm-db2/.
Ours is slightly different because we were using Tomcat.

Anyway, so what I am curious is:
Does anyone else have this need/problem to share session data? Is
there a less tricky way of doing this?

-Brian

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: Sharing Session information between Rails (Jruby) and Java code in Tomcat/JBoss

by Robert Egglestone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Brian,

When a container does authentication, the user name is usually passed
using request.getRemoteUser to servlets.
We make this available to Ruby on Rails as @request.env['REMOTE_USER'],
in the same way that Apache does.

If you need direct access to the session, you could use
$java_servlet_request to get the servlet request.

Cheers,
Robert

Brian Anderson wrote:

> Our project had a requirement that we run our Ruby application in the
> same context as our Java application so that we can share
> authentication data. We wanted to be able to have our users log in
> once and then seamlessly hop between the Rails app and the Java app.
> In order to read the java session (and check if they are logged in) we
> had to do the following:
>
> request.instance_variable_get("@session_options_with_string_keys")['java_request'].getSession(true).getAttribute('sessionBean')
>
> We discovered this after we read the blog post at:
> http://twentyseveneighteen.org/2007/11/27/jrubyonrails-on-ibm-websphere-application-server-using-ibm-db2/.
> Ours is slightly different because we were using Tomcat.
>
> Anyway, so what I am curious is:
> Does anyone else have this need/problem to share session data? Is
> there a less tricky way of doing this?
>
> -Brian
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>  

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: Sharing Session information between Rails (Jruby) and Java code in Tomcat/JBoss

by Brian Anderson-9 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Robert thanks for the response,

> When a container does authentication, the user name is usually passed
> using request.getRemoteUser to servlets.

This is for standard HTTP Authentication, correct? I should have
clarified that we have own user system that is based of of a web
login-form and then write some info to the session about who they are
and when their login will time out. So we are not using HTTP Auth.

> If you need direct access to the session, you could use
> $java_servlet_request to get the servlet request.

Oh this will simplify our code quite a bit! I'll give it a try!

-Brian

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email