feat: Createのアクティビティに対応

This commit is contained in:
usbharu 2023-11-22 02:14:21 +09:00
parent 89c299d3c0
commit 3009ca1532
3 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,14 @@
package dev.usbharu.hideout.activitypub.domain.exception
class HttpSignatureUnauthorizedException : RuntimeException {
constructor() : super()
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super(
message,
cause,
enableSuppression,
writableStackTrace
)
}

View File

@ -2,14 +2,21 @@ package dev.usbharu.hideout.activitypub.service.tmp
import dev.usbharu.hideout.activitypub.domain.exception.ActivityPubProcessException import dev.usbharu.hideout.activitypub.domain.exception.ActivityPubProcessException
import dev.usbharu.hideout.activitypub.domain.exception.FailedProcessException import dev.usbharu.hideout.activitypub.domain.exception.FailedProcessException
import dev.usbharu.hideout.activitypub.domain.exception.HttpSignatureUnauthorizedException
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.application.external.Transaction
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
abstract class AbstractActivityPubProcessor<T : Object>(val transaction: Transaction) : ActivityPubProcessor<T> { abstract class AbstractActivityPubProcessor<T : Object>(
private val transaction: Transaction,
private val allowUnauthorized: Boolean = false
) : ActivityPubProcessor<T> {
private val logger = LoggerFactory.getLogger(this::class.java) private val logger = LoggerFactory.getLogger(this::class.java)
override suspend fun process(activity: ActivityPubProcessContext<T>) { override suspend fun process(activity: ActivityPubProcessContext<T>) {
if (activity.isAuthorized.not() && allowUnauthorized.not()) {
throw HttpSignatureUnauthorizedException()
}
logger.info("START ActivityPub process") logger.info("START ActivityPub process")
try { try {
transaction.transaction { transaction.transaction {

View File

@ -0,0 +1,22 @@
package dev.usbharu.hideout.activitypub.service.tmp.impl
import dev.usbharu.hideout.activitypub.domain.model.Create
import dev.usbharu.hideout.activitypub.domain.model.Note
import dev.usbharu.hideout.activitypub.service.common.ActivityType
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService
import dev.usbharu.hideout.activitypub.service.tmp.AbstractActivityPubProcessor
import dev.usbharu.hideout.activitypub.service.tmp.ActivityPubProcessContext
import dev.usbharu.hideout.application.external.Transaction
import org.springframework.stereotype.Service
@Service
class CreateActivityProcessor(transaction: Transaction, private val apNoteService: APNoteService) :
AbstractActivityPubProcessor<Create>(transaction, false) {
override suspend fun internalProcess(activity: ActivityPubProcessContext<Create>) {
apNoteService.fetchNote(activity.activity.`object` as Note)
}
override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Create
override fun type(): Class<Create> = Create::class.java
}