Search This Blog

Wednesday, December 8, 2010

Grails and multi tenancy - Multi tenancy setup with grails




I was playing with multi tenancy setup with grails.
While there were some examples I found most them were old and werent updated for recent grails versions.
Ran into a bunch of errors when I tried to use multitenancy plugin with spring security.
Had to try out a few things before i was able to correct all the errors and get this working.
I try here to give a step by step guide to setting up multitenancy for grails based apps.

Create a simple domain class
grails create-domain-class com.helloworld.Message

install spring security plugin
>grails install-plugin spring-security-core

Create the user and roles
grails s2-quickstart org.racetrack User Role

Install multitenant plugin
grails install-plugin multi-tenant

install Multi-Tenant Spring Security Integration
grails install-plugin multi-tenant-spring-security

Add to config.groovy
tenant {
mode = "multiTenant" // "singleTenant" OR "multiTenant"
datasourceResolver.type = "db"
resolver {
type = "request"
resolver.request.dns.type = "db"
request.dns.type = "db"
}
}


Annotate domain classes that are to be shared after importing Multitenat annotation
import com.infusion.tenant.groovy.compiler.MultiTenant;

@MultiTenant

Add to the User Class
/** for multi-tenant-acegi plugin **/
Integer userTenantId
Add the following constraints 
// Existing constraints
userTenantId(min: 0)
Create a dns map table
grails create-dns-map
Now with all the setup in place you should be able to run your app with multitenancy setup.


No comments:

Post a Comment