restletrestlet-2.0

Extending Restlet 2.3 ClientInfo


Is it possible to extend org.restlet.data.ClientInfo? I need a convenient way of adding a List<String> permissions to complement the existing List<Role> roles. In a perfect world I would be able to add List<Permission> permissions but the former is perfectly acceptable.

I need to be able to get this from the request: org.restlet.resource.Resource.getRequest().getClientInfo().getPermissions()


Solution

  • I don't think that it's possible to add something within the class ClientInfo since it's a class that is managed by the Restlet engine. You can't subclass it to add a field permissions (you don't have the hand on the client info instantiation).

    That said, you can leverage the context attributes. I mean that you can fill within your Enroler implementation an attribute permissions for the request, as described below:

    public class MyEnroler implements Enroler {
        private Application application;
    
        public MyEnroler(Application application) {
            this.application = application;
        }
    
        public void enrole(ClientInfo clientInfo) {
            // Roles
            Role role = new Role(application, "roleId",
                        "Role name");
            clientInfo.getRoles().add(role);
    
            // Permissions
            Request request = Request.getCurrent();
            List<Permission> permissions = new ArrayList<Permission>();
            request.getAttributes().put("permissions", permissions);
    
            Permission permission = (...)
            permissions.add(permission);
    }
    

    Hope it helps you, Thierry