Grails spring security not working: Local Auth (No LDAP) -
i trying log in database user created in bootstrap file, keep getting error: sorry, not able find user username , password.
i've checked various tutorials working 2.4 plugin of spring, , don't know i'm missing.
please me...i need figure out :s
my models are:
user:
class user { transient springsecurityservice string username string password boolean enabled = true boolean accountexpired boolean accountlocked boolean passwordexpired static transients = ['springsecurityservice'] static constraints = { username blank: false, unique: true password blank: false } static mapping = { password column: '`password`' } set<role> getauthorities() { userrole.findallbyuser(this).collect { it.role } set } def beforeinsert() { encodepassword() } def beforeupdate() { if (isdirty('password')) { encodepassword() } } string tostring() { return username } protected void encodepassword() { password = springsecurityservice?.passwordencoder springsecurityservice.encodepassword(password) : password }
}
role:
class role {
string authority static mapping = { cache true } static constraints = { authority blank: false, unique: true }
}
userrole:
class userrole implements serializable { private static final long serialversionuid = 1 user user role role boolean equals(other) { if (!(other instanceof userrole)) { return false } other.user?.id == user?.id && other.role?.id == role?.id } int hashcode() { def builder = new hashcodebuilder() if (user) builder.append(user.id) if (role) builder.append(role.id) builder.tohashcode() } static userrole get(long userid, long roleid) { userrole.where { user == user.load(userid) && role == role.load(roleid) }.get() } static boolean exists(long userid, long roleid) { userrole.where { user == user.load(userid) && role == role.load(roleid) }.count() > 0 } static userrole create(user user, role role, boolean flush = false) { def instance = new userrole(user: user, role: role) instance.save(flush: flush, insert: true) instance } static boolean remove(user u, role r, boolean flush = false) { if (u == null || r == null) return false int rowcount = userrole.where { user == user.load(u.id) && role == role.load(r.id) }.deleteall() if (flush) { userrole.withsession { it.flush() } } rowcount > 0 } static void removeall(user u, boolean flush = false) { if (u == null) return userrole.where { user == user.load(u.id) }.deleteall() if (flush) { userrole.withsession { it.flush() } } } static void removeall(role r, boolean flush = false) { if (r == null) return userrole.where { role == role.load(r.id) }.deleteall() if (flush) { userrole.withsession { it.flush() } } } static constraints = { role validator: { role r, userrole ur -> if (ur.user == null) return boolean existing = false userrole.withnewsession { existing = userrole.exists(ur.user.id, r.id) } if (existing) { return 'userrole.exists' } } } static mapping = { id composite: ['role', 'user'] version false }
}
config file:
grails.plugin.springsecurity.userlookup.userdomainclassname = 'co.edu.uelbosque.unbosqueinscripciones.modelos.user' grails.plugin.springsecurity.userlookup.authorityjoinclassname = 'co.edu.uelbosque.unbosqueinscripciones.modelos.userrole' grails.plugin.springsecurity.authority.classname = 'co.edu.uelbosque.unbosqueinscripciones.modelos.role'
boostrap file:
class bootstrap { def init = { servletcontext -> def rol1 = new role(authority:'role_user') def rol2 = new role(authority:'role_admin') rol1.save(flush:true) rol2.save(flush:true) def us2 = new user(username:'testuser', password:'1234') us2.save(flush:true) new userrole(user:us2, role:rol2).save(flush:true) } def destroy = { }
}
plugins used (security plugin 2.0.rc):
plugins { // plugins build system build ":tomcat:7.0.55" // plugins compile step compile ":scaffolding:2.1.2" compile ':cache:1.1.8' compile ":asset-pipeline:1.9.9" // plugins needed @ runtime not compilation runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18" runtime ":database-migration:1.4.0" runtime ":jquery:1.11.1" //plugins adicionales compile ":mysql-connectorj:5.1.22.1" compile ":spring-security-ldap:2.0-rc4" compile ":simple-captcha:1.0.0" // plugins needed @ runtime not compilation runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18" runtime ":database-migration:1.4.0" runtime ":jquery:1.11.1" // uncomment these enable additional asset-pipeline capabilities //compile ":sass-asset-pipeline:1.9.0" //compile ":less-asset-pipeline:1.10.0" //compile ":coffee-asset-pipeline:1.8.0" //compile ":handlebars-asset-pipeline:1.3.0.3" }
Comments
Post a Comment