Search code examples
grailsspring-securitygrails-ormgrails3

grails 3 spring security User domain id field synthetic


I am using grails 3.2.9 with spring-security-core plugin 3.1.2.

I've run the s2-quickstart script to create User, Role, and UserRole domain classes. I've found that the id field in the User and Role domains is being considered synthetic. For instance, if I run the following bit of code the id field is not shown:

def u = User.class.declaredFields.findAll {!it.synthetic}
u.each {
    println it
}

Here is my User class:

@GrailsCompileStatic
@EqualsAndHashCode(includes='username')
@ToString(includes='username', includeNames=true, includePackage=false)
class User extends BaseDomain implements Serializable {

    private static final long serialVersionUID = 1

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

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

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

    static mapping = {
        id generator: 'identity', column: 'user_id', sqlType: 'bigint(20) unsigned'
        password column: '`password`'
        lastLogin sqlType: 'timestamp'
    }
}

This is not happening with my other domain classes, and the first problem I see this causing is with the exa-datatables plugin (2.0.1). The plugin uses similar code to find the fields of a domain, so when requesting the id field to be displayed by the plugin it fails with an unknown column error.


Solution

  • I found this was being caused because I was extending a class (BaseDomain in the example), and I did not mark the BaseDomain as abstract. As soon as I qualified BaseDomain as abstract, everything started working as expected.

    abstract class BaseDomain {...