|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Bootstrap issue with AcegiHi All,
I am new to grails and came across this bootstrap issue with grails 1.0 and grails-acegi-0.2. The User object(s) in bootstrap fails to save on initialization but rest of the objects saves ok, not sure if there is anything wrong with code, I cannot see any errors even with hibernate, spring and acegi logging turned on. Details follow, We have a plugin generated acegi classes out of which, User class looks like: class User { static transients = ["pass"] static hasMany=[authorities:Role] static belongsTo = Role /** Username */ String username /** User Real Name*/ String userRealName /** MD5 Password */ String passwd /** enabled */ boolean enabled = false String email boolean email_show = false /** description */ String description /** plain password to create a MD5 password */ String pass="[secret]" static def constraints = { username(blank:false,unique:true) passwd(blank:false) enabled() } } and the bootstrap class looks like, import org.apache.commons.codec.digest.DigestUtils as DU class BootStrap { def init = { servletContext -> def pass = DU.md5Hex("pass") new User(username:"god",passwd:pass,enabled:true).save() new User(username:"admin",passwd:pass,enabled:true).save() new Role(username:"god",description:"Superuser",authority:"ROLE_SUPERUSER").save() new Role(username:"admin",description:"Administrator",authority:"ROLE_ADMINISTRATOR").save() new Requestmap(url:"/captcha/**",configAttribute:"ROLE_SUPERUSER").save() new Requestmap(url:"/register/**",configAttribute:"ROLE_ADMINISTRATOR").save() } def destroy = { } } Please help :) |
|
|
Re: Bootstrap issue with AcegiRealized that it works if you put full set of attributes even if they are not in constraints, not sure what is the reason behind this is. So, the user will save if we change User(...).save() as follows, the next thing I am trying to find out is how to save the authorities along with user, at the moment it does add the user but with no authority.
import org.apache.commons.codec.digest.DigestUtils as DU class BootStrap { def init = { servletContext -> def md5pass = DU.md5Hex("pass") new User(username:"god",userRealName:"god",passwd:md5pass,enabled:true,email:"email@example.com",email_show:true,description:"Desc").save() new User(username:"admin",userRealName:"admin",passwd:md5pass,enabled:true,email:"email@example.com",email_show:true,description:"Desc").save() new Role(username:"god",description:"Superuser",authority:"ROLE_SUPERUSER").save() new Role(username:"admin",description:"Administrator",authority:"ROLE_ADMINISTRATOR").save() new Requestmap(url:"/captcha/**",configAttribute:"ROLE_SUPERUSER").save() new Requestmap(url:"/register/**",configAttribute:"ROLE_ADMINISTRATOR").save() new Product(name:"XT-20",category:"Bike",type:"Fender Eliminators",description:"Fender Eliminators").save() new Product(name:"GT-30",category:"Car",type:"Numberplate Mount",description:"Numberplate Mount").save() new Product(name:"AT-90",category:"Rocket",type:"Square Steering Wheel",description:"Square Steering Wheel").save() } def destroy = { } } |
|
|
Re: Bootstrap issue with AcegiHi all,
Not sure if this is a best way to save the authorities along with the user, but it works, import org.apache.commons.codec.digest.DigestUtils as DU class BootStrap { def init = { servletContext -> def md5pass = DU.md5Hex("pass") def user_god = new User(username:"god",userRealName:"god",passwd:md5pass,enabled:true,email:"email@example.com",email_show:true,description:"Desc").save() def user_admin = new User(username:"admin",userRealName:"admin",passwd:md5pass,enabled:true,email:"email@example.com",email_show:false,description:"Desc").save() def role_superuser = new Role(description:"Superuser",authority:"ROLE_SUPERUSER") role_superuser.addToPeople(user_god) role_superuser.save() def role_administrator = new Role(description:"Administrator",authority:"ROLE_ADMINISTRATOR") role_administrator.addToPeople(user_admin) role_administrator.addToPeople(user_god) role_administrator.save() new Requestmap(url:"/captcha/**",configAttribute:"ROLE_SUPERUSER").save() new Requestmap(url:"/register/**",configAttribute:"ROLE_ADMINISTRATOR").save() new Product(name:"XT-20",category:"Bike",type:"Fender Eliminators",description:"Fender Eliminators").save() new Product(name:"GT-30",category:"Car",type:"Numberplate Mount",description:"Numberplate Mount").save() new Product(name:"AT-90",category:"Rocket",type:"Square Steering Wheel",description:"Square Steering Wheel").save() } def destroy = { } } |
|
|
Re: Bootstrap issue with AcegiOn Feb 12, 2008, at 10:08 PM, Sailesh Ranjit wrote:
> Realized that it works if you put full set of attributes even if > they are not > in constraints, not sure what is the reason behind this is. The nullable constraint defaults to false, although I don't think this is documented anywhere (http://jira.codehaus.org/browse/GRAILS-2160) > So, the user > will save if we change User(...).save() as follows, the next thing I > am > trying to find out is how to save the authorities along with user, > at the > moment it does add the user but with no authority. > > import org.apache.commons.codec.digest.DigestUtils as DU > > class BootStrap { > > def init = { servletContext -> > > def md5pass = DU.md5Hex("pass") > > new > User > (username > :"god",userRealName:"god",passwd:md5pass,enabled:true,email:"email@... > ",email_show:true,description:"Desc").save() > new > User > (username > :"admin",userRealName:"admin",passwd:md5pass,enabled:true,email:"email@... > ",email_show:true,description:"Desc").save() > > new > Role > (username > :"god",description:"Superuser",authority:"ROLE_SUPERUSER").save() > new > Role > (username > :"admin > ",description:"Administrator",authority:"ROLE_ADMINISTRATOR").save() > > new > Requestmap(url:"/captcha/**",configAttribute:"ROLE_SUPERUSER").save() > new > Requestmap(url:"/register/ > **",configAttribute:"ROLE_ADMINISTRATOR").save() > > new Product(name:"XT-20",category:"Bike",type:"Fender > Eliminators",description:"Fender Eliminators").save() > new Product(name:"GT-30",category:"Car",type:"Numberplate > Mount",description:"Numberplate Mount").save() > new Product(name:"AT-90",category:"Rocket",type:"Square > Steering > Wheel",description:"Square Steering Wheel").save() > > } > def destroy = { > } > } > -- > View this message in context: http://www.nabble.com/Bootstrap-issue-with-Acegi-tp15447982p15448450.html > Sent from the grails - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Bootstrap issue with Acegijust a minor improvement
since the hashing-algorithm is a configurable item in the acegy config, maybe you should not use DigestUtils, but instead rely on acegi's authenticateService. you could add def authenticateService to your BootStrap class. then you should be able to replace def md5pass = DU.md5Hex("pass") with def md5pass = authenticateService.passwordEncoder("pass") i prefer to go one step further and put this stuff into a method "changePassword " to my User class. then my bootstrap-code looks like: def user = new User(....).changePassword("pass").save() regards, andi |
| Free embeddable forum powered by Nabble | Forum Help |