mirror of https://github.com/usbharu/Hideout.git
fix: userの一意性を保証できるように
This commit is contained in:
parent
4655156e35
commit
3ac0782246
|
@ -111,6 +111,36 @@ class APUserServiceImpl(
|
||||||
val person = apResourceResolveService.resolve<Person>(url, null as Long?)
|
val person = apResourceResolveService.resolve<Person>(url, null as Long?)
|
||||||
|
|
||||||
val id = person.id ?: throw IllegalActivityPubObjectException("id is null")
|
val id = person.id ?: throw IllegalActivityPubObjectException("id is null")
|
||||||
|
try {
|
||||||
|
val userEntity = userQueryService.findByUrl(id)
|
||||||
|
return Person(
|
||||||
|
type = emptyList(),
|
||||||
|
name = userEntity.name,
|
||||||
|
id = id,
|
||||||
|
preferredUsername = userEntity.name,
|
||||||
|
summary = userEntity.description,
|
||||||
|
inbox = "$id/inbox",
|
||||||
|
outbox = "$id/outbox",
|
||||||
|
url = id,
|
||||||
|
icon = Image(
|
||||||
|
type = emptyList(),
|
||||||
|
name = "$id/icon.png",
|
||||||
|
mediaType = "image/png",
|
||||||
|
url = "$id/icon.png"
|
||||||
|
),
|
||||||
|
publicKey = Key(
|
||||||
|
type = emptyList(),
|
||||||
|
name = "Public Key",
|
||||||
|
id = userEntity.keyId,
|
||||||
|
owner = id,
|
||||||
|
publicKeyPem = userEntity.publicKey
|
||||||
|
),
|
||||||
|
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
|
||||||
|
followers = userEntity.followers,
|
||||||
|
following = userEntity.following
|
||||||
|
) to userEntity
|
||||||
|
} catch (_: FailedToGetResourcesException) {
|
||||||
|
}
|
||||||
person to userService.createRemoteUser(
|
person to userService.createRemoteUser(
|
||||||
RemoteUserCreateDto(
|
RemoteUserCreateDto(
|
||||||
name = person.preferredUsername
|
name = person.preferredUsername
|
||||||
|
|
|
@ -117,9 +117,11 @@ class SecurityConfig {
|
||||||
fun getHttpSignatureFilter(
|
fun getHttpSignatureFilter(
|
||||||
authenticationManager: AuthenticationManager,
|
authenticationManager: AuthenticationManager,
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
apUserService: APUserService
|
apUserService: APUserService,
|
||||||
|
userQueryService: UserQueryService
|
||||||
): HttpSignatureFilter {
|
): HttpSignatureFilter {
|
||||||
val httpSignatureFilter = HttpSignatureFilter(DefaultSignatureHeaderParser(), transaction, apUserService)
|
val httpSignatureFilter =
|
||||||
|
HttpSignatureFilter(DefaultSignatureHeaderParser(), transaction, apUserService, userQueryService)
|
||||||
httpSignatureFilter.setAuthenticationManager(authenticationManager)
|
httpSignatureFilter.setAuthenticationManager(authenticationManager)
|
||||||
httpSignatureFilter.setContinueFilterChainOnUnsuccessfulAuthentication(false)
|
httpSignatureFilter.setContinueFilterChainOnUnsuccessfulAuthentication(false)
|
||||||
val authenticationEntryPointFailureHandler =
|
val authenticationEntryPointFailureHandler =
|
||||||
|
|
|
@ -17,7 +17,7 @@ class UserRepositoryImpl(
|
||||||
UserRepository {
|
UserRepository {
|
||||||
|
|
||||||
override suspend fun save(user: User): User {
|
override suspend fun save(user: User): User {
|
||||||
val singleOrNull = Users.select { Users.id eq user.id or (Users.url eq user.url) }.empty()
|
val singleOrNull = Users.select { Users.id eq user.id }.empty()
|
||||||
if (singleOrNull) {
|
if (singleOrNull) {
|
||||||
Users.insert {
|
Users.insert {
|
||||||
it[id] = user.id
|
it[id] = user.id
|
||||||
|
|
|
@ -2,6 +2,8 @@ package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
|
import dev.usbharu.hideout.core.query.UserQueryService
|
||||||
import dev.usbharu.httpsignature.common.HttpHeaders
|
import dev.usbharu.httpsignature.common.HttpHeaders
|
||||||
import dev.usbharu.httpsignature.common.HttpMethod
|
import dev.usbharu.httpsignature.common.HttpMethod
|
||||||
import dev.usbharu.httpsignature.common.HttpRequest
|
import dev.usbharu.httpsignature.common.HttpRequest
|
||||||
|
@ -14,7 +16,8 @@ import java.net.URL
|
||||||
class HttpSignatureFilter(
|
class HttpSignatureFilter(
|
||||||
private val httpSignatureHeaderParser: SignatureHeaderParser,
|
private val httpSignatureHeaderParser: SignatureHeaderParser,
|
||||||
private val transaction: Transaction,
|
private val transaction: Transaction,
|
||||||
private val apUserService: APUserService
|
private val apUserService: APUserService,
|
||||||
|
private val userQueryService: UserQueryService
|
||||||
) :
|
) :
|
||||||
AbstractPreAuthenticatedProcessingFilter() {
|
AbstractPreAuthenticatedProcessingFilter() {
|
||||||
override fun getPreAuthenticatedPrincipal(request: HttpServletRequest?): Any? {
|
override fun getPreAuthenticatedPrincipal(request: HttpServletRequest?): Any? {
|
||||||
|
@ -32,7 +35,11 @@ class HttpSignatureFilter(
|
||||||
}
|
}
|
||||||
runBlocking {
|
runBlocking {
|
||||||
transaction.transaction {
|
transaction.transaction {
|
||||||
apUserService.fetchPerson(signature.keyId)
|
try {
|
||||||
|
userQueryService.findByKeyId(signature.keyId)
|
||||||
|
} catch (e: FailedToGetResourcesException) {
|
||||||
|
apUserService.fetchPerson(signature.keyId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return signature.keyId
|
return signature.keyId
|
||||||
|
|
Loading…
Reference in New Issue