diff --git a/hideout-core/build.gradle.kts b/hideout-core/build.gradle.kts
index ec38328f..52db4593 100644
--- a/hideout-core/build.gradle.kts
+++ b/hideout-core/build.gradle.kts
@@ -93,8 +93,8 @@ tasks.withType {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
}
- dependsOn("openApiGenerateMastodonCompatibleApi")
- mustRunAfter("openApiGenerateMastodonCompatibleApi")
+// dependsOn("openApiGenerateMastodonCompatibleApi")
+// mustRunAfter("openApiGenerateMastodonCompatibleApi")
}
diff --git a/hideout-core/src/intTest/kotlin/mastodon/filter/FilterTest.kt b/hideout-core/src/intTest/kotlin/mastodon/filter/FilterTest.kt
index bb3dccae..2732663e 100644
--- a/hideout-core/src/intTest/kotlin/mastodon/filter/FilterTest.kt
+++ b/hideout-core/src/intTest/kotlin/mastodon/filter/FilterTest.kt
@@ -17,7 +17,6 @@
package mastodon.filter
import dev.usbharu.hideout.SpringApplication
-import dev.usbharu.hideout.application.config.ActivityPubConfig
import dev.usbharu.hideout.domain.mastodon.model.generated.FilterKeywordsPostRequest
import dev.usbharu.hideout.domain.mastodon.model.generated.FilterPostRequest
import dev.usbharu.hideout.domain.mastodon.model.generated.FilterPostRequestKeyword
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt
deleted file mode 100644
index afe658a1..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.application.config
-
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.fasterxml.jackson.annotation.JsonSetter
-import com.fasterxml.jackson.annotation.Nulls
-import com.fasterxml.jackson.core.JsonParser
-import com.fasterxml.jackson.databind.DeserializationFeature
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.databind.module.SimpleModule
-import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
-import dev.usbharu.hideout.activitypub.domain.model.StringORObjectSerializer
-import dev.usbharu.hideout.activitypub.domain.model.StringOrObject
-import dev.usbharu.hideout.core.infrastructure.httpsignature.HttpRequestMixIn
-import dev.usbharu.httpsignature.common.HttpRequest
-import dev.usbharu.httpsignature.sign.HttpSignatureSigner
-import dev.usbharu.httpsignature.sign.RsaSha256HttpSignatureSigner
-import org.springframework.beans.factory.annotation.Qualifier
-import org.springframework.context.annotation.Bean
-import org.springframework.context.annotation.Configuration
-import java.time.format.DateTimeFormatter
-import java.util.*
-
-@Configuration
-class ActivityPubConfig {
-
- @Bean
- @Qualifier("activitypub")
- fun objectMapper(): ObjectMapper {
- val module = SimpleModule().addSerializer(StringOrObject::class.java, StringORObjectSerializer())
-
- val objectMapper = jacksonObjectMapper()
- .registerModules(module)
- .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
- .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
- .setDefaultSetterInfo(JsonSetter.Value.forContentNulls(Nulls.SKIP))
- .setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP))
- .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
- .configure(JsonParser.Feature.ALLOW_COMMENTS, true)
- .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
- .configure(JsonParser.Feature.ALLOW_TRAILING_COMMA, true)
- .addMixIn(HttpRequest::class.java, HttpRequestMixIn::class.java)
-
- return objectMapper
- }
-
- @Bean
- @Qualifier("http")
- fun dateTimeFormatter(): DateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
-
- @Bean
- fun httpSignatureSigner(): HttpSignatureSigner = RsaSha256HttpSignatureSigner()
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt
index 837a261c..0730dfb7 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt
@@ -16,43 +16,25 @@
package dev.usbharu.hideout.application.config
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.fasterxml.jackson.databind.module.SimpleModule
import com.nimbusds.jose.jwk.JWKSet
import com.nimbusds.jose.jwk.RSAKey
import com.nimbusds.jose.jwk.source.ImmutableJWKSet
import com.nimbusds.jose.jwk.source.JWKSource
import com.nimbusds.jose.proc.SecurityContext
-import dev.usbharu.hideout.activitypub.domain.model.StringORObjectSerializer
-import dev.usbharu.hideout.activitypub.domain.model.StringOrObject
-import dev.usbharu.hideout.core.application.shared.Transaction
-import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureFilter
-import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureHeaderChecker
-import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureUserDetailsService
-import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureVerifierComposite
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.UserDetailsImpl
-import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.UserDetailsServiceImpl
import dev.usbharu.hideout.util.RsaUtil
-import dev.usbharu.httpsignature.sign.RsaSha256HttpSignatureSigner
-import dev.usbharu.httpsignature.verify.DefaultSignatureHeaderParser
-import dev.usbharu.httpsignature.verify.RsaSha256HttpSignatureVerifier
import jakarta.annotation.PostConstruct
import jakarta.servlet.*
import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
-import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
-import org.springframework.context.annotation.Primary
import org.springframework.core.annotation.Order
import org.springframework.http.HttpMethod.GET
import org.springframework.http.HttpMethod.POST
import org.springframework.http.HttpStatus
-import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
-import org.springframework.security.authentication.AccountStatusUserDetailsChecker
import org.springframework.security.authentication.AuthenticationManager
import org.springframework.security.authentication.dao.DaoAuthenticationProvider
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
@@ -74,8 +56,6 @@ import org.springframework.security.oauth2.server.authorization.token.JwtEncodin
import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenCustomizer
import org.springframework.security.web.FilterChainProxy
import org.springframework.security.web.SecurityFilterChain
-import org.springframework.security.web.access.ExceptionTranslationFilter
-import org.springframework.security.web.authentication.AuthenticationEntryPointFailureHandler
import org.springframework.security.web.authentication.HttpStatusEntryPoint
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider
@@ -83,7 +63,6 @@ import org.springframework.security.web.context.AbstractSecurityWebApplicationIn
import org.springframework.security.web.debug.DebugFilter
import org.springframework.security.web.firewall.HttpFirewall
import org.springframework.security.web.firewall.RequestRejectedHandler
-import org.springframework.security.web.savedrequest.RequestCacheAwareFilter
import org.springframework.security.web.util.matcher.AnyRequestMatcher
import org.springframework.web.filter.CompositeFilter
import java.io.IOException
@@ -105,14 +84,9 @@ class SecurityConfig {
@Order(1)
fun httpSignatureFilterChain(
http: HttpSecurity,
- httpSignatureFilter: HttpSignatureFilter,
): SecurityFilterChain {
http {
securityMatcher("/users/*/posts/*")
- addFilterAt(httpSignatureFilter)
- addFilterBefore(
- ExceptionTranslationFilter(HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))
- )
authorizeHttpRequests {
authorize(anyRequest, permitAll)
}
@@ -130,57 +104,6 @@ class SecurityConfig {
return http.build()
}
- @Bean
- fun getHttpSignatureFilter(
- authenticationManager: AuthenticationManager,
- httpSignatureHeaderChecker: HttpSignatureHeaderChecker,
- ): HttpSignatureFilter {
- val httpSignatureFilter =
- HttpSignatureFilter(DefaultSignatureHeaderParser(), httpSignatureHeaderChecker)
- httpSignatureFilter.setAuthenticationManager(authenticationManager)
- httpSignatureFilter.setContinueFilterChainOnUnsuccessfulAuthentication(false)
- val authenticationEntryPointFailureHandler =
- AuthenticationEntryPointFailureHandler(HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))
- authenticationEntryPointFailureHandler.setRethrowAuthenticationServiceException(false)
- httpSignatureFilter.setAuthenticationFailureHandler(authenticationEntryPointFailureHandler)
- return httpSignatureFilter
- }
-
- @Bean
- @Order(2)
- fun daoAuthenticationProvider(userDetailsServiceImpl: UserDetailsServiceImpl): DaoAuthenticationProvider {
- val daoAuthenticationProvider = DaoAuthenticationProvider()
- daoAuthenticationProvider.setUserDetailsService(userDetailsServiceImpl)
-
- return daoAuthenticationProvider
- }
-
- @Bean
- @Order(1)
- fun httpSignatureAuthenticationProvider(
- transaction: Transaction,
- actorRepository: ActorRepository,
- ): PreAuthenticatedAuthenticationProvider {
- val provider = PreAuthenticatedAuthenticationProvider()
- val signatureHeaderParser = DefaultSignatureHeaderParser()
- provider.setPreAuthenticatedUserDetailsService(
- HttpSignatureUserDetailsService(
- HttpSignatureVerifierComposite(
- mapOf(
- "rsa-sha256" to RsaSha256HttpSignatureVerifier(
- signatureHeaderParser, RsaSha256HttpSignatureSigner()
- )
- ),
- signatureHeaderParser
- ),
- transaction,
- signatureHeaderParser,
- actorRepository
- )
- )
- provider.setUserDetailsChecker(AccountStatusUserDetailsChecker())
- return provider
- }
@Bean
@Order(2)
@@ -291,22 +214,6 @@ class SecurityConfig {
}
}
- @Bean
- @Primary
- fun jackson2ObjectMapperBuilderCustomizer(): Jackson2ObjectMapperBuilderCustomizer {
- return Jackson2ObjectMapperBuilderCustomizer {
- it.serializationInclusion(JsonInclude.Include.ALWAYS)
- .modulesToInstall(SimpleModule().addSerializer(StringOrObject::class.java, StringORObjectSerializer()))
- .serializers()
- }
- }
-
- @Bean
- fun mappingJackson2HttpMessageConverter(): MappingJackson2HttpMessageConverter {
- val builder = Jackson2ObjectMapperBuilder().serializationInclusion(JsonInclude.Include.NON_NULL)
- builder.modulesToInstall(SimpleModule().addSerializer(StringOrObject::class.java, StringORObjectSerializer()))
- return MappingJackson2HttpMessageConverter(builder.build())
- }
// Spring Security 3.2.1 に存在する EnableWebSecurity(debug = true)にすると発生するエラーに対処するためのコード
// trueにしないときはコメントアウト
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaService.kt
deleted file mode 100644
index 32615016..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaService.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.application.service.init
-
-import org.springframework.stereotype.Service
-
-@Service
-interface MetaService {
- suspend fun getMeta(): Meta
- suspend fun updateMeta(meta: Meta)
- suspend fun getJwtMeta(): Jwt
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImpl.kt
deleted file mode 100644
index 3ca63744..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/MetaServiceImpl.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.application.service.init
-
-import dev.usbharu.hideout.core.application.shared.Transaction
-import dev.usbharu.hideout.core.domain.exception.NotInitException
-import org.springframework.stereotype.Service
-
-@Service
-class MetaServiceImpl(private val metaRepository: MetaRepository, private val transaction: Transaction) :
- MetaService {
- override suspend fun getMeta(): Meta =
- transaction.transaction { metaRepository.get() ?: throw NotInitException("Meta is null") }
-
- override suspend fun updateMeta(meta: Meta): Unit = transaction.transaction {
- metaRepository.save(meta)
- }
-
- override suspend fun getJwtMeta(): Jwt = getMeta().jwt
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseService.kt
deleted file mode 100644
index ffec5686..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/service/init/ServerInitialiseService.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.application.service.init
-
-import org.springframework.stereotype.Service
-
-@Service
-interface ServerInitialiseService {
- suspend fun init()
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt
index 2a8c231e..0348c80f 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt
@@ -36,7 +36,7 @@ class UpdateLocalNoteApplicationService(
post.content = postContentFactoryImpl.create(updateLocalNote.content)
post.overview = updateLocalNote.overview?.let { PostOverview(it) }
- post.mediaIds = updateLocalNote.mediaIds.map { MediaId(it) }
+ post.addMediaIds(updateLocalNote.mediaIds.map { MediaId(it) })
post.sensitive = updateLocalNote.sensitive
postRepository.save(post)
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt
index 702f3246..8d13c8e6 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt
@@ -72,7 +72,7 @@ class Actor(
var moveTo = moveTo
set(value) {
- require(moveTo != id)
+ require(value != id)
addDomainEvent(ActorDomainEventFactory(this).createEvent(move))
field = value
}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt
index bd1c0c1b..178716a0 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt
@@ -85,4 +85,16 @@ data class ActorInstanceRelationship(
result = 31 * result + instanceId.hashCode()
return result
}
+
+ override fun toString(): String {
+ return "ActorInstanceRelationship(" +
+ "actorId=$actorId, " +
+ "instanceId=$instanceId, " +
+ "blocking=$blocking, " +
+ "muting=$muting, " +
+ "doNotSendPrivate=$doNotSendPrivate" +
+ ")"
+ }
+
+
}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt
index 529eb3af..5c3eddf6 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt
@@ -28,4 +28,18 @@ data class Media(
val mimeType: MimeType,
val blurHash: MediaBlurHash?,
val description: MediaDescription? = null,
-)
+) {
+ override fun toString(): String {
+ return "Media(" +
+ "id=$id, " +
+ "name=$name, " +
+ "url=$url, " +
+ "remoteUrl=$remoteUrl, " +
+ "thumbnailUrl=$thumbnailUrl, " +
+ "type=$type, " +
+ "mimeType=$mimeType, " +
+ "blurHash=$blurHash, " +
+ "description=$description" +
+ ")"
+ }
+}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt
index d992a78e..f1846382 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt
@@ -24,7 +24,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
import java.net.URI
import java.time.Instant
-class Post private constructor(
+class Post(
val id: PostId,
actorId: ActorId,
overview: PostOverview? = null,
@@ -191,8 +191,8 @@ class Post private constructor(
return id.hashCode()
}
- abstract class PostFactory {
- protected fun create(
+ companion object {
+ fun create(
id: PostId,
actorId: ActorId,
overview: PostOverview? = null,
@@ -206,24 +206,30 @@ class Post private constructor(
apId: URI,
deleted: Boolean,
mediaIds: List,
- hide: Boolean,
+ visibleActors: List = emptyList(),
+ hide: Boolean = false,
+ moveTo: PostId? = null,
): Post {
- return Post(
- id = id,
- actorId = actorId,
- overview = overview,
- content = content,
- createdAt = createdAt,
- visibility = visibility,
- url = url,
- repostId = repostId,
- replyId = replyId,
- sensitive = sensitive,
- apId = apId,
- deleted = deleted,
- mediaIds = mediaIds,
- hide = hide
- ).apply { addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.create)) }
+ val post = Post(
+ id,
+ actorId,
+ overview,
+ content,
+ createdAt,
+ visibility,
+ url,
+ repostId,
+ replyId,
+ sensitive,
+ apId,
+ deleted,
+ mediaIds,
+ visibleActors,
+ hide,
+ moveTo
+ )
+ post.addDomainEvent(PostDomainEventFactory(post).createEvent(PostEvent.create))
+ return post
}
}
}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt
index c4ef154b..d7bf7ba8 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt
@@ -26,5 +26,5 @@ interface IRemoteActorCheckDomainService {
@Service
class RemoteActorCheckDomainService(private val applicationConfig: ApplicationConfig) : IRemoteActorCheckDomainService {
- override fun isRemoteActor(actor: Actor): Boolean = actor.domain.domain == applicationConfig.url.host
+ override fun isRemoteActor(actor: Actor): Boolean = actor.domain.domain != applicationConfig.url.host
}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt
deleted file mode 100644
index b7b19949..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptTask.kt
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.domain.model.Accept
-import dev.usbharu.owl.common.property.*
-import dev.usbharu.owl.common.task.PropertyDefinition
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class DeliverAcceptTask(
- val accept: Accept,
- val inbox: String,
- val signer: Long,
-) : Task()
-
-@Component
-data object DeliverAcceptTaskDef : TaskDefinition {
- override val name: String
- get() = "DeliverAccept"
- override val priority: Int
- get() = 10
- override val maxRetry: Int
- get() = 5
- override val retryPolicy: String
- get() = ""
- override val timeoutMilli: Long
- get() = 1000
- override val propertyDefinition: PropertyDefinition
- get() = PropertyDefinition(
- mapOf(
- "accept" to PropertyType.binary,
- "inbox" to PropertyType.string,
- "signer" to PropertyType.number,
- )
- )
- override val type: Class
- get() = DeliverAcceptTask::class.java
-
- override fun serialize(task: DeliverAcceptTask): Map> {
- return mapOf(
- "accept" to ObjectPropertyValue(task.accept),
- "inbox" to StringPropertyValue(task.inbox),
- "signer" to LongPropertyValue(task.signer)
- )
- }
-
- override fun deserialize(value: Map>): DeliverAcceptTask {
- return DeliverAcceptTask(
- value.getValue("accept").value as Accept,
- value.getValue("inbox").value as String,
- value.getValue("signer").value as Long,
- )
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt
deleted file mode 100644
index 2c645290..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverCreateTask.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.domain.model.Create
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class DeliverCreateTask(
- val create: Create,
- val inbox: String,
- val actor: String,
-) : Task()
-
-@Component
-data object DeliverCreateTaskDef : TaskDefinition {
- override val type: Class
- get() = DeliverCreateTask::class.java
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt
deleted file mode 100644
index 6ce63ad2..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverDeleteTask.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.domain.model.Delete
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class DeliverDeleteTask(
- val delete: Delete,
- val inbox: String,
- val signer: Long,
-) : Task()
-
-@Component
-data object DeliverDeleteTaskDef : TaskDefinition {
- override val type: Class
- get() = DeliverDeleteTask::class.java
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt
deleted file mode 100644
index c1c73154..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverReactionTask.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.domain.model.Like
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class DeliverReactionTask(
- val actor: String,
- val like: Like,
- val inbox: String,
-) : Task()
-
-@Component
-data object DeliverReactionTaskDef : TaskDefinition {
- override val type: Class
- get() = DeliverReactionTask::class.java
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectTask.kt
deleted file mode 100644
index 5bb47432..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectTask.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.domain.model.Reject
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class DeliverRejectTask(
- val reject: Reject,
- val inbox: String,
- val signer: Long,
-) : Task()
-
-@Component
-data object DeliverRejectTaskDef : TaskDefinition {
- override val type: Class
- get() = DeliverRejectTask::class.java
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt
deleted file mode 100644
index 3ae7f129..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoTask.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.domain.model.Undo
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class DeliverUndoTask(
- val undo: Undo,
- val inbox: String,
- val signer: Long,
-) : Task()
-
-@Component
-data object DeliverUndoTaskDef : TaskDefinition {
- override val type: Class
- get() = DeliverUndoTask::class.java
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt
deleted file mode 100644
index de6b926f..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/InboxTask.kt
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.service.common.ActivityType
-import dev.usbharu.httpsignature.common.HttpRequest
-import dev.usbharu.owl.common.property.ObjectPropertyValue
-import dev.usbharu.owl.common.property.PropertyValue
-import dev.usbharu.owl.common.property.StringPropertyValue
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class InboxTask(
- val json: String,
- val type: ActivityType,
- val httpRequest: HttpRequest,
- val headers: Map>,
-) : Task()
-
-@Component
-data object InboxTaskDef : TaskDefinition {
- override val type: Class
- get() = InboxTask::class.java
-
- override fun serialize(task: InboxTask): Map> {
- return mapOf(
- "json" to StringPropertyValue(task.json),
- "type" to ObjectPropertyValue(task.type),
- "httpRequest" to ObjectPropertyValue(task.httpRequest),
- "headers" to ObjectPropertyValue(task.headers),
- )
- }
-
- override fun deserialize(value: Map>): InboxTask {
- return InboxTask(
- value.getValue("json").value as String,
- value.getValue("type").value as ActivityType,
- value.getValue("httpRequest").value as HttpRequest,
- value.getValue("headers").value as Map>,
- )
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt
deleted file mode 100644
index a72b0d5a..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/ReceiveFollowTask.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.hideout.activitypub.domain.model.Follow
-import dev.usbharu.owl.common.property.ObjectPropertyValue
-import dev.usbharu.owl.common.property.PropertyValue
-import dev.usbharu.owl.common.property.StringPropertyValue
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class ReceiveFollowTask(
- val actor: String,
- val follow: Follow,
- val targetActor: String,
-) : Task()
-
-@Component
-data object ReceiveFollowTaskDef : TaskDefinition {
- override val type: Class
- get() = ReceiveFollowTask::class.java
-
- override fun serialize(task: ReceiveFollowTask): Map> {
- return mapOf(
- "actor" to StringPropertyValue(task.actor),
- "follow" to ObjectPropertyValue(task.follow),
- "targetActor" to StringPropertyValue(task.targetActor)
- )
- }
-
- override fun deserialize(value: Map>): ReceiveFollowTask {
- return ReceiveFollowTask(
- value.getValue("actor").value as String,
- value.getValue("follow").value as Follow,
- value.getValue("targetActor").value as String,
- )
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/UpdateActorTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/UpdateActorTask.kt
deleted file mode 100644
index 5fc1a272..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/UpdateActorTask.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.external.job
-
-import dev.usbharu.owl.common.task.Task
-import dev.usbharu.owl.common.task.TaskDefinition
-import org.springframework.stereotype.Component
-
-data class UpdateActorTask(
- val id: Long,
- val apId: String,
-) : Task()
-
-@Component
-data object UpdateActorTaskDef : TaskDefinition {
- override val type: Class
- get() = UpdateActorTask::class.java
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt
index 871b67b6..1273b68c 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt
@@ -59,7 +59,8 @@ class ActorFactoryImpl(
postsCount = ActorPostsCount(0),
lastPostAt = null,
suspend = false,
- emojiIds = emptySet()
+ emojiIds = emptySet(),
+ deleted = false
)
}
}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt
index 9e240543..f28dd0d1 100644
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt
@@ -34,7 +34,7 @@ class PostFactoryImpl(
private val idGenerateService: IdGenerateService,
private val postContentFactoryImpl: PostContentFactoryImpl,
private val applicationConfig: ApplicationConfig,
-) : Post.PostFactory() {
+) {
suspend fun createLocal(
actorId: ActorId,
actorName: ActorName,
@@ -48,7 +48,7 @@ class PostFactoryImpl(
): Post {
val id = idGenerateService.generateId()
val url = URI.create(applicationConfig.url.toString() + "/users/" + actorName + "/posts/" + id)
- return super.create(
+ return Post.create(
PostId(id),
actorId,
overview,
@@ -61,7 +61,7 @@ class PostFactoryImpl(
sensitive,
url,
false,
- mediaIds
+ mediaIds,
)
}
}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureFilter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureFilter.kt
deleted file mode 100644
index 27886cfb..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureFilter.kt
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
-
-import dev.usbharu.httpsignature.common.HttpHeaders
-import dev.usbharu.httpsignature.common.HttpMethod
-import dev.usbharu.httpsignature.common.HttpRequest
-import dev.usbharu.httpsignature.verify.SignatureHeaderParser
-import jakarta.servlet.http.HttpServletRequest
-import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter
-import java.net.URL
-
-class HttpSignatureFilter(
- private val httpSignatureHeaderParser: SignatureHeaderParser,
- private val httpSignatureHeaderChecker: HttpSignatureHeaderChecker,
-) :
- AbstractPreAuthenticatedProcessingFilter() {
- override fun getPreAuthenticatedPrincipal(request: HttpServletRequest?): Any? {
- val headersList = request?.headerNames?.toList().orEmpty()
-
- val headers =
- headersList.associateWith { header -> request?.getHeaders(header)?.toList().orEmpty() }
-
- val signature = try {
- httpSignatureHeaderParser.parse(HttpHeaders(headers))
- } catch (_: IllegalArgumentException) {
- return null
- } catch (_: RuntimeException) {
- return ""
- }
- return signature.keyId
- }
-
- override fun getPreAuthenticatedCredentials(request: HttpServletRequest?): Any? {
- requireNotNull(request)
- val url = request.requestURL.toString()
-
- val headersList = request.headerNames?.toList().orEmpty()
-
- val headers =
- headersList.associateWith { header -> request.getHeaders(header)?.toList().orEmpty() }
-
- val method = when (val method = request.method.lowercase()) {
- "get" -> HttpMethod.GET
- "post" -> HttpMethod.POST
- else -> {
-// throw IllegalArgumentException("Unsupported method: $method")
- return null
- }
- }
-
- try {
- httpSignatureHeaderChecker.checkDate(request.getHeader("date")!!)
- httpSignatureHeaderChecker.checkHost(request.getHeader("host")!!)
- if (request.method.equals("post", true)) {
- httpSignatureHeaderChecker.checkDigest(
- request.inputStream.readAllBytes()!!,
- request.getHeader("digest")!!
- )
- }
- } catch (_: NullPointerException) {
- return null
- } catch (_: IllegalArgumentException) {
- return null
- }
-
- return HttpRequest(
- URL(url + request.queryString.orEmpty()),
- HttpHeaders(headers),
- method
- )
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureHeaderChecker.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureHeaderChecker.kt
deleted file mode 100644
index eab673cb..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureHeaderChecker.kt
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
-
-import dev.usbharu.hideout.application.config.ApplicationConfig
-import dev.usbharu.hideout.util.Base64Util
-import org.springframework.stereotype.Component
-import java.security.MessageDigest
-import java.time.Instant
-import java.time.format.DateTimeFormatter
-import java.util.*
-
-@Component
-class HttpSignatureHeaderChecker(private val applicationConfig: ApplicationConfig) {
- fun checkDate(date: String) {
- val from = Instant.from(dateFormat.parse(date))
-
- if (from.isAfter(Instant.now()) || from.isBefore(Instant.now().minusSeconds(86400))) {
- throw IllegalArgumentException("未来")
- }
- }
-
- fun checkHost(host: String) {
- if (applicationConfig.url.host.equals(host, true).not()) {
- throw IllegalArgumentException("ホスト名が違う")
- }
- }
-
- fun checkDigest(byteArray: ByteArray, digest: String) {
- val find = regex.find(digest)
- val sha256 = MessageDigest.getInstance("SHA-256")
-
- val other = find?.groups?.get(2)?.value.orEmpty()
-
- if (Base64Util.encode(sha256.digest(byteArray)).equals(other, true).not()) {
- throw IllegalArgumentException("リクエストボディが違う")
- }
- }
-
- companion object {
- private val dateFormat = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
- private val regex = Regex("^([a-zA-Z0-9\\-]+)=(.+)$")
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUser.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUser.kt
deleted file mode 100644
index 50fc2c4e..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUser.kt
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
-
-import org.springframework.security.core.GrantedAuthority
-import org.springframework.security.core.userdetails.User
-import java.io.Serial
-
-class HttpSignatureUser(
- username: String,
- val domain: String,
- val id: Long,
- credentialsNonExpired: Boolean,
- accountNonLocked: Boolean,
- authorities: MutableCollection?
-) : User(
- username,
- "",
- true,
- true,
- credentialsNonExpired,
- accountNonLocked,
- authorities
-) {
-
- override fun equals(other: Any?): Boolean {
- if (this === other) return true
- if (other !is HttpSignatureUser) return false
- if (!super.equals(other)) return false
-
- if (domain != other.domain) return false
- if (id != other.id) return false
-
- return true
- }
-
- override fun hashCode(): Int {
- var result = super.hashCode()
- result = 31 * result + domain.hashCode()
- result = 31 * result + id.hashCode()
- return result
- }
-
- override fun toString(): String {
- return "HttpSignatureUser(" +
- "domain='$domain', " +
- "id=$id" +
- ")" +
- " ${super.toString()}"
- }
-
- companion object {
- @Serial
- private const val serialVersionUID: Long = -3330552099960982997L
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt
deleted file mode 100644
index 36c61d4c..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
-
-import dev.usbharu.hideout.core.application.shared.Transaction
-import dev.usbharu.hideout.core.domain.exception.HttpSignatureVerifyException
-import dev.usbharu.hideout.util.RsaUtil
-import dev.usbharu.httpsignature.common.HttpMethod
-import dev.usbharu.httpsignature.common.HttpRequest
-import dev.usbharu.httpsignature.common.PublicKey
-import dev.usbharu.httpsignature.verify.FailedVerification
-import dev.usbharu.httpsignature.verify.HttpSignatureVerifier
-import dev.usbharu.httpsignature.verify.SignatureHeaderParser
-import kotlinx.coroutines.runBlocking
-import org.slf4j.LoggerFactory
-import org.springframework.security.authentication.BadCredentialsException
-import org.springframework.security.core.userdetails.AuthenticationUserDetailsService
-import org.springframework.security.core.userdetails.UserDetails
-import org.springframework.security.core.userdetails.UsernameNotFoundException
-import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken
-
-class HttpSignatureUserDetailsService(
- private val httpSignatureVerifier: HttpSignatureVerifier,
- private val transaction: Transaction,
- private val httpSignatureHeaderParser: SignatureHeaderParser,
- private val actorRepository: ActorRepository
-) :
- AuthenticationUserDetailsService {
- override fun loadUserDetails(token: PreAuthenticatedAuthenticationToken): UserDetails = runBlocking {
- check(token.principal is String) { "Token is not String" }
- val credentials = token.credentials
-
- check(credentials is HttpRequest) { "Credentials is not HttpRequest" }
-
- val keyId = token.principal as String
- val findByKeyId = transaction.transaction {
- actorRepository.findByKeyId(keyId) ?: throw UsernameNotFoundException("keyId: $keyId not found.")
- }
-
- val signature = httpSignatureHeaderParser.parse(credentials.headers)
-
- val requiredHeaders = when (credentials.method) {
- HttpMethod.GET -> getRequiredHeaders
- HttpMethod.POST -> postRequiredHeaders
- }
- if (signature.headers.containsAll(requiredHeaders).not()) {
- logger.warn(
- "FAILED Verify HTTP Signature. required headers: {} but actual: {}",
- requiredHeaders,
- signature.headers
- )
- throw BadCredentialsException("HTTP Signature. required headers: $requiredHeaders")
- }
-
- @Suppress("TooGenericExceptionCaught")
- val verify = try {
- httpSignatureVerifier.verify(
- credentials,
- PublicKey(RsaUtil.decodeRsaPublicKeyPem(findByKeyId.publicKey), keyId)
- )
- } catch (e: RuntimeException) {
- throw BadCredentialsException("", e)
- }
-
- if (verify is FailedVerification) {
- logger.warn("FAILED Verify HTTP Signature reason: {}", verify.reason)
- throw HttpSignatureVerifyException(verify.reason)
- }
-
- HttpSignatureUser(
- username = findByKeyId.name,
- domain = findByKeyId.domain,
- id = findByKeyId.id,
- credentialsNonExpired = true,
- accountNonLocked = true,
- authorities = mutableListOf()
- )
- }
-
- companion object {
- private val logger = LoggerFactory.getLogger(HttpSignatureUserDetailsService::class.java)
- private val postRequiredHeaders = listOf("(request-target)", "date", "host", "digest")
- private val getRequiredHeaders = listOf("(request-target)", "date", "host")
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureVerifierComposite.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureVerifierComposite.kt
deleted file mode 100644
index 8dd83ee3..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureVerifierComposite.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
-
-import dev.usbharu.httpsignature.common.HttpRequest
-import dev.usbharu.httpsignature.common.PublicKey
-import dev.usbharu.httpsignature.verify.HttpSignatureVerifier
-import dev.usbharu.httpsignature.verify.SignatureHeaderParser
-import dev.usbharu.httpsignature.verify.VerificationResult
-
-class HttpSignatureVerifierComposite(
- private val map: Map,
- private val httpSignatureHeaderParser: SignatureHeaderParser
-) : HttpSignatureVerifier {
- override fun verify(httpRequest: HttpRequest, key: PublicKey): VerificationResult {
- val signature = httpSignatureHeaderParser.parse(httpRequest.headers)
- val verify = map[signature.algorithm]?.verify(httpRequest, key)
- if (verify != null) {
- return verify
- }
-
- throw IllegalArgumentException("Unsupported algorithm. ${signature.algorithm}")
- }
-
- override fun equals(other: Any?): Boolean {
- if (this === other) return true
- if (javaClass != other?.javaClass) return false
-
- other as HttpSignatureVerifierComposite
-
- if (map != other.map) return false
- if (httpSignatureHeaderParser != other.httpSignatureHeaderParser) return false
-
- return true
- }
-
- override fun hashCode(): Int {
- var result = map.hashCode()
- result = 31 * result + httpSignatureHeaderParser.hashCode()
- return result
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt
deleted file mode 100644
index 04b1f298..00000000
--- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsServiceImpl.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.core.infrastructure.springframework.oauth2
-
-import dev.usbharu.hideout.application.config.ApplicationConfig
-import dev.usbharu.hideout.core.application.shared.Transaction
-import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException
-import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
-import kotlinx.coroutines.runBlocking
-import org.springframework.security.core.userdetails.UserDetails
-import org.springframework.security.core.userdetails.UserDetailsService
-import org.springframework.security.core.userdetails.UsernameNotFoundException
-import org.springframework.stereotype.Service
-
-@Service
-class UserDetailsServiceImpl(
- private val applicationConfig: ApplicationConfig,
- private val userDetailRepository: UserDetailRepository,
- private val transaction: Transaction,
- private val actorRepository: ActorRepository
-) :
- UserDetailsService {
- override fun loadUserByUsername(username: String?): UserDetails = runBlocking {
- if (username == null) {
- throw UsernameNotFoundException("$username not found")
- }
- transaction.transaction {
- val findById =
- actorRepository.findByNameAndDomain(username, applicationConfig.url.host)
- ?: throw UserNotFoundException.withNameAndDomain(username, applicationConfig.url.host)
-
- val userDetails = userDetailRepository.findByActorId(findById.id)
- ?: throw UsernameNotFoundException("${findById.id} not found.")
- UserDetailsImpl(
- id = findById.id,
- username = findById.name,
- password = userDetails.password,
- enabled = true,
- accountNonExpired = true,
- credentialsNonExpired = true,
- accountNonLocked = true,
- authorities = mutableListOf()
- )
- }
- }
-}
diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt
new file mode 100644
index 00000000..5819c47b
--- /dev/null
+++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostContentFormatter.kt
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2024 usbharu
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dev.usbharu.hideout.core.service.post
+
+import org.jsoup.Jsoup
+import org.jsoup.nodes.Document
+import org.jsoup.nodes.Element
+import org.jsoup.nodes.TextNode
+import org.jsoup.select.Elements
+import org.owasp.html.PolicyFactory
+import org.springframework.stereotype.Service
+
+
+interface PostContentFormatter {
+ fun format(content: String): FormattedPostContent
+}
+
+@Service
+class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : PostContentFormatter {
+ override fun format(content: String): FormattedPostContent {
+ // まず不正なHTMLを整形する
+ val document = Jsoup.parseBodyFragment(content)
+ val outputSettings = Document.OutputSettings()
+ outputSettings.prettyPrint(false)
+
+ document.outputSettings(outputSettings)
+
+ val unsafeElement = document.getElementsByTag("body").first() ?: return FormattedPostContent(
+ "",
+ ""
+ )
+
+ // 文字だけのHTMLなどはここでpタグで囲む
+ val flattenHtml = unsafeElement.childNodes().mapNotNull {
+ if (it is Element) {
+ it
+ } else if (it is TextNode) {
+ Element("p").appendText(it.text())
+ } else {
+ null
+ }
+ }.filter { it.text().isNotBlank() }
+
+ // HTMLのサニタイズをする
+ val unsafeHtml = Elements(flattenHtml).outerHtml()
+
+ val safeHtml = policyFactory.sanitize(unsafeHtml)
+
+ val safeDocument =
+ Jsoup.parseBodyFragment(safeHtml).getElementsByTag("body").first() ?: return FormattedPostContent("", "")
+
+ val formattedHtml = mutableListOf()
+
+ // 連続するbrタグを段落に変換する
+ for (element in safeDocument.children()) {
+ var brCount = 0
+ var prevIndex = 0
+ val childNodes = element.childNodes()
+ for ((index, childNode) in childNodes.withIndex()) {
+ if (childNode is Element && childNode.tagName() == "br") {
+ brCount++
+ } else if (brCount >= 2) {
+ formattedHtml.add(Element("p").appendChildren(childNodes.subList(prevIndex, index - brCount)))
+ prevIndex = index
+ }
+ }
+ formattedHtml.add(Element("p").appendChildren(childNodes.subList(prevIndex, childNodes.size)))
+ }
+
+ val elements = Elements(formattedHtml)
+
+ return FormattedPostContent(elements.outerHtml().replace("\n", ""), printHtml(elements))
+ }
+
+ private fun printHtml(element: Elements): String {
+ return element.joinToString("\n\n") {
+ it.childNodes().joinToString("") { node ->
+ if (node is Element && node.tagName() == "br") {
+ "\n"
+ } else if (node is Element) {
+ node.text()
+ } else if (node is TextNode) {
+ node.text()
+ } else {
+ ""
+ }
+ }
+ }
+ }
+}
+
+data class FormattedPostContent(
+ val html: String,
+ val content: String,
+)
\ No newline at end of file
diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt
index b25ec4a2..96f3655f 100644
--- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt
+++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt
@@ -124,7 +124,7 @@ class EqualsAndToStringTest {
}
try {
ToStringVerifier.forClass(it).withPreset(Presets.INTELLI_J).verify()
- } catch (e: Exception) {
+ } catch (e: Throwable) {
e.printStackTrace()
}
}
diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/AnnounceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/AnnounceTest.kt
deleted file mode 100644
index ed037bd6..00000000
--- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/AnnounceTest.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.activitypub.domain.model
-
-import com.fasterxml.jackson.module.kotlin.readValue
-import dev.usbharu.hideout.application.config.ActivityPubConfig
-import org.junit.jupiter.api.Test
-
-class AnnounceTest{
- @Test
- fun mastodonのjsonをデシリアライズできる() {
- //language=JSON
- val json = """{
- "@context": "https://www.w3.org/ns/activitystreams",
- "id": "https://kb.usbharu.dev/users/usbharu/statuses/111859915842276344/activity",
- "type": "Announce",
- "actor": "https://kb.usbharu.dev/users/usbharu",
- "published": "2024-02-02T04:07:40Z",
- "to": [
- "https://kb.usbharu.dev/users/usbharu/followers"
- ],
- "cc": [
- "https://kb.usbharu.dev/users/usbharu"
- ],
- "object": "https://kb.usbharu.dev/users/usbharu/statuses/111850484548963326"
-}"""
-
- val objectMapper = ActivityPubConfig().objectMapper()
-
- val readValue = objectMapper.readValue(json)
-
-
- }
-}
\ No newline at end of file
diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/CreateTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/CreateTest.kt
deleted file mode 100644
index ce633497..00000000
--- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/CreateTest.kt
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2024 usbharu
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dev.usbharu.hideout.activitypub.domain.model
-
-import com.fasterxml.jackson.module.kotlin.readValue
-import dev.usbharu.hideout.application.config.ActivityPubConfig
-import org.intellij.lang.annotations.Language
-import org.junit.jupiter.api.Test
-
-class CreateTest {
- @Test
- fun Createのデイシリアライズができる() {
- @Language("JSON") val json = """{
- "@context": [
- "https://www.w3.org/ns/activitystreams",
- "https://w3id.org/security/v1",
- {
- "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
- "sensitive": "as:sensitive",
- "Hashtag": "as:Hashtag",
- "quoteUrl": "as:quoteUrl",
- "toot": "http://joinmastodon.org/ns#",
- "Emoji": "toot:Emoji",
- "featured": "toot:featured",
- "discoverable": "toot:discoverable",
- "schema": "http://schema.org#",
- "PropertyValue": "schema:PropertyValue",
- "value": "schema:value",
- "misskey": "https://misskey-hub.net/ns#",
- "_misskey_content": "misskey:_misskey_content",
- "_misskey_quote": "misskey:_misskey_quote",
- "_misskey_reaction": "misskey:_misskey_reaction",
- "_misskey_votes": "misskey:_misskey_votes",
- "isCat": "misskey:isCat",
- "vcard": "http://www.w3.org/2006/vcard/ns#"
- }
- ],
- "id": "https://misskey.usbharu.dev/notes/9f2i9cm88e/activity",
- "actor": "https://misskey.usbharu.dev/users/97ws8y3rj6",
- "type": "Create",
- "published": "2023-05-22T14:26:53.600Z",
- "object": {
- "id": "https://misskey.usbharu.dev/notes/9f2i9cm88e",
- "type": "Note",
- "attributedTo": "https://misskey.usbharu.dev/users/97ws8y3rj6",
- "content": "