hi.

I've a multi-tenant restlet application that perform authentication and some
authorization towards cloud services. I'm going to make it work for multiple
applications at a time, each of them being multi tenant. Thus I have only
one authn/authz server instance.

The multi-tenancy now is achieved the simple way: the tenant parameter on
the URL percolate all through the services layer to the repository one as a
parameter. That's not that bad, in the end.
Now I want to add multi-app support without touching the code of the
Resources and the spring xml that loads everyghing: the restlet app, router,
the resources (using a SpringBeanRouter) and all the app services and spring
security stuff.

I'm thinking storing data on a different db (with it's own credentials) for
each hosted app.
Given that the class that write/read on mongo (MongoTemplate) is autowired
to different services, it will be a lot of work to change it. I can change
the MongoTemplate with a MongoTemplateFactory, but again I need thea  app
parameter to percolate till that level.

I think that given that the actual spring context works nice for a single
app, I should go in a direction where I can load as many spring context as
many host application my REST Resource is managing and inject the classes
from the right context when I init a Resource. What do you think?


Now, I only have a .properties file that defines the mongo host, db and so
on. Let's make it simple and try to figure out a scenario with a fixed
number of applications, two, so I can just have say two different properties
file app1.properties and app2.properties with appropriate mongo parameters.

What I want is that when a restlet Resource is loaded, the correct spring
bean is taken from the right ApplicationContext. Something like in a
BaseReource class that extends ServerResource and is extended by all the
other resources:

@Override
   protected void doInit() throws ResourceException {
      String app = (String) getRequestAttributes().get("app");
      ApplicationContext context = springContextFactory.get(app);
      inject(context, this);
      super.doInit();
   }

Now, I have no idea of how to achieve this, or if in any way this could
work, expecially with the SpringBeanRouter. Anyone here have some clue? Also
"hey this solution make no sense" is an answer that I'll consider of course
:)

In this scenario,

1. the springContextFactory is something I made up, that would take the app
parameter, use it to load a whole set of spring xml files with the
appropriate placeholder.
2. the restlet spring beans are more tricky. The server (host, port...) so
is the component defined as

  <bean id="restletComponent" class="org.restlet.ext.spring.SpringComponent"
init-method="start" destroy-method="stop">
    <property name="server" ref="server" />
    <property name="defaultTarget" ref="application" />
  </bean>

the ref=application there is my actual restlet application.
Now I thought I could have different target, one per hostet application, but
probably I do not need this.

I think that I just have to split the restlet app spring configuration from
the services layer and the rest of the stuff. Cause the restlet server,
component, application, router and resources are fine the way they are.
If in the doInit method of the BaseResource I can load dynamically the rest
of the spring context and perform a "manual" injection of the needed beans
inside the actual Resource. So all the component-application-beanRouter
stuff should work as normal, just every resource is loaded with the right
app spring context.
Probably I also have to change the mount path from

<bean name="/accounts" class="AccountsResource" id="accounts"
scope="prototype"/>

to

<bean name="{app}/accounts" class="AccountsResource" id="accounts"
scope="prototype"/>

What do you think?
I know that most of the problem is more close to spring multi context
scenario, but being this basically a Restlet app I'd like to listen your
opinion, maybe I'm making some basic mistake.

Thanks for reading all of the long message.

-- 
Daniele Dellafiore
http://danieledellafiore.net

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2719456

Reply via email to