Search code examples
authenticationgrailsspring-securitygrails-plugin

Grails Spring Security Core Create New User


Installed the latest spring-security-core plugin for grails 2.1.0, launched s2-quickstart com.myapp User Role, it create User Role and UserRole domain, then generate-all com.myapp.User and com.myapp.Role to build basic CRUD. Now i'm trying to create a "Register" button to allow new users to sign in, using the User create() method, the problem is that when creating a new User, this one comes without Role, i'm trying to auto-assignate 'ROLE_USER' to every new user that register through the 'register' button and form.

Any help or suggestion is most welcome.


Solution

  • Add this in the controller action after checking that the user creation was successful:

    def roleUser = Role.findByName('ROLE_USER')
    UserRole.create user, roleUser, true