diff --git a/build.gradle.kts b/build.gradle.kts index 5b6bc454..18442d5e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ plugins { kotlin("jvm") version "1.8.21" id("io.ktor.plugin") version "2.3.0" id("org.graalvm.buildtools.native") version "0.9.21" - id("io.gitlab.arturbosch.detekt") version "1.22.0" + id("io.gitlab.arturbosch.detekt") version "1.23.1" id("com.google.devtools.ksp") version "1.8.21-1.0.11" id("org.springframework.boot") version "3.1.2" kotlin("plugin.spring") version "1.8.21" @@ -65,7 +65,7 @@ tasks.create("openApiGenerateServer", GenerateTask::class) { generatorName.set("kotlin-spring") inputSpec.set("$rootDir/src/main/resources/openapi/api.yaml") outputDir.set("$buildDir/generated/sources/openapi") - apiPackage.set("dev.usbharu.hideout.controller") + apiPackage.set("dev.usbharu.hideout.controller.generated") modelPackage.set("dev.usbharu.hideout.domain.model.generated") configOptions.put("interfaceOnly", "true") configOptions.put("useSpringBoot3", "true") @@ -149,6 +149,8 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jdbc") implementation("org.springframework.boot:spring-boot-starter-webflux") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") + testImplementation("org.springframework.boot:spring-boot-test-autoconfigure") + testImplementation("org.springframework.boot:spring-boot-starter-test") implementation("io.ktor:ktor-client-logging-jvm:$ktor_version") implementation("io.ktor:ktor-server-host-common-jvm:$ktor_version") @@ -226,9 +228,17 @@ detekt { } tasks.withType().configureEach { - exclude("**/org/koin/ksp/generated/**") + exclude("**/org/koin/ksp/generated/**", "**/generated/**") } tasks.withType().configureEach { - exclude("**/org/koin/ksp/generated/**") + exclude("**/org/koin/ksp/generated/**", "**/generated/**") +} + +configurations.matching { it.name == "detekt" }.all { + resolutionStrategy.eachDependency { + if (requested.group == "org.jetbrains.kotlin") { + useVersion("1.9.0") + } + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt b/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt index 8385ee79..0cc32e48 100644 --- a/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt +++ b/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt @@ -4,7 +4,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.context.properties.ConfigurationPropertiesScan import org.springframework.boot.runApplication - @SpringBootApplication @ConfigurationPropertiesScan class SpringApplication diff --git a/src/main/kotlin/dev/usbharu/hideout/config/DatabaseConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/DatabaseConfig.kt index dfe744ac..03064946 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/DatabaseConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/DatabaseConfig.kt @@ -6,7 +6,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration - @Configuration class DatabaseConfig { @@ -22,10 +21,8 @@ class DatabaseConfig { password = dbConfig.password ) } - } - @ConfigurationProperties("hideout.database") data class DatabaseConnectConfig( val url: String, diff --git a/src/main/kotlin/dev/usbharu/hideout/config/SecurityConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/SecurityConfig.kt index 3217acea..75505da3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/SecurityConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/SecurityConfig.kt @@ -38,7 +38,8 @@ class SecurityConfig { http .exceptionHandling { it.defaultAuthenticationEntryPointFor( - LoginUrlAuthenticationEntryPoint("/login"), MediaTypeRequestMatcher(MediaType.TEXT_HTML) + LoginUrlAuthenticationEntryPoint("/login"), + MediaTypeRequestMatcher(MediaType.TEXT_HTML) ) } .oauth2ResourceServer { @@ -50,7 +51,6 @@ class SecurityConfig { return http.build() } - @Bean @Order(2) fun defaultSecurityFilterChain(http: HttpSecurity): SecurityFilterChain { @@ -121,7 +121,6 @@ class SecurityConfig { } } - @ConfigurationProperties("hideout.security.jwt") @ConditionalOnProperty(name = ["hideout.security.jwt.generate"], havingValue = "") data class JwkConfig( diff --git a/src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt index a9d76420..92caf4f1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt @@ -8,7 +8,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement import org.springframework.transaction.annotation.TransactionManagementConfigurer import javax.sql.DataSource - @Configuration @EnableTransactionManagement class SpringTransactionConfig(val datasource: DataSource) : TransactionManagementConfigurer { diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/DefaultApiImpl.kt b/src/main/kotlin/dev/usbharu/hideout/controller/DefaultApiImpl.kt index 32e21fb2..b6253251 100644 --- a/src/main/kotlin/dev/usbharu/hideout/controller/DefaultApiImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/controller/DefaultApiImpl.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.controller +import dev.usbharu.hideout.controller.generated.DefaultApi import dev.usbharu.hideout.domain.model.hideout.dto.JwtToken import dev.usbharu.hideout.service.api.UserAuthApiService import org.springframework.http.HttpStatus diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt index 7a825c0c..7199a949 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt @@ -87,7 +87,6 @@ class RegisteredClientRepositoryImpl(private val database: Database) : Registere } } - // org/springframework/security/oauth2/server/authorization/client/oauth2-registered-client-schema.sql object RegisteredClient : Table("registered_client") { val id = varchar("id", 100) @@ -108,7 +107,6 @@ object RegisteredClient : Table("registered_client") { } fun ResultRow.toRegisteredClient(): SpringRegisteredClient { - fun resolveClientAuthenticationMethods(string: String): ClientAuthenticationMethod { return when (string) { ClientAuthenticationMethod.CLIENT_SECRET_BASIC.value -> ClientAuthenticationMethod.CLIENT_SECRET_BASIC @@ -160,7 +158,6 @@ fun ResultRow.toRegisteredClient(): SpringRegisteredClient { .scopes { it.addAll(clientScopes) } .clientSettings(ClientSettings.withSettings(JsonUtil.jsonToMap(this[clientSettings])).build()) - val tokenSettingsMap = JsonUtil.jsonToMap(this[tokenSettings]) val withSettings = TokenSettings.withSettings(tokenSettingsMap) if (tokenSettingsMap.containsKey(ConfigurationSettingNames.Token.ACCESS_TOKEN_FORMAT)) { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt index bc684bb4..51ea4eee 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt @@ -10,7 +10,6 @@ import io.ktor.http.* import org.koin.core.annotation.Single import org.springframework.stereotype.Service - @Service interface APCreateService { suspend fun receiveCreate(create: Create): ActivityPubResponse diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt index 6ad4f67e..03bb22f4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt @@ -11,7 +11,6 @@ import io.ktor.http.* import org.koin.core.annotation.Single import org.springframework.stereotype.Service - @Service interface APUndoService { suspend fun receiveUndo(undo: Undo): ActivityPubResponse diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt index 8abea597..dac35033 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt @@ -105,7 +105,6 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository: it[deviceCodeMetadata] = deviceCode?.metadata?.let { it1 -> JsonUtil.mapToJson(it1) } } } - } override fun remove(authorization: OAuth2Authorization?) { @@ -176,7 +175,6 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository: } fun ResultRow.toAuthorization(): OAuth2Authorization { - val registeredClientId = this[Authorization.registeredClientId] val registeredClient = registeredClientRepository.findById(registeredClientId) @@ -186,7 +184,7 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository: val principalName = this[Authorization.principalName] val authorizationGrantType = this[Authorization.authorizationGrantType] val authorizedScopes = this[Authorization.authorizedScopes]?.split(",").orEmpty().toSet() - val attributes = this[Authorization.attributes]?.let { JsonUtil.jsonToMap(it) } ?: emptyMap() + val attributes = this[Authorization.attributes]?.let { JsonUtil.jsonToMap(it) }.orEmpty() builder.id(id).principalName(principalName) .authorizationGrantType(AuthorizationGrantType(authorizationGrantType)).authorizedScopes(authorizedScopes) @@ -218,7 +216,7 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository: val accessTokenIssuedAt = this[Authorization.accessTokenIssuedAt] val accessTokenExpiresAt = this[Authorization.accessTokenExpiresAt] val accessTokenMetadata = - this[Authorization.accessTokenMetadata]?.let { JsonUtil.jsonToMap(it) } ?: emptyMap() + this[Authorization.accessTokenMetadata]?.let { JsonUtil.jsonToMap(it) }.orEmpty() val accessTokenType = if (this[Authorization.accessTokenType].equals(OAuth2AccessToken.TokenType.BEARER.value, true)) { OAuth2AccessToken.TokenType.BEARER @@ -229,7 +227,11 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository: val accessTokenScope = this[Authorization.accessTokenScopes]?.split(",").orEmpty().toSet() val oAuth2AccessToken = OAuth2AccessToken( - accessTokenType, accessTokenValue, accessTokenIssuedAt, accessTokenExpiresAt, accessTokenScope + accessTokenType, + accessTokenValue, + accessTokenIssuedAt, + accessTokenExpiresAt, + accessTokenScope ) builder.token(oAuth2AccessToken) { it.putAll(accessTokenMetadata) } @@ -240,7 +242,7 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository: val oidcTokenIssuedAt = this[Authorization.oidcIdTokenIssuedAt] val oidcTokenExpiresAt = this[Authorization.oidcIdTokenExpiresAt] val oidcTokenMetadata = - this[Authorization.oidcIdTokenMetadata]?.let { JsonUtil.jsonToMap(it) } ?: emptyMap() + this[Authorization.oidcIdTokenMetadata]?.let { JsonUtil.jsonToMap(it) }.or val oidcIdToken = OidcIdToken( oidcIdTokenValue, diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/UserDetailsServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/UserDetailsServiceImpl.kt index a889e79a..76bb81a9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/UserDetailsServiceImpl.kt @@ -19,7 +19,9 @@ class UserDetailsServiceImpl(private val userQueryService: UserQueryService, pri transaction.transaction { val findById = userQueryService.findByNameAndDomain(username, "") User( - findById.name, findById.password, listOf() + findById.name, + findById.password, + listOf() ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/UsernamePasswordAuthFilter.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/UsernamePasswordAuthFilter.kt index 5655e8b4..208f4c6a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/UsernamePasswordAuthFilter.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/UsernamePasswordAuthFilter.kt @@ -4,14 +4,12 @@ import org.springframework.security.authentication.AuthenticationManager import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter import org.springframework.security.web.util.matcher.AntPathRequestMatcher - class UsernamePasswordAuthFilter(jwtService: JwtService, authenticationManager: AuthenticationManager?) : UsernamePasswordAuthenticationFilter(authenticationManager) { init { setRequiresAuthenticationRequestMatcher(AntPathRequestMatcher("/api/internal/v1/login", "POST")) this.setAuthenticationSuccessHandler { request, response, authentication -> - } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/util/JsonUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/JsonUtil.kt index fcd97a9f..25d282bc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/JsonUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/JsonUtil.kt @@ -12,5 +12,4 @@ object JsonUtil { fun jsonToMap(json: String, objectMapper: ObjectMapper = this.objectMapper): Map = objectMapper.readValue(json) - }