Allowing or denying self registration with grails-acegi plugin

The grails-acegi-0.2 plugin is great - it adds login, user management, and user registration capabilities to your application in seconds. However, I'm building a web application where I want to be able to let the deployment team decide whether users can register themselves or alternatively, have an administrator create users. I want provide these settings without the deployment unit (the WAR file) having to be modified.

I currently have a properties file for each server (DEV, STAGE, PROD) which defines properties specific to the environment - such as the email server and username/password etc. In this properties file, I also have application settings which are relevant to that environment. So, this is a good place to define a property:


Grails has an excellent configuration strategy, and in my applications Config.groovy all I have to do is specify the external config locations:

grails.config.locations = ["file:${System.getProperty('')}"]

I've referenced a system property, so anyone deploying my application just needs to use the -D jvm option - when running with grails all we have to do is:


Now I just need to modify the RegistrationController.groovy to check this property:

def index = {
//if logon user.
if(authenticateService.userDomain()!=null){"${authenticateService.userDomain()} user hit the register page")

if(!(grailsApplication.config.jtchat.registration.enabled=='false')) {
def person = new Person() = params
return ['person': person]
} else {

And that's it. An easy way to provide settings to an application without modifying the WAR. Grails rocks!

Popular posts from this blog

Using the Crystal Reports Java API to generate PDF

No Scope registered for scope request

Using Selenium WebDriver to select JSF/PrimeFaces selectOneMenu options