본문 바로가기

Development/Web & Server

[Play Framework] Scala에 Hibernate + Jasypt 적용하기

1. 라이브러리 추가(http://www.jasypt.org/hibernate.html)

"org.jasypt" % "jasypt-hibernate4" % "1.9.2"

2. 초기값 설정

class ApplicationLoader extends GuiceApplicationLoader {

override def builder (context: ApplicationLoader.Context) : GuiceApplicationBuilder = {

val stringEncryptor = new StandardPBEStringEncryptor()
stringEncryptor.setPassword("asdfweqfqwef")//아무거나..

HibernatePBEEncryptorRegistry
.getInstance()
.registerPBEStringEncryptor("stringEncryptor",stringEncryptor)

initialBuilder
.in(context.environment)
.loadConfig(context.initialConfiguration)
.overrides(overrides(context):_*)

}

}

3. Loader 설정 (application.conf 파일)

play.application.loader = "global.MCApplicationLoader"

4. 모델 설정

@Entity
@Table (name = "user")
@TypeDef(name = "encryptedString",
typeClass = classOf[EncryptedStringType],
parameters= Array {
new Parameter (name = "encryptorRegisteredName", value = "stringEncryptor")
}
)
case class User (@(Id @field) @(GeneratedValue @field)@(Column @field)(name = "no") var no : Long,
@(Column @field)(name = "user_id") var userId : String,
@(Column @field)(name = "password") @(Type @field)(`type` = "encryptedString") var password : String) {
def this() = this(0, null, null)