Archived

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

How to implement a Glacier2.PermissionsVerifier in C#

Hi!

I am trying to implement the C++ chat server from the demos in C#.

When I implement a class deriving from the Glacier2.PermissionsVerifier interface the compiler forces me to implement ALL the methods of the Glacier2.PermissionsVerifier interface. I guess this is not so strange, after all what is the purpose of interfaces if not to be implemented?

In the C++ example it suffices to implement the checkPermissions method, which is really sweet.

As I tried to understand the difference between the C++ and the C# environments, I see that in C++ PermissionsVerifier derives from the Ice::Object CLASS (there are some more definitions!), whereas in C# it derives from System.Object CLASS and implements 3 other INTERFACES. Somehow, magically, it also derives from the abstract Ice.Object INTERFACE, and, no wonder, most of the methods which the compiler forces me to implement are defined in Ice.Object. But together with the definition of Ice.Object, I see that there is also an implementation of the methods of Ice.Object in the Ice.ObjectImpl CLASS. I guess this corresponds to the C++ implementation of Ice.Object in file Object.cpp.

So I wonder how can I avail myself of the implementation of Ice.ObjectImpl in implementing the Glacier2.PermissionsVerifier? I have the feeling that the implementation given in Ice.ObjectImpl to most of the methods would suffice in many situations, and, just as in the C++ example it should be enough to override the checkPermissions(..) method and let Ice.ObjectImpl do most of the job.

This is my attempt which wouldn't compile until I implement all the methods:
class DummyPermissionsVerifierI : Glacier2.PermissionsVerifier
{
    bool checkPermissions(string userID, string password, Ice.Current current)
    {
        Console.WriteLine("verified user '" + userID + "' with password '" + password + "'");
        return true;
    }
}

Since Ice.ObjectImpl is an abstract class, I tried to inherit from it, like this:
class DummyPermissionsVerifierI : Ice.ObjectImpl, Glacier2.PermissionsVerifier
{
    bool checkPermissions(string userID, string password, Ice.Current current)
    {
        Console.WriteLine("verified user '" + userID + "' with password '" + password + "'");
        return true;
    }
}

While this would satisfy the compiler, Glacier would not start any more:

C:\catalin\chatServer\exe>glacier2router --Ice.Config=config.glacier2
!! 12/13/12 19:23:23.420 glacier2router: error: permissions verifier `DummyPermi
ssionsVerifier:tcp -h 127.0.0.1 -p 10001' is invalid

Can anyone point me in the right direction here? I guess I do not master C# enough to understand how to implement this interface in the proper way.

Thanks,
Catalin

Comments

  • xdm
    xdm La Coruña, Spain
    Hi,

    Basically the problem is that you are using the wrong base class. You should be using Glacier2.PermissionsVerifierDisp_ as the base class for your servant implementation.

    See: Server-Side C-Sharp Mapping for Interfaces - Ice 3.4 - ZeroC

    In your implementation the signature of checkPermissions operation isn't right, the reason out parameter is missing.

    It should be something like:
    class DummyPermissionsVerifierI : Glacier2.PermissionsVerifierDisp_
    {
        override
        public bool checkPermissions(string userID, string password, out string reason, Ice.Current current)
        {
            Console.WriteLine("verified user '" + userID + "' with password '" + password + "'");
            reason = "";
            return true;
        }
    }