grailsgrails-plugingrails-3.0grails-spring-security

Grails 3 Spring Security UI Plugin Add Custom Fields to Registration Form


Grails/Spring Security newbie here, I'm working w a legacy system and am in need of some proper answers from authoritative sources.

Working with Grails 3 and version 3.1.2 of the Spring Security UI plugin, I'm just trying to add new fields like phone number and country to the registration form and I've tried many approaches to no avail. All the stackoverflow answers are outdated or not complete. I followed the doc and ran the s2ui override script to extend the RegisterController and copied everything from the original controller, and added the new fields inside the RegisterCommand class, and edited the gsps to show the new fields.

However when I fire up the app and tried to register I get a no signature of method Error because I'm passing the modified RegisterCommand w the additional fields to the uiRegistrationStrategy.createUser method which is expecting the original RegisterCommand values. I tried extending the DefaultRegistrationCodeStrategy or the SpringSecurityUiService but did not get far, just wanted to make sure I'm on the right path.

What additional steps am I missing?
It seems like the createUser method is handled by SpringSecurityUiService through DefaultRegistrationCodeStrategy so am I correct in assuming that I need to extend both? This is getting way too complicated for such a simple task...

Any help will be greatly appreciated. Thank you!


Solution

  • I ended up with the following steps to add more fields to the registration form and get the createUser and register methods to work.

    I also had to include the initialize() method in MySpringSecurityUiService from the parent or the User didn't get generated in the createUser method. Also had an issue with calling parent SpringSecurityUiService methods from DefaultRegistrationCodeStrategy for those that weren't overriden due to the change in RegisterCommand (ex. register) for some reason. Just overrode all methods with the same methods from the parent and it worked.

    Hope this helps someone, please feel free to fix my mistake all suggest improvements if you have something better. Spent the last 3 days trying to figure this out, lesson learned- Grails is not for someone without a decent amount of Spring knowledge and the docs could definitely be better w some concrete examples.