style: スタイルを修正

This commit is contained in:
usbharu 2023-09-19 16:21:35 +09:00
parent 866309e552
commit ac8ae2c65a
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
13 changed files with 28 additions and 27 deletions

View File

@ -13,7 +13,7 @@ plugins {
kotlin("jvm") version "1.8.21" kotlin("jvm") version "1.8.21"
id("io.ktor.plugin") version "2.3.0" id("io.ktor.plugin") version "2.3.0"
id("org.graalvm.buildtools.native") version "0.9.21" 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("com.google.devtools.ksp") version "1.8.21-1.0.11"
id("org.springframework.boot") version "3.1.2" id("org.springframework.boot") version "3.1.2"
kotlin("plugin.spring") version "1.8.21" kotlin("plugin.spring") version "1.8.21"
@ -65,7 +65,7 @@ tasks.create<GenerateTask>("openApiGenerateServer", GenerateTask::class) {
generatorName.set("kotlin-spring") generatorName.set("kotlin-spring")
inputSpec.set("$rootDir/src/main/resources/openapi/api.yaml") inputSpec.set("$rootDir/src/main/resources/openapi/api.yaml")
outputDir.set("$buildDir/generated/sources/openapi") 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") modelPackage.set("dev.usbharu.hideout.domain.model.generated")
configOptions.put("interfaceOnly", "true") configOptions.put("interfaceOnly", "true")
configOptions.put("useSpringBoot3", "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-data-jdbc")
implementation("org.springframework.boot:spring-boot-starter-webflux") implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") 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-client-logging-jvm:$ktor_version")
implementation("io.ktor:ktor-server-host-common-jvm:$ktor_version") implementation("io.ktor:ktor-server-host-common-jvm:$ktor_version")
@ -226,9 +228,17 @@ detekt {
} }
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach { tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
exclude("**/org/koin/ksp/generated/**") exclude("**/org/koin/ksp/generated/**", "**/generated/**")
} }
tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach { tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().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")
}
}
} }

View File

@ -4,7 +4,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationPropertiesScan import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication import org.springframework.boot.runApplication
@SpringBootApplication @SpringBootApplication
@ConfigurationPropertiesScan @ConfigurationPropertiesScan
class SpringApplication class SpringApplication

View File

@ -6,7 +6,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
@Configuration @Configuration
class DatabaseConfig { class DatabaseConfig {
@ -22,10 +21,8 @@ class DatabaseConfig {
password = dbConfig.password password = dbConfig.password
) )
} }
} }
@ConfigurationProperties("hideout.database") @ConfigurationProperties("hideout.database")
data class DatabaseConnectConfig( data class DatabaseConnectConfig(
val url: String, val url: String,

View File

@ -38,7 +38,8 @@ class SecurityConfig {
http http
.exceptionHandling { .exceptionHandling {
it.defaultAuthenticationEntryPointFor( it.defaultAuthenticationEntryPointFor(
LoginUrlAuthenticationEntryPoint("/login"), MediaTypeRequestMatcher(MediaType.TEXT_HTML) LoginUrlAuthenticationEntryPoint("/login"),
MediaTypeRequestMatcher(MediaType.TEXT_HTML)
) )
} }
.oauth2ResourceServer { .oauth2ResourceServer {
@ -50,7 +51,6 @@ class SecurityConfig {
return http.build() return http.build()
} }
@Bean @Bean
@Order(2) @Order(2)
fun defaultSecurityFilterChain(http: HttpSecurity): SecurityFilterChain { fun defaultSecurityFilterChain(http: HttpSecurity): SecurityFilterChain {
@ -121,7 +121,6 @@ class SecurityConfig {
} }
} }
@ConfigurationProperties("hideout.security.jwt") @ConfigurationProperties("hideout.security.jwt")
@ConditionalOnProperty(name = ["hideout.security.jwt.generate"], havingValue = "") @ConditionalOnProperty(name = ["hideout.security.jwt.generate"], havingValue = "")
data class JwkConfig( data class JwkConfig(

View File

@ -8,7 +8,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement
import org.springframework.transaction.annotation.TransactionManagementConfigurer import org.springframework.transaction.annotation.TransactionManagementConfigurer
import javax.sql.DataSource import javax.sql.DataSource
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
class SpringTransactionConfig(val datasource: DataSource) : TransactionManagementConfigurer { class SpringTransactionConfig(val datasource: DataSource) : TransactionManagementConfigurer {

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.controller 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.domain.model.hideout.dto.JwtToken
import dev.usbharu.hideout.service.api.UserAuthApiService import dev.usbharu.hideout.service.api.UserAuthApiService
import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus

View File

@ -87,7 +87,6 @@ class RegisteredClientRepositoryImpl(private val database: Database) : Registere
} }
} }
// org/springframework/security/oauth2/server/authorization/client/oauth2-registered-client-schema.sql // org/springframework/security/oauth2/server/authorization/client/oauth2-registered-client-schema.sql
object RegisteredClient : Table("registered_client") { object RegisteredClient : Table("registered_client") {
val id = varchar("id", 100) val id = varchar("id", 100)
@ -108,7 +107,6 @@ object RegisteredClient : Table("registered_client") {
} }
fun ResultRow.toRegisteredClient(): SpringRegisteredClient { fun ResultRow.toRegisteredClient(): SpringRegisteredClient {
fun resolveClientAuthenticationMethods(string: String): ClientAuthenticationMethod { fun resolveClientAuthenticationMethods(string: String): ClientAuthenticationMethod {
return when (string) { return when (string) {
ClientAuthenticationMethod.CLIENT_SECRET_BASIC.value -> ClientAuthenticationMethod.CLIENT_SECRET_BASIC ClientAuthenticationMethod.CLIENT_SECRET_BASIC.value -> ClientAuthenticationMethod.CLIENT_SECRET_BASIC
@ -160,7 +158,6 @@ fun ResultRow.toRegisteredClient(): SpringRegisteredClient {
.scopes { it.addAll(clientScopes) } .scopes { it.addAll(clientScopes) }
.clientSettings(ClientSettings.withSettings(JsonUtil.jsonToMap(this[clientSettings])).build()) .clientSettings(ClientSettings.withSettings(JsonUtil.jsonToMap(this[clientSettings])).build())
val tokenSettingsMap = JsonUtil.jsonToMap<String, Any>(this[tokenSettings]) val tokenSettingsMap = JsonUtil.jsonToMap<String, Any>(this[tokenSettings])
val withSettings = TokenSettings.withSettings(tokenSettingsMap) val withSettings = TokenSettings.withSettings(tokenSettingsMap)
if (tokenSettingsMap.containsKey(ConfigurationSettingNames.Token.ACCESS_TOKEN_FORMAT)) { if (tokenSettingsMap.containsKey(ConfigurationSettingNames.Token.ACCESS_TOKEN_FORMAT)) {

View File

@ -10,7 +10,6 @@ import io.ktor.http.*
import org.koin.core.annotation.Single import org.koin.core.annotation.Single
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@Service @Service
interface APCreateService { interface APCreateService {
suspend fun receiveCreate(create: Create): ActivityPubResponse suspend fun receiveCreate(create: Create): ActivityPubResponse

View File

@ -11,7 +11,6 @@ import io.ktor.http.*
import org.koin.core.annotation.Single import org.koin.core.annotation.Single
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@Service @Service
interface APUndoService { interface APUndoService {
suspend fun receiveUndo(undo: Undo): ActivityPubResponse suspend fun receiveUndo(undo: Undo): ActivityPubResponse

View File

@ -105,7 +105,6 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository:
it[deviceCodeMetadata] = deviceCode?.metadata?.let { it1 -> JsonUtil.mapToJson(it1) } it[deviceCodeMetadata] = deviceCode?.metadata?.let { it1 -> JsonUtil.mapToJson(it1) }
} }
} }
} }
override fun remove(authorization: OAuth2Authorization?) { override fun remove(authorization: OAuth2Authorization?) {
@ -176,7 +175,6 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository:
} }
fun ResultRow.toAuthorization(): OAuth2Authorization { fun ResultRow.toAuthorization(): OAuth2Authorization {
val registeredClientId = this[Authorization.registeredClientId] val registeredClientId = this[Authorization.registeredClientId]
val registeredClient = registeredClientRepository.findById(registeredClientId) val registeredClient = registeredClientRepository.findById(registeredClientId)
@ -186,7 +184,7 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository:
val principalName = this[Authorization.principalName] val principalName = this[Authorization.principalName]
val authorizationGrantType = this[Authorization.authorizationGrantType] val authorizationGrantType = this[Authorization.authorizationGrantType]
val authorizedScopes = this[Authorization.authorizedScopes]?.split(",").orEmpty().toSet() val authorizedScopes = this[Authorization.authorizedScopes]?.split(",").orEmpty().toSet()
val attributes = this[Authorization.attributes]?.let { JsonUtil.jsonToMap<String, Any>(it) } ?: emptyMap() val attributes = this[Authorization.attributes]?.let { JsonUtil.jsonToMap<String, Any>(it) }.orEmpty()
builder.id(id).principalName(principalName) builder.id(id).principalName(principalName)
.authorizationGrantType(AuthorizationGrantType(authorizationGrantType)).authorizedScopes(authorizedScopes) .authorizationGrantType(AuthorizationGrantType(authorizationGrantType)).authorizedScopes(authorizedScopes)
@ -218,7 +216,7 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository:
val accessTokenIssuedAt = this[Authorization.accessTokenIssuedAt] val accessTokenIssuedAt = this[Authorization.accessTokenIssuedAt]
val accessTokenExpiresAt = this[Authorization.accessTokenExpiresAt] val accessTokenExpiresAt = this[Authorization.accessTokenExpiresAt]
val accessTokenMetadata = val accessTokenMetadata =
this[Authorization.accessTokenMetadata]?.let { JsonUtil.jsonToMap<String, Any>(it) } ?: emptyMap() this[Authorization.accessTokenMetadata]?.let { JsonUtil.jsonToMap<String, Any>(it) }.orEmpty()
val accessTokenType = val accessTokenType =
if (this[Authorization.accessTokenType].equals(OAuth2AccessToken.TokenType.BEARER.value, true)) { if (this[Authorization.accessTokenType].equals(OAuth2AccessToken.TokenType.BEARER.value, true)) {
OAuth2AccessToken.TokenType.BEARER OAuth2AccessToken.TokenType.BEARER
@ -229,7 +227,11 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository:
val accessTokenScope = this[Authorization.accessTokenScopes]?.split(",").orEmpty().toSet() val accessTokenScope = this[Authorization.accessTokenScopes]?.split(",").orEmpty().toSet()
val oAuth2AccessToken = OAuth2AccessToken( val oAuth2AccessToken = OAuth2AccessToken(
accessTokenType, accessTokenValue, accessTokenIssuedAt, accessTokenExpiresAt, accessTokenScope accessTokenType,
accessTokenValue,
accessTokenIssuedAt,
accessTokenExpiresAt,
accessTokenScope
) )
builder.token(oAuth2AccessToken) { it.putAll(accessTokenMetadata) } builder.token(oAuth2AccessToken) { it.putAll(accessTokenMetadata) }
@ -240,7 +242,7 @@ class ExposedOAuth2AuthorizationService(private val registeredClientRepository:
val oidcTokenIssuedAt = this[Authorization.oidcIdTokenIssuedAt] val oidcTokenIssuedAt = this[Authorization.oidcIdTokenIssuedAt]
val oidcTokenExpiresAt = this[Authorization.oidcIdTokenExpiresAt] val oidcTokenExpiresAt = this[Authorization.oidcIdTokenExpiresAt]
val oidcTokenMetadata = val oidcTokenMetadata =
this[Authorization.oidcIdTokenMetadata]?.let { JsonUtil.jsonToMap<String, Any>(it) } ?: emptyMap() this[Authorization.oidcIdTokenMetadata]?.let { JsonUtil.jsonToMap<String, Any>(it) }.or
val oidcIdToken = OidcIdToken( val oidcIdToken = OidcIdToken(
oidcIdTokenValue, oidcIdTokenValue,

View File

@ -19,7 +19,9 @@ class UserDetailsServiceImpl(private val userQueryService: UserQueryService, pri
transaction.transaction { transaction.transaction {
val findById = userQueryService.findByNameAndDomain(username, "") val findById = userQueryService.findByNameAndDomain(username, "")
User( User(
findById.name, findById.password, listOf() findById.name,
findById.password,
listOf()
) )
} }
} }

View File

@ -4,14 +4,12 @@ import org.springframework.security.authentication.AuthenticationManager
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
import org.springframework.security.web.util.matcher.AntPathRequestMatcher import org.springframework.security.web.util.matcher.AntPathRequestMatcher
class UsernamePasswordAuthFilter(jwtService: JwtService, authenticationManager: AuthenticationManager?) : class UsernamePasswordAuthFilter(jwtService: JwtService, authenticationManager: AuthenticationManager?) :
UsernamePasswordAuthenticationFilter(authenticationManager) { UsernamePasswordAuthenticationFilter(authenticationManager) {
init { init {
setRequiresAuthenticationRequestMatcher(AntPathRequestMatcher("/api/internal/v1/login", "POST")) setRequiresAuthenticationRequestMatcher(AntPathRequestMatcher("/api/internal/v1/login", "POST"))
this.setAuthenticationSuccessHandler { request, response, authentication -> this.setAuthenticationSuccessHandler { request, response, authentication ->
} }
} }
} }

View File

@ -12,5 +12,4 @@ object JsonUtil {
fun <K, V> jsonToMap(json: String, objectMapper: ObjectMapper = this.objectMapper): Map<K, V> = fun <K, V> jsonToMap(json: String, objectMapper: ObjectMapper = this.objectMapper): Map<K, V> =
objectMapper.readValue(json) objectMapper.readValue(json)
} }