Upon creating new users in my system, I am sending them a temporary password via email and setting an property of changePasswordNextLogin=true. When they come to log in for the first time, I would like to intercept the flow upon a successful login, check for this this value, and if it is true, redirect them to a change password action. Once the password change has been completed, ideally I would like to send them to their intended destination.
I have been pouring through the default settings and am not seeing – or more likely not interpreting properly – any way to make that happen. It seems that almost every time that I try to cobble some solution together in Grails, I find that someone has already made a much more elegant approach to do the same thing. Is there any functionality built in that would allow this?
If not, I would really appreciate any suggestions on the best approach to make it so.
There is some support for this directly with Spring Security and the grails plugin, but you also have to do some work yourself 🙂
The domain class that was created when you installed grails-spring-security plugin (and ran the S2Quickstart script) has a property on it named ‘passwordExpired’. Set this to true when you create your new user domain instance.
Once that user logs in for the first time, the Spring Security core libs will throw an exception which you can catch in your login controller’s authfail closure, re-directing them to the change password form (that you need to supply yourself).
Here’s an example from one of my apps, a skeleton version of this closure should already be included in your login controller:
From your ‘changePasssword’ view, submit the form back to another controller closure (I call mine ‘updatePassword’ that checks whatever constraints you want for passwords and either saves the updated password on the domain object or not..