tags:

views:

46

answers:

2

Hello,

I am designing an enterprise security server for our company - we own many different applications, most written in java and a few written in PHP. I could provide a remote API that would give each application access to the server. I could also create 'agents' that each application could include that would do all the work for them, but allow my server control over their sessions and thus their authentications/authorizations. Issue is I would probably be better to write the agent in java because 80% or more of our apps are in java.

If I wrote the agent in java does anyone know if there was a way this program could access the php session? If not does anyone have a suggestion regarding a better way to go about doing this?

+1  A: 

You can hook into PHP's session handling using session_set_save_handler() (an example for a simple but complete custom handler is included in the manual). You should be able to synchronize PHP's session management with a central Java server that way.

Your PHP application would receive a session ID through a cookie ($_COOKIE["SESSION_ID"] or whatever).

Your custom session_save_handler would, instead of maintaining a session store of its own, pass that session ID to your central Java-based security server, and get all the session data in return. Writing into a session from PHP would be routed the same way.

You could of course also go the other way, and poll PHP's internal session data from the outside, but wouldn't quite understand what exactly for. If that is the case, can you go into more detail there?

Pekka
Well - I wanted to have access to the session in order to implement synchronous updates to the user's security roles - i.e. if its discovered the user is a closet criminal and is stealing financial data, it should be easy to log into a security interface and switch the user 'off' - i could leave it up to the app to call 'home' on each sensitive call or, having access to the session, yank the credential out from underneath them and on the next request the user is thrown back to the login portal, unable to access anything.
Matt1776
In that case, I think using a session handler that is connected to your portal is the better way. Authentication (association a session with a user record) would take place in Java, and the second you turn a session off in the Java server, it is gone in PHP as well.
Pekka
A: 

The session data is stored as a (php) serialized array in a temporary folder. The locations for these are set in the php.ini file.

But you can change both the format of the data and the place it is stored (e.g. to a database or shared memory or somewhere else) by writing your own handler.

A quick google suggests that several people have written [de]serializers in Java for PHP data. e.g. http://hurring.com/scott/code/java/serialize/

If you have problems with the built-in PHP serialize function - have a google for WDDX (which IIRC comes as standard) and serializes data into XML.

You might want to think about how you keep the session data appearing to be active to PHP if you want the agent to continue independently of the web session.

C.

symcbean
Thank you - esp. did not know about ability to change session format from ini - good to know.
Matt1776