0

I wanted to use encryption to encrypt user data in Grails 2.5.4 application. I followed the instructions on downloading configuring the 1.3.1 version of plugin.

Updated my Java Security JCE files in JDK 1.8 (both in JDK jre and standalone JRE directories).

I found some posts here which were similar and applied the fixes like the lower case i in configFIlePath.

def configFilePath = System.getenv('ENCRYPTION_CONFIG_LOCATION') ?:    "file:${userHome}"
configFilePath += "/.jasypt.groovy"
grails.config.locations = [configFilePath]

I also tried with configuration inside the Config.groovy

jasypt {
    algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC"
    providerName = "BC"
    password = "test"
    keyObtentionIterations = 1000
}

My domain object is defined as follows:

package com.xyz

import java.util.Date;
import com.bloomhealthco.jasypt.*

class UserProfile {

    String firstName
    String lastName
    Date dateOfBirth

    // USATT membership information
    long usattID
    Date expirationDate

    // contact information
    String email
    String phone
    String streetAddress
    String city
    String state
    String zipCode
    String country
    String gender
    String club


    // no reference to SecUser
    static belongsTo = SecUser

    static hasMany = [tournamentEntries: TournamentEntry]

    static constraints = {
        firstName blank: false, maxSize: 384, type: GormEncryptedStringType
        lastName blank: false, maxSize: 384, type: GormEncryptedStringType
        dateOfBirth blank: false 
        gender blank: false, type: GormEncryptedStringType
        email blank: false, maxSize: 384, type: GormEncryptedStringType
        phone blank: false, maxSize: 384, type: GormEncryptedStringType
        streetAddress blank: false, maxSize: 384, type: GormEncryptedStringType
        city blank: false, maxSize: 384, type: GormEncryptedStringType
        state blank: false, type: GormEncryptedStringType
        zipCode blank: false, type: GormEncryptedStringType
        country blank: false, maxSize: 384, type: GormEncryptedStringType
        expirationDate nullable: true 
    }
}

No matter what I try the data in my Domain object is not getting encrypted as far as I can tell by viewing it via Grails dbconsole application.

I turned on debug logging but don't see any logs from jasypt.

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73
Swavek
  • 9
  • 1

1 Answers1

1

I suspect the main issue is the use of type within your constraints and not within mapping as the documentation explains.

I'd recommend you change you constraints to look like this:

static constraints = {
    firstName blank: false, maxSize: 384
    lastName blank: false, maxSize: 384
    dateOfBirth blank: false 
    gender blank: false
    email blank: false, maxSize: 384
    phone blank: false, maxSize: 384
    streetAddress blank: false, maxSize: 384
    city blank: false, maxSize: 384
    state blank: false
    zipCode blank: false
    country blank: false, maxSize: 384
    expirationDate nullable: true 
}

And add mappings just after the constraints like this:

static mapping = {
    firstName type: GormEncryptedStringType
    lastName type: GormEncryptedStringType
    gender blank: false, type: GormEncryptedStringType
    email type: GormEncryptedStringType
    phone type: GormEncryptedStringType
    streetAddress type: GormEncryptedStringType
    city type: GormEncryptedStringType
    state type: GormEncryptedStringType
    zipCode blank: false, type: GormEncryptedStringType
    country type: GormEncryptedStringType
}
Joshua Moore
  • 24,706
  • 6
  • 50
  • 73