2016-03-30 64 views
0

我想在Grails 2.5.4應用程序中使用加密來加密用戶數據。我遵循下載配置1.3.1版插件的說明。Jasypt在Grails 2.5.4中不加密

更新了JDK 1.8(無論是在JDK和JRE JRE獨立目錄)我的Java安全JCE文件。

我發現這裏的一些帖子這是類似的,應用了修復喜歡我的 小寫的configFIlePath。

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

我也試圖與配置的Config.groovy

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

我的域對象內部定義如下:

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 
    } 
} 

無論我嘗試在我的域對象中的數據通過Grails dbconsole應用程序查看它並沒有得到加密。

我打開調試日誌記錄,但沒有看到任何jasypt日誌。

回答

1

我懷疑主要問題是在您的constraints中使用type,而不是在mapping中,因爲documentation解釋。

我建議你改變你constraints看起來像這樣:

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 
} 

而就在這樣的約束條件之後,添加mappings

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 
}