Question

I'm learning Java RMI and I'm trying to do an assignment which requires me to have two different client types interacting with the same server.

One of the two clients has more privleges than the other one, and this means that the first one is the only one that can call a certain method.

Let's make a quick sample:

we have 3 classes:

  • Server
  • AdminClient
  • UserClient

Server exports a method called doSomething() which cannot be called from UserClient but only from AdminClient.

Is there a way to do something like this?

I know that, since I'm writing the code, it's quite easy to write the UserClient and stop him from calling that method, but I'm asking more something on server-side security, provided that the client's code can be modified to call doSomething().

The doSomething() should be like:

void doSomething(){
    Class caller = getCaller().getClass();
    if (caller instanceof UserClient) return;
    ...
}
Was it helpful?

Solution

You can't. Your server won't know who the remote client is.

I suggest placing your domain logic behind 2 different remote services, one implementing a UserInterface and one implementing an AdminInterface. Hand out the UserInterface stub to the UserClient, hand out the AdminInterface stub to the AdminClient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top