diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt index 68538572..2ee0f07e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt @@ -10,7 +10,9 @@ import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.query.FollowerQueryService import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.core.service.user.UserService +import org.springframework.stereotype.Service +@Service class ApAcceptProcessor( transaction: Transaction, private val userQueryService: UserQueryService, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt index 99f4b159..efb37938 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt @@ -10,7 +10,9 @@ import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.query.PostQueryService +import org.springframework.stereotype.Service +@Service class APDeleteProcessor( transaction: Transaction, private val postQueryService: PostQueryService, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt index 847f4609..537606f4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt @@ -9,7 +9,9 @@ import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.external.job.ReceiveFollowJob import dev.usbharu.hideout.core.external.job.ReceiveFollowJobParam import dev.usbharu.hideout.core.service.job.JobQueueParentService +import org.springframework.stereotype.Service +@Service class APFollowProcessor( transaction: Transaction, private val jobQueueParentService: JobQueueParentService, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt index 8938f017..665c7c94 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt @@ -10,7 +10,9 @@ import dev.usbharu.hideout.activitypub.service.objects.user.APUserService import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.query.PostQueryService import dev.usbharu.hideout.core.service.reaction.ReactionService +import org.springframework.stereotype.Service +@Service class APLikeProcessor( transaction: Transaction, private val apUserService: APUserService, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt index 1fee5eda..1487eb56 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt @@ -8,7 +8,9 @@ import dev.usbharu.hideout.core.external.job.DeliverReactionJob import dev.usbharu.hideout.core.external.job.DeliverReactionJobParam import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.core.service.job.JobProcessor +import org.springframework.stereotype.Service +@Service class ApReactionJobProcessor( private val userQueryService: UserQueryService, private val apRequestService: APRequestService, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt index 6a873aca..285670b5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt @@ -11,8 +11,10 @@ import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJobParam import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.core.service.job.JobProcessor +import org.springframework.stereotype.Service import java.time.Instant +@Service class ApRemoveReactionJobProcessor( private val userQueryService: UserQueryService, private val transaction: Transaction, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index 16419348..2c8067a4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -9,7 +9,9 @@ import dev.usbharu.hideout.activitypub.service.objects.user.APUserService import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.core.service.user.UserService +import org.springframework.stereotype.Service +@Service class APUndoProcessor( transaction: Transaction, private val apUserService: APUserService, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt index 1bb106e3..0e04262e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt @@ -7,7 +7,9 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.application.external.Transaction import org.slf4j.Logger import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +@Service abstract class AbstractActivityPubProcessor( private val transaction: Transaction, private val allowUnauthorized: Boolean = false diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt index fc68f7fa..1e4aeb2d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt @@ -5,7 +5,6 @@ import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessor -import dev.usbharu.hideout.activitypub.service.common.ActivityType import dev.usbharu.hideout.activitypub.service.objects.user.APUserService import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException @@ -20,13 +19,12 @@ import dev.usbharu.httpsignature.common.PublicKey import dev.usbharu.httpsignature.verify.HttpSignatureVerifier import dev.usbharu.httpsignature.verify.Signature import dev.usbharu.httpsignature.verify.SignatureHeaderParser -import kjob.core.job.JobProps import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @Service class InboxJobProcessor( - private val activityPubProcessorList: List>, + private val activityPubProcessorList: List>, private val objectMapper: ObjectMapper, private val signatureHeaderParser: SignatureHeaderParser, private val signatureVerifier: HttpSignatureVerifier, @@ -34,42 +32,6 @@ class InboxJobProcessor( private val apUserService: APUserService, private val transaction: Transaction ) : JobProcessor { - suspend fun process(props: JobProps) { - val type = ActivityType.valueOf(props[InboxJob.type]) - val jsonString = objectMapper.readTree(props[InboxJob.json]) - val httpRequestString = props[InboxJob.httpRequest] - val headersString = props[InboxJob.headers] - - logger.info("START Process inbox. type: {}", type) - logger.trace("type: {} \njson: \n{}", type, jsonString.toPrettyString()) - - val map = objectMapper.readValue>>(headersString) - - val httpRequest = - objectMapper.readValue(httpRequestString).copy(headers = HttpHeaders(map)) - - logger.trace("request: {}\nheaders: {}", httpRequest, map) - - val signature = parseSignatureHeader(httpRequest.headers) - - logger.debug("Has signature? {}", signature != null) - - val verify = signature?.let { verifyHttpSignature(httpRequest, it) } ?: false - - logger.debug("Is verifying success? {}", verify) - - val activityPubProcessor = activityPubProcessorList.firstOrNull { it.isSupported(type) } - - if (activityPubProcessor == null) { - logger.warn("ActivityType {} is not support.", type) - throw IllegalStateException("ActivityPubProcessor not found.") - } - - val value = objectMapper.treeToValue(jsonString, activityPubProcessor.type()) - activityPubProcessor.process(ActivityPubProcessContext(value, jsonString, httpRequest, signature, verify)) - - logger.info("SUCCESS Process inbox. type: {}", type) - } private suspend fun verifyHttpSignature(httpRequest: HttpRequest, signature: Signature): Boolean { val user = try { @@ -116,7 +78,8 @@ class InboxJobProcessor( logger.debug("Is verifying success? {}", verify) - val activityPubProcessor = activityPubProcessorList.firstOrNull { it.isSupported(param.type) } + val activityPubProcessor = + activityPubProcessorList.firstOrNull { it.isSupported(param.type) } as ActivityPubProcessor? if (activityPubProcessor == null) { logger.warn("ActivityType {} is not support.", param.type) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt index df54350d..181f869a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt @@ -10,7 +10,9 @@ import dev.usbharu.hideout.core.external.job.DeliverPostJobParam import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.core.service.job.JobProcessor import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +@Service class ApNoteJobProcessor( private val transaction: Transaction, private val objectMapper: ObjectMapper,