From ca4fa261879d4db7c14dac20363995ad604ab8ac Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 21:04:08 +0800 Subject: [PATCH] Update config file --- .../kotlin/top/fatweb/api/FatWebApiApplication.kt | 12 ++++++++++-- .../{constants => constant}/SecurityConstants.kt | 14 +++----------- .../{constants => constant}/ServerConstants.kt | 5 +++-- .../resources/application-config-template.yml | 9 +++++++++ src/main/resources/application.yml | 15 +++++++++------ 5 files changed, 34 insertions(+), 21 deletions(-) rename src/main/kotlin/top/fatweb/api/{constants => constant}/SecurityConstants.kt (51%) rename src/main/kotlin/top/fatweb/api/{constants => constant}/ServerConstants.kt (74%) diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 5dbcf42..9d83e83 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.transaction.annotation.EnableTransactionManagement import java.io.File +import java.util.* @SpringBootApplication @EnableTransactionManagement @@ -17,7 +18,14 @@ fun main(args: Array) { runApplication(*args) } else { logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created. Please change the configuration file content and rename it to 'application.yml', and then restart the server.") - FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText() - ?.let { File("application-config.example.yml").writeText(it) } + FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText() + ?.let { + File("application-config.example.yml").writeText( + it.replace( + "\$uuid\$", + UUID.randomUUID().toString() + ) + ) + } } } diff --git a/src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt b/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt similarity index 51% rename from src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt rename to src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt index e92897a..e868e1f 100644 --- a/src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt +++ b/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt @@ -1,8 +1,7 @@ -package top.fatweb.api.constants +package top.fatweb.api.constant import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component -import java.security.MessageDigest import java.util.concurrent.TimeUnit @Component @@ -16,14 +15,7 @@ object SecurityConstants { var jwtTtlUnit = TimeUnit.HOURS - lateinit var jwtKey: String + var jwtKey = "FatWeb" - private fun ByteArray.hex(): String { - return joinToString("") { "%02X".format(it) } - } - - private fun String.md5(): String { - val bytes = MessageDigest.getInstance("MD5").digest(this.toByteArray()) - return bytes.hex() - } + var jwtIssuer = "FatWeb" } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt b/src/main/kotlin/top/fatweb/api/constant/ServerConstants.kt similarity index 74% rename from src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt rename to src/main/kotlin/top/fatweb/api/constant/ServerConstants.kt index adabb4e..5f55621 100644 --- a/src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt +++ b/src/main/kotlin/top/fatweb/api/constant/ServerConstants.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.constants +package top.fatweb.api.constant import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @@ -13,5 +13,6 @@ object ServerConstants { lateinit var buildTime: String - fun buildZoneDateTime(zoneId: ZoneId = ZoneId.systemDefault()): ZonedDateTime = LocalDateTime.parse(buildTime).atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId) + fun buildZoneDateTime(zoneId: ZoneId = ZoneId.systemDefault()): ZonedDateTime = + LocalDateTime.parse(buildTime).atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId) } \ No newline at end of file diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index 88a4403..1e91da0 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -1,3 +1,12 @@ +app: + security: +# header-string: "Authorization" # The key of head to get token +# token-prefix: "Bearer " # Token prefix +# jwt-ttl: 2 # The life of token +# jwt-ttl-unit: hours # Unit of life of token + jwt-key: $uuid$ # Key to generate token +# jwt-issuer: FatWeb # Token issuer + server: # port: 8080 # Server port diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 27104c4..cec8de8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,15 +1,18 @@ app: version: @project.version@ build-time: @build.timestamp@ - security: - header-string: "Authorization" - token-prefix: "Bearer " - jwt-ttl: 2 - jwt-ttl-unit: hours spring: profiles: active: config datasource: type: com.alibaba.druid.pool.DruidDataSource - driver-class-name: com.mysql.cj.jdbc.Driver \ No newline at end of file + driver-class-name: com.mysql.cj.jdbc.Driver +mybatis-plus: + global-config: + db-config: + logic-delete-field: deleted + logic-not-delete-value: 0 + logic-delete-value: id + id-type: assign_id + type-aliases-package: top.fatweb.api.entity