When developing a Grails 3.0 plugin:
- How should a domain be defined so that it can be extended by the application using the plugin?
- How does the plugin reference instances of the extended class?
As an example, a security plugin could have classes such as:
User.groovy
package com.example.plugins.security
class User {
String email
String hash
Boolean enabled = true
}
SecurityService.groovy
package com.example.plugins.security
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
class SecurityService {
def authenticate(String email, String password) {
def user = User.findByEmail(email) //instance of BookstoreUser???
def encoder = new BCryptPasswordEncoder()
return user && encoder.matches(password, user.hash) ? user : null
}
}
The application would have a domain such as:
grails-app/domain/com/example/bookstore/BookstoreUser.groovy
package org.example.bookstore
import org.bson.types.ObjectId
import org.example.plugins.security.User
class BookstoreUser extends User {
ObjectId id
String firstName
String lastName
static mapWith = "mongo"
}
The rest of the code is at:
https://github.com/center-key/bookstore