Acegi – Security Plugin for Grails
Acegi is the security plugin which enables features like role-based access for Grails.As opposed to Struts where we need to make changes in struts-config.xml and override the processRoles() function in the controller class,here we only have to include the plugin in our project using groovy commands or we can install plugin when we are using IDEs like netbeans and everything is configurable.Steps are listed below when netbeans ide is being used :
Step-1
Right click the project to click on ‘Grails Plugins ‘ tab.
Then click the ‘New Plugins’ tab to list all the available Plugins.
Install Plugin named with ‘webflow’.
Install “acegi†plugin.
Step-2
Run “create-auth-domain-classes†command with User,Role and RequestMap class names as parameters.This command will create the three domain classes required.The classes look as folows :
class User {
static transients = [‘pass’]
static hasMany = [authorities: Role]
static belongsTo = Role
static mapping = {table ‘loginuser’}
/** Username */
String username
/** User Real Name*/
String userRealName
/** MD5 Password */
String passwd
/** enabled */
boolean enabled
String email
boolean emailShow
/** description */
String description = ”
/** plain password to create a MD5 password */
String pass = ‘[secret]’
static constraints = {
username(blank: false, unique: true)
userRealName(blank: false)
passwd(blank: false)
enabled()
}
}
/** Authority domain class.
*/
class Role {
static hasMany = [people: User]
/** description */
String description
/** ROLE String */
String authority
static mapping = {table ‘loginrole’}
static constraints = {
authority(blank: false, unique: true)
description()
}
}
/**
* Request Map domain class.
*/
class RequestMap {
String url
String configAttribute
String module
def listArr = []
boolean readval
boolean editval
static transients = [‘module’,’readval’,’editval’,’listArr’]
static constraints = {
url(blank: false, unique: true)
configAttribute(blank: false)
}
}
Step-3
Run “generate-manager†command to create the controllers and views
Having performed the above mentioned steps,when we run the project we can find all the three controller links and we can configure role mappings from “RequestMap†controller for the URLs to be accessed by which comma separated values for roles provided that the role is already present.
Having configured the role map, and that URL is mapped with a role in RequestMap, we can see that the login page appears when a particular URL is accessed.
Related posts:
Tags: Groovy on Grails
This entry was posted on Thursday, September 30th, 2010 at 8:02 am and is filed under Java. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.