I'm integrating the SpringSecurity plugin with an application. To do so, I installed the plugin and ran the s2-quickstart script, which created three domain classes: SecUser, SecRole, and SecUserSecRole as well as the login/logout controllers.
As I already have an existing User domain class and wanted to keep it, I modified User to extend SecUser and removed the overlapping fields of username and password from User. Also, I've added tablePerHierarchy false to both User and SecUser mapping sections.
In BootStrap, I'm trying to create an Admin user to exist on startup. To do so, I create a new SecRole object adminRole with the authority set to ROLE_ADMIN. Then, I create a new User object and check if it contains the admin role via
def springSecurityService
def init {
def adminUser = User.findByUsername('admin') ?: new User(
username:'admin',
password:'adminUser',
userType:'Admin',
enabled:true
).save(failOnError:true)
if (!adminUser.authorities.contains(adminRole))
SecUserSecRole.create adminUser, adminRole, true
}
My issue is I keep getting a transient instance exception, regardless if adminUser is declared to be a User or SecUser instance. As userType has a constraint of blank:false, if I comment out the userType field when creating a User instance, I get an excception stating that null is not a valid setting for userType. When I include it, I get the transient object exception: object references an unsaved transient instance - save the transient instance before flushing: books4africa.SecUser, so I know I'm passing all User validation settings.
What causes a valid User object to not be saved in this circumstance?
EDIT
The solution for this issue was to delete the existing dev database file and reinitialize the application. My guess is that there was some sort of conflict between the db and Spring Security with the original db, so restarting the app with a fresh db solved the problem.
Since none of the answers below solved the exact problem, I won't be accepting in this instance, but thanks for the help!
.save(failOnError:true, flush:true)or anithing like that. Well, thats the problem when you use a framework that is built on frameworks, sometimes exceptions tell you just the bare minimum. - GalmWing