diff --git a/build.gradle.kts b/build.gradle.kts index 99e54fd..57955aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,8 @@ plugins { java.sourceCompatibility = JavaVersion.VERSION_21 +val jasyptVersion: String by project.extra + allprojects { group = "com.mashup.ppangzip" version = "0.0.1-SNAPSHOT" @@ -27,7 +29,9 @@ subprojects { dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:${jasyptVersion}") + testImplementation("org.springframework.boot:spring-boot-starter-test") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/gradle.properties b/gradle.properties index 8c0a155..7c18b1f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ jjwtVersion=0.11.5 mysqlConnectorVersion=8.0.33 springDocOpenApiVersion=2.0.2 +jasyptVersion=3.0.5 diff --git a/pic-api/src/main/resources/application-domain.yaml b/pic-api/src/main/resources/application-domain.yaml index d584c93..5ca6fe3 100644 --- a/pic-api/src/main/resources/application-domain.yaml +++ b/pic-api/src/main/resources/application-domain.yaml @@ -1,8 +1,8 @@ spring: datasource: - url: ${MYSQL_URL} - username: ${MYSQL_USERNAME} - password: ${MYSQL_PASSWORD} + url: ENC(Ay1RamiVb1M/bs+asVmYBsfpJKWCV/GlfYiAJTiO5nW7l9HAeGWVDneMntFvqS+myIfeypom11iMvX0KAXkBKnRd408MJWVuepy8uMU6tR+NqmwTJBOdSd9flGdOvSlnyG7l/YqwK46KtSC513pNwsV8UlIypgEDVn+Of3q/N2biF/oUXcJRsmGxn5XzY7v8InR+CBoakJJmCzHaaYPxMRQFEd/l3a9bsTfyNSUcbYg=) + username: ENC(MeGy+GMnB7qvepqgo1UWRTBadVuqO/NYMlQmif0WItNsbzShuX2U5Dl4iVKrznuz) + password: ENC(9hUR9OvMkz9IEOgjKsf7uXbUaLUaT1RXGR9AjOU2vDYEhVuTwFtu+vyU9IPv6HzHfmK16liLpmKXdBsf2OkZyg==) driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: diff --git a/pic-api/src/main/resources/application.yaml b/pic-api/src/main/resources/application.yaml index 9371446..0cc0d01 100644 --- a/pic-api/src/main/resources/application.yaml +++ b/pic-api/src/main/resources/application.yaml @@ -5,10 +5,10 @@ spring: import: - classpath:/application-domain.yaml jwt: - secret-key: ${SECRET_KEY} + secret-key: ENC(NtDCxHj5jr9w2VZJ8ePLbjYrgB5mcL68ysQhvGgnj53mqiHnML6eWOi3X0sL4CRUnvqZMEKx9af16oM02kKDj91w76d72ljnLVhT49M1lhc=) kakao: issuer: https://kauth.kakao.com audience: - rest: ${KAKAO_REST_KEY} - native: ${KAKAO_NATIVE_KEY} + rest: ENC(fEnBOJApIyZToWk4lc77g7xYnG20FhdIFwAJkolwbrEWZ5S+Gm/gJWUbMFciWL99oSEVLhTJxUOzxZWjr4Z+8A==) + native: ENC(/vP+mCyAS0JwUoWO207Sp4OwXLiiYdF//59zusyXxoEB8MJg0q8AYVEzubY5EGdhM/rioCqlhAQyqDgZuwxws2pwdONcc1qG7SDksRymywQ=) jwk-uri: https://kauth.kakao.com/.well-known/jwks.json diff --git a/pic-common/src/main/kotlin/com/mashup/pic/config/JasyptConfig.kt b/pic-common/src/main/kotlin/com/mashup/pic/config/JasyptConfig.kt new file mode 100644 index 0000000..8b2fe1d --- /dev/null +++ b/pic-common/src/main/kotlin/com/mashup/pic/config/JasyptConfig.kt @@ -0,0 +1,8 @@ +package com.mashup.pic.config + +import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties +import org.springframework.context.annotation.Configuration + +@Configuration +@EnableEncryptableProperties +class JasyptConfig diff --git a/pic-common/src/test/kotlin/com/mashup/pic/SharedContext.kt b/pic-common/src/test/kotlin/com/mashup/pic/SharedContext.kt new file mode 100644 index 0000000..c4a7649 --- /dev/null +++ b/pic-common/src/test/kotlin/com/mashup/pic/SharedContext.kt @@ -0,0 +1,8 @@ +package com.mashup.pic + +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.TestConstructor + +@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +abstract class SharedContext diff --git a/pic-common/src/test/kotlin/com/mashup/pic/config/JasyptConfigTest.kt b/pic-common/src/test/kotlin/com/mashup/pic/config/JasyptConfigTest.kt new file mode 100644 index 0000000..634507c --- /dev/null +++ b/pic-common/src/test/kotlin/com/mashup/pic/config/JasyptConfigTest.kt @@ -0,0 +1,29 @@ +package com.mashup.pic.config + +import com.mashup.pic.SharedContext +import org.hamcrest.Matchers.`is` +import org.hamcrest.MatcherAssert.assertThat +import org.jasypt.encryption.StringEncryptor +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest + +/** + * Run > Edit Configurations > Configuration > Environment variables > 'JASYPT_ENCRYPTOR_PASSWORD={암호화키}' 입력 + */ +@Disabled("암호화, 복호화 결과 확인을 위한 테스트이므로 비활성화") +@SpringBootTest(classes = [JasyptConfig::class]) +class JasyptConfigTest( + private val stringEncryptor: StringEncryptor +) : SharedContext() { + + private val plainText: String = "test" + + @Test + fun execute() { + stringEncryptor.encrypt(plainText).let { encrypted -> + println(encrypted) + assertThat(stringEncryptor.decrypt(encrypted), `is`(plainText)) + } + } +}