How to get current user in servant object's method?

in Help Center
Hi, I use Glacier2 as router, and develope a client program to login the router to locate the servant object in order to invoke it's method. Now I need to get the current user in the method, will anybody help me how to?
thanks.
thanks.
0
Comments
You can use Glacier2 sessions to keep track of the user Id. See the Glacier2 demos included with your distribution for some examples (in the demo/Glacier2 directory). Let us know if you need more information.
Cheers,
Benoit.
I had find a way to resolve this problem, but I don't know it's OK or not, so I share it to the public:
(1)At the server site, start a SessionServer program for Glacier2Router to validate the login user, if the user login OK, then store User_ID and Session_ID to a Database(or a shared cache), and here is my Java code: (2) At client Site, when client success to login and acquire the instance of Glacier2.SessionPrx, put Session_ID to DefaultContext, and Here is my Java Code:
(3) At the server site, when client application send a invoke request to the Servant's method, it will auto send Session_ID to the server, the server application now can acquire Session_ID, and then query the database to find out the login user. Here is my code: (4) When client program logout, remove Session_ID from SessionI's destroy method:
I had tested it this morning(Beijing Time Zone), and it seems that everything is OK, but Communicator.setDefaultContext is deprecated, what method should I use, and how?
Thanks.
This is a Eclipse RCP application using Ice as communication layer. It has the folowing features:
(1) start/stop/restart bundle.
(2) group bundle.
(3) view log file.
(4) config the bundle's runtime parameter and restart it.
(5) upload bundle to remote server(not implement).
(6) permission check(not implement).
You can use implicit contexts as a replacement for setDefaultContext, see here in the Ice manual for more information on implicit contexts.
Instead of passing the session id in the request context, why don't you just pass the user id? I suppose it's to ensure that another client can't steal the identity of another client? While using a UUID is safer, it could still be guessed (see this recent thread). If you want to make sure this can't happen, a better approach would be to setup a servant per session on the server side, this servant would cache the user ID and would not rely on any client hints to retrieve it.
Cheers,
Benoit.
It seems that UUID generator is not safe since it can be guessed.
Now I use another UUID genrator:
I test it and it is OK. I use MD5 to encode the timestamp and another password, now you can guess the timestamp, but you can't the generate MD5 code, so I think it's safe.
If MD5 is not safe, I can use RSA to replace it:
(1) At the server site, the server program use it RSA PRIVATE KEY to encode a timestamp, and use the encoded string as object_id which can be transform to Session_ID.
(2) At the client site, the client program use server's RSA PUBLIC KEY to validate the object id.
(3) When client send object id back to the server, the server can also validate the object id.
So, now do you think is OK?
By using per-session servants on the server side and appropriate Glacier2 filtering, you can have the guarantee that only the client which established a given session is invoking on a given Ice object.
Cheers,
Benoit.