Home Rest APi User Registration
Reply: 0

Rest APi User Registration

user1703 Published in June 19, 2018, 2:28 pm

I create a Grails REST API

I'm using Spring Security

For create the User and Role domain classes

grails s2-quickstart com.mycompany.myapp User Role

My REST API should support the ability to create users, but I do not know how to do this

@ToString(includes='username', includeNames=true, includePackage=false)
class User implements Serializable {
    private static final long serialVersionUID = 1

    String username
    String password
    boolean enabled = true
    boolean accountExpired
    boolean accountLocked
    boolean passwordExpired

    User(String username, String password) {
        this.username = username
        this.password = password

    Set<Role> getAuthorities() {
        (UserRole.findAllByUser(this) as List<UserRole>)*.role as Set<Role>

    static constraints = {
        password nullable: false, blank: false, password: true
        username nullable: false, blank: false, unique: true

    static mapping = {
        table '`user`'
        password column: '`password`'

I created a controller

class UserController extends RestfulController {
    static responseFormats = ['json', 'xml']
    UserController() {

    def save() {

And at the moment I can create users, but I can not automatically assign them a role

How can I assign it the role of ROLE_USER when creating a new user?

I use Grails 3.3.5

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.370648 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO