JiniKJohny
JiniKJohny

Reputation: 1182

Grails Spring securiy authentication with three parameters

Currently I have a domain model of User as follows:

class User {
  transient springSecurityService

  String username
  String password
  String firstName
  String lastName
  boolean enabled = true

  static transients = ['springSecurityService', 'enabled']

  static constraints = {
      username blank: false, unique: true
      password blank: false
  }

}

And Spring security authentication with Role, UserRole models are working fine. But I need to override User authentication with username and password along with emailID, email ID will be unique and it is a foreign key.

New User domain model is

class User {

  transient neatEncryptedType
  transient springSecurityService

  String username
  String password
  String emailId
  String firstName
  String lastName
  boolean enabled = true
}

How can I do this authentication using email, username and password? Please anyone suggest how to override spring security authentication for this?

Upvotes: 0

Views: 55

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

I did a talk a while back about the inner workings of the Spring Security plugins, and one example I did was a custom login with a 3rd parameter. There are a few steps involved to support this, so check out the downloadable code from this blog post for the process. It's not difficult, but requires a custom Authentication class, and custom filter and authenticator. But they're all based on existing classes, so it's all straightforward.

Upvotes: 2

Related Questions