-
Notifications
You must be signed in to change notification settings - Fork 749
Understanding Mifos Platform
One of the key concepts of the mifos x project is:
- The split between platform responsibilities and client applications built on top of the platform.
This page discusses the interesting parts of the platform responsibilities.
The key topics to talk about are:
- RESTful API
- Multi-tenant support
The RESTful API is the public contract of the platform with the outside world. The goal of this API is to empower developers to quickly get up to speed with the API so they can support:
- Client application development on top of platform
- Integrate other applications/systems with the platform capabilities
This API can be described as:
- resource-oriented: There is a set of resources applicable to the application domain (users, roles etc) and the domain of microfinance (clients, loans etc) but it is not an attempt at pure REST.
Some might say its:
- service-oriented: You can look on the API as a clear defined set of services but it not an attempt at pure SOA.
Simply put:
- The RESTful API is a simple and pragmatic way of exposing the capabilities of the platform that are of use to client application developers and systems integrators.
You can find published documentation on the API at https://ec2-46-137-62-163.eu-west-1.compute.amazonaws.com:8443/api-docs/apiLive.htm
- The API only accepts and returns JSON.
- The API is JAX-RS compliant and uses Jersey (http://jersey.java.net/) as the JAX-RS implementation
- As the API is RESTful, CRUD operations are exposed through HTTP's @POST,@GET,@PUT,@DELETE
- The API is secured using BASIC Auth (Spring security is the implementation technology used to enforce basic auth on platform)
- As the platform is RESTful, it is stateless and every request to the platform requires credentials so authentication and authorization checks can be done. As such there is no session concept. Horizontal scaling is a breeze if need be.
The java class org.mifosng.platform.infrastructure.TenantAwareBasicAuthenticationFilter
is the most interesting entry point for every request coming into the platform. If you were debugging the platform, every qualifying request should reach this point.
An example resource would be org.mifosng.platform.api.LoanProductsApiResource
.
The @Path("/loanproducts")
indicates that this resouces is invoked when requests match https://localhost:8443/mifosng-provider/api/v1/loanproducts
URL.
MifosX platform has support for hosting multiple tenants in seperate schemas and serving their data through the one running server application.
For storing information relevant to all the platform tenants we use the mifosplatform-tenants
database which has one table in it for now tenants
.
The java class org.mifosng.platform.infrastructure.TenantAwareBasicAuthenticationFilter
is responsible for checking each request to see if it has a tenant identifer in it to determine against which schema the request should be processed. There are two ways to pass this tenant information:
- As a request header - A header named
X-Mifos-Platform-TenantId
is looked for e.g.X-Mifos-Platform-TenantId: default
- If the request header doesnt exist, a check is done for a query parameter named
tenantIdentifier
e.g.tenantIdentifier=default
If multi-tenant details supplied are valid (exist in tenants database), we use the details supplied on the mifosplatform-tenants
database to know what schema we should connect with for this request. These details are stored in a ThreadLocal
variable so they can be got at later on in the request when needed by other parts of code.
The Java class org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource
is responsible for routing or delegating the process of getting a connection to the correct schema.
It will return a new or existing pooled connection datasource based on the tenant identifier that was provided in the given request.