I am new in Grails and Spring Security. I try to make a simple register view. I created the User, Role and UserRole domain classes with the s2-quickstart script from spring-security.
My problem is that only the User will be saved in the database. But I want to save the User and the UserRole.
Thats my controller:
@Secured('permitAll')
class RegisterController {
def index() {
}
def register() {
def user = new User(params)
user.save()
def role = Role.findByAuthority('ROLE_USER') // ROLE_USER will be created in the bootstrap class
UserRole.create(user, role)
redirect view: 'index'
}
}
If i put the same code in the bootstrap class the UserRole will be saved too.
Hope someone can help and explain, why this not work.