feat: Actorのエンドポイントを追加

This commit is contained in:
usbharu 2024-11-09 07:34:23 +09:00
parent 4c62651da5
commit 22bd24304c
Signed by: usbharu
GPG Key ID: 95CBCF7046307B77
5 changed files with 78 additions and 1 deletions

View File

@ -4,6 +4,12 @@ plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.detekt)
alias(libs.plugins.kover)
alias(libs.plugins.spring.boot)
alias(libs.plugins.kotlin.spring)
}
apply {
plugin("io.spring.dependency-management")
}
group = "dev.usbharu"
@ -17,6 +23,8 @@ dependencies {
testImplementation(kotlin("test"))
detektPlugins(libs.detekt.formatting)
implementation("dev.usbharu:hideout-core:0.0.1")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation(libs.bundles.jackson)
}

View File

@ -0,0 +1,22 @@
package dev.usbharu.hideout.activitypub.application.actor
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@Service
class GetActorApplicationService(transaction: Transaction) : AbstractApplicationService<String, Actor>(
transaction,
logger
) {
override suspend fun internalExecute(command: String, principal: Principal): Actor {
TODO()
}
companion object {
private val logger = LoggerFactory.getLogger(GetActorApplicationService::class.java)
}
}

View File

@ -0,0 +1,27 @@
package dev.usbharu.hideout.activitypub.config
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.annotation.Order
import org.springframework.http.HttpMethod.GET
import org.springframework.http.HttpMethod.POST
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.invoke
import org.springframework.security.web.SecurityFilterChain
@Configuration
class ActivityPubSecurityConfig {
@Bean
@Order(4)
fun activityPubSecurityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
authorizeHttpRequests {
authorize(POST, "/inbox", permitAll)
authorize(POST, "/users/{username}/inbox", permitAll)
authorize(GET, "/outbox", permitAll)
authorize(GET, "/users/{username}/outbox", permitAll)
}
}
return http.build()
}
}

View File

@ -0,0 +1,20 @@
package dev.usbharu.hideout.activitypub.`interface`.api
import dev.usbharu.hideout.activitypub.application.actor.GetActorApplicationService
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
@Controller
class APActorController(private val getActorApplicationService: GetActorApplicationService) {
@GetMapping(
"/users/{username}",
consumes = ["application/activity+json"],
produces = ["application/activity+json"]
)
suspend fun user(@PathVariable username: String): Actor {
return getActorApplicationService.execute(username, Anonymous)
}
}

View File

@ -75,7 +75,7 @@ class SecurityConfig {
}
@Bean
@Order(3)
@Order(6)
fun httpSecurityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
authorizeHttpRequests {