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 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(
|
||||
RemoteUserCreateDto(
|
||||
name = person.preferredUsername
|
||||
|
|
|
@ -117,9 +117,11 @@ class SecurityConfig {
|
|||
fun getHttpSignatureFilter(
|
||||
authenticationManager: AuthenticationManager,
|
||||
transaction: Transaction,
|
||||
apUserService: APUserService
|
||||
apUserService: APUserService,
|
||||
userQueryService: UserQueryService
|
||||
): HttpSignatureFilter {
|
||||
val httpSignatureFilter = HttpSignatureFilter(DefaultSignatureHeaderParser(), transaction, apUserService)
|
||||
val httpSignatureFilter =
|
||||
HttpSignatureFilter(DefaultSignatureHeaderParser(), transaction, apUserService, userQueryService)
|
||||
httpSignatureFilter.setAuthenticationManager(authenticationManager)
|
||||
httpSignatureFilter.setContinueFilterChainOnUnsuccessfulAuthentication(false)
|
||||
val authenticationEntryPointFailureHandler =
|
||||
|
|
|
@ -17,7 +17,7 @@ class UserRepositoryImpl(
|
|||
UserRepository {
|
||||
|
||||
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) {
|
||||
Users.insert {
|
||||
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.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.HttpMethod
|
||||
import dev.usbharu.httpsignature.common.HttpRequest
|
||||
|
@ -14,7 +16,8 @@ import java.net.URL
|
|||
class HttpSignatureFilter(
|
||||
private val httpSignatureHeaderParser: SignatureHeaderParser,
|
||||
private val transaction: Transaction,
|
||||
private val apUserService: APUserService
|
||||
private val apUserService: APUserService,
|
||||
private val userQueryService: UserQueryService
|
||||
) :
|
||||
AbstractPreAuthenticatedProcessingFilter() {
|
||||
override fun getPreAuthenticatedPrincipal(request: HttpServletRequest?): Any? {
|
||||
|
@ -32,7 +35,11 @@ class HttpSignatureFilter(
|
|||
}
|
||||
runBlocking {
|
||||
transaction.transaction {
|
||||
apUserService.fetchPerson(signature.keyId)
|
||||
try {
|
||||
userQueryService.findByKeyId(signature.keyId)
|
||||
} catch (e: FailedToGetResourcesException) {
|
||||
apUserService.fetchPerson(signature.keyId)
|
||||
}
|
||||
}
|
||||
}
|
||||
return signature.keyId
|
||||
|
|
Loading…
Reference in New Issue