Grails: Multiple logins per user

29 Apr 2015
by cvringer

Sometimes you would create multiple logins for the same user in an application. You might want to login as administrator or as regular user, without entering all your personal data again, or without creating yet another email address. Here is how you do it.

– Setup a secured Grails application.(there are multiple ways of doing that)

– Create a relations between your regular user object (where you store firstname, lastname, email and so) and the Login object.

class Login {
     String username
     String passwordHash
     static belongsTo = [user:User]

and in the User class:

static hasMany = [logins: Login]

That’s it. You can create multiple logins for the same user,and you can even assign different roles per login, so the same user can login as administrator, and use another login with another role.


Leave a Comment:

* - required fields

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© Keienberg Consultants