Archived

This forum has been archived. Please start a new discussion on GitHub.

Ice Context propagation problem (C++, Java)

Hi !

I play with Ice, it is really nice. Currently, i'm trying to make an authentificaton system. When you have some rights you can/cannot access to a specific method of an interface.

When the user is being authentificated to the Authentification service, it gets a user_key.

This user_key is stored in a context. So each time the user call a method, a check is done to the Authentification service.


The problem that I have is the propagation of the context. I use the implicit/explicit context mechanism:


Imagine that the Authentification service has a sequence with all others generic services:


| Authentification |--1
0..n-| Generic Service |

| string login(us,pswd)|
| getServices () |


So the user connect to the authentification service. Next it calls the login method that returns the user key.
At this point i have the user key, A User can call the getServices only if it is already identified. So to do it,

I add the user key to the context (Client side in Java, Server side in C++ VS2005):


String key = authManager.login(getLogin(), getPassword());

// Here we have the connection id and we add it to the context
java.util.Map ctx = ic.getDefaultContext();
ctx.put("my_key", key);
mAuthentificationManager = hdg.authentification.IManagerPrxHelper.uncheckedCast(authManager.ice_newContext(ctx));

So at this point, the mAuthentificationManager should have an implicit context. So every time i use a method of the mAuthentificationManager
proxy the context should be preset.


So for now, all are ok.

Now i'm calling the getServices (), the user can call this method because the implicit context contains its key. However, I would like that
all GenericService proxy returned by the getServices have the same context.

So the getServices method looks like that (Server side in C++):


::hdg::service::IAbstractManagerSeq AuthentificationI::getServices(const ::Ice::Current& cur) {

checkRightPermission (AdminRight, cur);

hdg::service::IAbstractManagerSeq seq;

for (hdg::service::IAbstractManagerSeq::iterator it = m_services.begin (); it != m_services.end (); ++it) {

hdg::service::IAbstractManagerPrx service = hdg::service::IAbstractManagerPrx::uncheckedCast((*it)->ice_newContext (cur.ctx));

// just make the affectation to debug and see the contents of the context.
Ice::Context ctx = service->ice_getContext ();

seq.push_back (service);
}
return seq;
}


At this point, each generic service proxy has the context of the proxy caller of the getServices method.

However, the problem comes from the java part, in fact, when i get the result of the getServices method, i get all generic service proxies
without the context. The ice_context of all returned generic service proxies are empty.


Maybe i've missed something,

Can you help me ?

Thank you.

Comments

  • mes
    mes California
    Hi,

    Ice is behaving as expected; the context is a strictly local setting, therefore any context values defined for a proxy do not accompany that proxy when it is marshaled and sent to another process. However, if you replace the communicator's default context using Communicator.setDefaultContext, then any proxy subsequently received by the application will automatically use your new default context.

    Hope that helps,
    - Mark
  • Thank you Mes !

    Of course, it helps :p

    Joel