From 225f58f81ca6ba93faee88ff0a987718da7b7364 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Fri, 13 Dec 2024 10:36:33 +0800 Subject: [PATCH] refactor: address deprecations --- .../configuration/KomgaSettingsProvider.kt | 2 +- ...oqConfiguration.kt => KomgaJooqConfiguration.kt} | 2 +- .../gotson/komga/infrastructure/kobo/KoboProxy.kt | 13 +++++++------ .../oauth2/KomgaOAuth2UserServiceConfiguration.kt | 2 +- .../komga/interfaces/api/kobo/KoboController.kt | 6 +++--- .../komga/interfaces/api/opds/v2/Opds2Controller.kt | 2 +- .../interfaces/scheduler/InitialUserController.kt | 2 +- komga/src/main/resources/application.yml | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) rename komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/{JooqConfiguration.kt => KomgaJooqConfiguration.kt} (98%) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaSettingsProvider.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaSettingsProvider.kt index b692b632..95cb3aea 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaSettingsProvider.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaSettingsProvider.kt @@ -39,7 +39,7 @@ class KomgaSettingsProvider( rememberMeKey = getRandomRememberMeKey() } - private fun getRandomRememberMeKey() = RandomStringUtils.randomAlphanumeric(32) + private fun getRandomRememberMeKey() = RandomStringUtils.secure().nextAlphanumeric(32) var rememberMeDuration: Duration = (serverSettingsDao.getSettingByKey(Settings.REMEMBER_ME_DURATION.name, Int::class.java) ?: 365).days diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/JooqConfiguration.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/KomgaJooqConfiguration.kt similarity index 98% rename from komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/JooqConfiguration.kt rename to komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/KomgaJooqConfiguration.kt index 7ed9ac5b..3be2c4ca 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/JooqConfiguration.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/KomgaJooqConfiguration.kt @@ -18,7 +18,7 @@ import javax.sql.DataSource // taken from https://github.com/spring-projects/spring-boot/blob/v3.1.4/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java // as advised in https://docs.spring.io/spring-boot/docs/3.1.4/reference/htmlsingle/#howto.data-access.configure-jooq-with-multiple-datasources @Configuration -class JooqConfiguration { +class KomgaJooqConfiguration { @Bean("dslContext") @Primary fun mainDslContext( diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/kobo/KoboProxy.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/kobo/KoboProxy.kt index 9e5a76d8..5ae442a2 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/kobo/KoboProxy.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/kobo/KoboProxy.kt @@ -7,11 +7,12 @@ import org.gotson.komga.infrastructure.configuration.KomgaSettingsProvider import org.gotson.komga.infrastructure.kobo.KoboHeaders.X_KOBO_SYNCTOKEN import org.gotson.komga.infrastructure.web.getCurrentRequest import org.gotson.komga.language.contains +import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder +import org.springframework.boot.http.client.ClientHttpRequestFactorySettings import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod import org.springframework.http.HttpStatusCode import org.springframework.http.ResponseEntity -import org.springframework.http.client.ReactorNettyClientRequestFactory import org.springframework.stereotype.Component import org.springframework.util.LinkedMultiValueMap import org.springframework.web.client.RestClient @@ -32,11 +33,11 @@ class KoboProxy( RestClient.builder() .baseUrl("https://storeapi.kobo.com") .requestFactory( - ReactorNettyClientRequestFactory().apply { - setConnectTimeout(1.minutes.toJavaDuration()) - setReadTimeout(1.minutes.toJavaDuration()) - setExchangeTimeout(1.minutes.toJavaDuration()) - }, + ClientHttpRequestFactoryBuilder.reactor().build( + ClientHttpRequestFactorySettings.defaults() + .withReadTimeout(1.minutes.toJavaDuration()) + .withConnectTimeout(1.minutes.toJavaDuration()), + ), ) .build() diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/security/oauth2/KomgaOAuth2UserServiceConfiguration.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/security/oauth2/KomgaOAuth2UserServiceConfiguration.kt index 32a98440..c07a69a6 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/security/oauth2/KomgaOAuth2UserServiceConfiguration.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/security/oauth2/KomgaOAuth2UserServiceConfiguration.kt @@ -73,7 +73,7 @@ class KomgaOAuth2UserServiceConfiguration( private fun tryCreateNewUser(email: String) = if (komgaProperties.oauth2AccountCreation) { logger.info { "Creating new user from OAuth2 login: $email" } - userLifecycle.createUser(KomgaUser(email, RandomStringUtils.randomAlphanumeric(12), roleAdmin = false)) + userLifecycle.createUser(KomgaUser(email, RandomStringUtils.secure().nextAlphanumeric(12), roleAdmin = false)) } else { throw OAuth2AuthenticationException("ERR_1025") } diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/kobo/KoboController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/kobo/KoboController.kt index c6805fcd..a1601f0b 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/kobo/KoboController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/kobo/KoboController.kt @@ -228,8 +228,8 @@ class KoboController( * Return dummy data to keep the device happy. */ return AuthDto( - accessToken = RandomStringUtils.randomAlphanumeric(24), - refreshToken = RandomStringUtils.randomAlphanumeric(24), + accessToken = RandomStringUtils.secure().nextAlphanumeric(24), + refreshToken = RandomStringUtils.secure().nextAlphanumeric(24), trackingId = UUID.randomUUID().toString(), userKey = body.get("UserKey")?.asText() ?: "", ) @@ -688,7 +688,7 @@ class KoboController( if (!thumbnailBookRepository.existsById(thumbnailId) && koboProxy.isEnabled()) { ResponseEntity .status(HttpStatus.TEMPORARY_REDIRECT) - .location(UriComponentsBuilder.fromHttpUrl(koboProxy.imageHostUrl).buildAndExpand(thumbnailId, width, height).toUri()) + .location(UriComponentsBuilder.fromUriString(koboProxy.imageHostUrl).buildAndExpand(thumbnailId, width, height).toUri()) .build() } else { val poster = bookLifecycle.getThumbnailBytesByThumbnailId(thumbnailId) ?: throw ResponseStatusException(HttpStatus.NOT_FOUND) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/opds/v2/Opds2Controller.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/opds/v2/Opds2Controller.kt index 435d7e07..792f0b36 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/opds/v2/Opds2Controller.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/opds/v2/Opds2Controller.kt @@ -416,7 +416,7 @@ class Opds2Controller( @PathVariable(name = "id", required = false) libraryId: String?, @Parameter(hidden = true) page: Pageable, ): FeedDto { - val (library, authorizedLibraryIds) = checkLibraryAccess(libraryId, principal) + val (library, _) = checkLibraryAccess(libraryId, principal) val entries = seriesDtoRepository.findAll( diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/scheduler/InitialUserController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/scheduler/InitialUserController.kt index 7ebc64f2..2757ceef 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/scheduler/InitialUserController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/scheduler/InitialUserController.kt @@ -50,6 +50,6 @@ class InitialUsersProdConfiguration { @Bean fun initialUsers(): List = listOf( - KomgaUser("admin@example.org", RandomStringUtils.randomAlphanumeric(12), roleAdmin = true), + KomgaUser("admin@example.org", RandomStringUtils.secure().nextAlphanumeric(12), roleAdmin = true), ) } diff --git a/komga/src/main/resources/application.yml b/komga/src/main/resources/application.yml index ec761c95..bea36450 100644 --- a/komga/src/main/resources/application.yml +++ b/komga/src/main/resources/application.yml @@ -76,7 +76,7 @@ management: roles: ADMIN show-details: when_authorized shutdown: - enabled: true + access: unrestricted info: java: enabled: true