Upgrading spring security rest for grails 3.3.x with mongodb.

Grails has come up with the latest version of 3.3.x and with this new release lot of changes are made to improve the overall performance of grails application.

In this blog we will look into the changes required to make the spring security core and spring security rest work with mongdb.

 

1. First of all starting from grails 3.3.x , we need to compile the below mentioned spring security core plugin.

compile 'org.grails.plugins:spring-security-core:3.2.0.M1'

 

2. For next set of configuration you can follow my old post on grails spring security core and rest mentioned below.

 

3. Most important step, you will notice a new file created under src/main/groovy/com/yourapp.SecUserPasswordEncoderListener.groovy file, this file is an event listener file used to encode the password before saving it to the database. Along with this file you will also notice file change under conf/spring/resources.groovy file, changes would look similar to code mentioned below.

 

import com.example.webapi.SecUserPasswordEncoderListener
// Place your Spring DSL code here
beans = {
    secUserPasswordEncoderListener(SecUserPasswordEncoderListener, ref('hibernateDatastore'))
}

 

Just update the hibernateDataStore to mongoDatastore and your password encoder will start working.