Tuesday, January 20, 2009

Integrate Acegi(0.5.1) with Grails

Recently we try to integrate Acegi(0.5.1) into the grails. We follow the document:

http://docs.codehaus.org/display/GRAILS/AcegiSecurity+Plugin+-+Basic+Tutorial

However, this document is not updated with the latest Acegi. You need pay attention to several issue when you create role, requestmap. Otherwise, it will not work for your.

When you create a role, the role name should include "ROLE" (case sensitive): i.e: ROLE_admin. And this is the quick steps to plugin acegi into your grails project:

1.1: Install the Acegi plugin

> grails install-plugin acegi

1.2: CREATE THE USER, ROLE, AND REQUESTMAP DOMAIN CLASSES

> grails create-auth-domains User Role Requestmap

1.3: OPTIONAL - CREATE CONTROLLERS AND GSPS FOR USER, ROLE, AND REQUESTMAP DOMAIN CLASSES

> grails generate-manager

1.4: OPTIONAL - CREATE CONTROLLERS AND GSPS FOR CAPTCHA, REGISTER, AND AN EMAILER SERVICE.

> grails generate-registration

1.5: CREATE A CONTROLLER THAT WILL BE RESTRICTED BY ROLE

> grails create-controller Secure

2.1: Create role

http://localhost:8080/demo/role
attention - And role name should be start with "ROLE" - i.e: ROLE_ADMIN, ROLE_USER

2.2: Create user

http://localhost:8080/demo/user

2.3: create url request map

http://localhost:8080/demo/requestmap
please add the following url:

/user/** /role/** /adminpage/** /requestmap/**
ROLE_ADMIN

2.4: login to admin page

http://localhost:8080/demo/adminpage

Friday, January 16, 2009

Grails JasperReport plugin

Recently we start to play with Jasper plugin for Grails (version 1.0.4), and we did not have lucky to make it work - we use comment line "grails install-plugin jasper" (version 0.9). We always end with this kind of error - my poor hair:
at net.sf.jasperreports.engine.JRPropertiesMap.readObject(JRPropertiesMap.java:185)
After look around for a while, it seems the grails plugin jasper report library version is too old, and it somehow does not work under this version of Grails.

After update to the latest version of jasperReport and iText

iText-2.1.4.jar
jasperreports-3.1.3.jar


and put it into plugins/japser-0.9/lib, now I can generate the PDF file.

And if you are using the latest iReport, you also need pay attention to the xml format of .jrxml. Please follow the example .jrxml to generated your .jasper file.