EDITED HEADER: more related to the real issue
I am trying to set spring security for my test application
i installed the plugin, created user classes and roles;
put it in UrlMappings.groovy;
"/login/$action?"(controller: "login")
"/logout/$action?"(controller: "logout")
then I put the user in bootstrap as follows:
import org.project.auth.Role
import org.project.auth.User
import org.project.auth.UserRole;
class BootStrap {
def springSecurityService
def init = { servletContext ->
def userRole = Role.findByAuthority('ROLE_USER') ?: new Role(authority: 'ROLE_USER').save(failOnError: true,flush:true)
def adminRole = Role.findByAuthority('ROLE_ADMIN') ?: new Role(authority: 'ROLE_ADMIN').save(failOnError: true,flush:true)
def adminUser = User.findByUsername('admin') ?: new User(
username: 'admin',
password: springSecurityService.encodePassword('admin'),
enabled: true).save(failOnError: true,flush:true)
print User.count()
if (!adminUser.authorities.contains(adminRole)) {
print "TEST"
UserRole.create adminUser, adminRole,true
}
}
def destroy = {
}
}
this print User.count () returns 1, so I know that the user is created, printing "TEST" also works, so I know that he is in the if block, but when I start the server, it fails with
Sorry, we were not able to find a user with that username and password.
I am using Grails 2.0.0.M1, do you think this could be a problem?
source
share