mirror of https://github.com/usbharu/Hideout.git
style: スタイルを調整
This commit is contained in:
parent
3c310952b5
commit
09442d2bdf
|
@ -2,6 +2,7 @@ build:
|
|||
maxIssues: 20
|
||||
weights:
|
||||
Indentation: 0
|
||||
MagicNumber: 0
|
||||
|
||||
style:
|
||||
ClassOrdering:
|
||||
|
|
|
@ -30,17 +30,19 @@ class JobQueueWorkerRunner(
|
|||
) : ApplicationRunner {
|
||||
override fun run(args: ApplicationArguments?) {
|
||||
LOGGER.info("Init job queue worker.")
|
||||
jobQueueWorkerService.init(jobs.map {
|
||||
it to {
|
||||
execute {
|
||||
LOGGER.debug("excute job ${it.name}")
|
||||
apService.processActivity(
|
||||
job = this,
|
||||
hideoutJob = it
|
||||
)
|
||||
jobQueueWorkerService.init(
|
||||
jobs.map {
|
||||
it to {
|
||||
execute {
|
||||
LOGGER.debug("excute job ${it.name}")
|
||||
apService.processActivity(
|
||||
job = this,
|
||||
hideoutJob = it
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.boot.runApplication
|
|||
@ConfigurationPropertiesScan
|
||||
class SpringApplication
|
||||
|
||||
@Suppress("SpreadOperator")
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<SpringApplication>(*args)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@ class HttpClientConfig {
|
|||
applicationConfig: ApplicationConfig
|
||||
): KtorKeyMap {
|
||||
return KtorKeyMap(
|
||||
userQueryService, transaction, applicationConfig
|
||||
userQueryService,
|
||||
transaction,
|
||||
applicationConfig
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ class SecurityConfig {
|
|||
return http.build()
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@Order(2)
|
||||
fun defaultSecurityFilterChain(http: HttpSecurity, introspector: HandlerMappingIntrospector): SecurityFilterChain {
|
||||
|
@ -99,9 +98,7 @@ class SecurityConfig {
|
|||
}
|
||||
|
||||
@Bean
|
||||
fun passwordEncoder(): PasswordEncoder {
|
||||
return BCryptPasswordEncoder()
|
||||
}
|
||||
fun passwordEncoder(): PasswordEncoder = BCryptPasswordEncoder()
|
||||
|
||||
@Bean
|
||||
fun genJwkSource(): JWKSource<SecurityContext> {
|
||||
|
@ -131,9 +128,8 @@ class SecurityConfig {
|
|||
}
|
||||
|
||||
@Bean
|
||||
fun jwtDecoder(jwkSource: JWKSource<SecurityContext>): JwtDecoder {
|
||||
return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource)
|
||||
}
|
||||
fun jwtDecoder(jwkSource: JWKSource<SecurityContext>): JwtDecoder =
|
||||
OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource)
|
||||
|
||||
@Bean
|
||||
fun authorizationServerSettings(): AuthorizationServerSettings {
|
||||
|
|
|
@ -12,7 +12,6 @@ import javax.sql.DataSource
|
|||
@EnableTransactionManagement
|
||||
class SpringTransactionConfig(val datasource: DataSource) : TransactionManagementConfigurer {
|
||||
@Bean
|
||||
override fun annotationDrivenTransactionManager(): PlatformTransactionManager {
|
||||
return SpringTransactionManager(datasource)
|
||||
}
|
||||
override fun annotationDrivenTransactionManager(): PlatformTransactionManager =
|
||||
SpringTransactionManager(datasource)
|
||||
}
|
||||
|
|
|
@ -12,10 +12,11 @@ interface InboxController {
|
|||
@RequestMapping(
|
||||
"/inbox",
|
||||
"/users/{username}/inbox",
|
||||
produces = ["application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""],
|
||||
produces = [
|
||||
"application/activity+json",
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
],
|
||||
method = [RequestMethod.GET, RequestMethod.POST]
|
||||
)
|
||||
fun inbox(@RequestBody string: String): ResponseEntity<Unit> {
|
||||
return ResponseEntity(HttpStatus.ACCEPTED)
|
||||
}
|
||||
fun inbox(@RequestBody string: String): ResponseEntity<Unit> = ResponseEntity(HttpStatus.ACCEPTED)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,5 @@ import org.springframework.web.bind.annotation.RestController
|
|||
@RestController
|
||||
interface OutboxController {
|
||||
@RequestMapping("/outbox", "/users/{username}/outbox", method = [RequestMethod.POST, RequestMethod.GET])
|
||||
fun outbox(@RequestBody string: String): ResponseEntity<Unit> {
|
||||
return ResponseEntity(HttpStatus.ACCEPTED)
|
||||
}
|
||||
fun outbox(@RequestBody string: String): ResponseEntity<Unit> = ResponseEntity(HttpStatus.ACCEPTED)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,5 @@ import org.springframework.web.bind.annotation.RestController
|
|||
|
||||
@RestController
|
||||
class OutboxControllerImpl : OutboxController {
|
||||
override fun outbox(@RequestBody string: String): ResponseEntity<Unit> {
|
||||
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
|
||||
}
|
||||
override fun outbox(@RequestBody string: String): ResponseEntity<Unit> = ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
|
||||
}
|
||||
|
|
|
@ -29,14 +29,8 @@ class HostMetaController(private val applicationConfig: ApplicationConfig) {
|
|||
}"""
|
||||
|
||||
@GetMapping("/.well-known/host-meta", produces = ["application/xml"])
|
||||
fun hostmeta(): ResponseEntity<String> {
|
||||
return ResponseEntity(xml, HttpStatus.OK)
|
||||
}
|
||||
fun hostmeta(): ResponseEntity<String> = ResponseEntity(xml, HttpStatus.OK)
|
||||
|
||||
@GetMapping("/.well-known/host-meta.json", produces = ["application/json"])
|
||||
fun hostmetJson(): ResponseEntity<String> {
|
||||
return ResponseEntity(json, HttpStatus.OK)
|
||||
}
|
||||
|
||||
|
||||
fun hostmetJson(): ResponseEntity<String> = ResponseEntity(json, HttpStatus.OK)
|
||||
}
|
||||
|
|
|
@ -20,11 +20,13 @@ class NodeinfoController(private val applicationConfig: ApplicationConfig) {
|
|||
"${applicationConfig.url}/nodeinfo/2.0"
|
||||
)
|
||||
)
|
||||
), HttpStatus.OK
|
||||
),
|
||||
HttpStatus.OK
|
||||
)
|
||||
}
|
||||
|
||||
@GetMapping("/nodeinfo/2.0")
|
||||
@Suppress("FunctionNaming")
|
||||
fun nodeinfo2_0(): ResponseEntity<Nodeinfo2_0> {
|
||||
return ResponseEntity(
|
||||
Nodeinfo2_0(
|
||||
|
|
|
@ -42,10 +42,12 @@ class UserDetailsImpl(
|
|||
)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonSubTypes
|
||||
@Suppress("UnnecessaryAbstractClass")
|
||||
abstract class UserDetailsMixin
|
||||
|
||||
class UserDetailsDeserializer : JsonDeserializer<UserDetailsImpl>() {
|
||||
val SIMPLE_GRANTED_AUTHORITY_SET = object : TypeReference<Set<SimpleGrantedAuthority>>() {}
|
||||
|
||||
private val SIMPLE_GRANTED_AUTHORITY_SET = object : TypeReference<Set<SimpleGrantedAuthority>>() {}
|
||||
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): UserDetailsImpl {
|
||||
val mapper = p.codec as ObjectMapper
|
||||
val jsonNode: JsonNode = mapper.readTree(p)
|
||||
|
@ -57,14 +59,14 @@ class UserDetailsDeserializer : JsonDeserializer<UserDetailsImpl>() {
|
|||
|
||||
val password = jsonNode.readText("password")
|
||||
return UserDetailsImpl(
|
||||
jsonNode["id"].longValue(),
|
||||
jsonNode.readText("username"),
|
||||
password,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
authorities.toMutableList(),
|
||||
id = jsonNode["id"].longValue(),
|
||||
username = jsonNode.readText("username"),
|
||||
password = password,
|
||||
enabled = true,
|
||||
accountNonExpired = true,
|
||||
credentialsNonExpired = true,
|
||||
accountNonLocked = true,
|
||||
authorities = authorities.toMutableList(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package dev.usbharu.hideout.domain.model.wellknown
|
||||
|
||||
|
||||
data class Nodeinfo(
|
||||
val links: List<Links>
|
||||
) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.usbharu.hideout.domain.model.wellknown
|
||||
|
||||
@Suppress("ClassNaming")
|
||||
data class Nodeinfo2_0(
|
||||
val version: String,
|
||||
val software: Software,
|
||||
|
|
|
@ -48,9 +48,9 @@ class RegisteredClientRepositoryImpl(private val database: Database) : Registere
|
|||
it[clientSecretExpiresAt] = registeredClient.clientSecretExpiresAt
|
||||
it[clientName] = registeredClient.clientName
|
||||
it[clientAuthenticationMethods] =
|
||||
registeredClient.clientAuthenticationMethods.map { it.value }.joinToString(",")
|
||||
registeredClient.clientAuthenticationMethods.map { method -> method.value }.joinToString(",")
|
||||
it[authorizationGrantTypes] =
|
||||
registeredClient.authorizationGrantTypes.map { it.value }.joinToString(",")
|
||||
registeredClient.authorizationGrantTypes.map { type -> type.value }.joinToString(",")
|
||||
it[redirectUris] = registeredClient.redirectUris.joinToString(",")
|
||||
it[postLogoutRedirectUris] = registeredClient.postLogoutRedirectUris.joinToString(",")
|
||||
it[scopes] = registeredClient.scopes.joinToString(",")
|
||||
|
@ -100,20 +100,7 @@ class RegisteredClientRepositoryImpl(private val database: Database) : Registere
|
|||
|
||||
private fun <T, U> jsonToMap(json: String): Map<T, U> = objectMapper.readValue(json)
|
||||
|
||||
companion object {
|
||||
val objectMapper: ObjectMapper = ObjectMapper()
|
||||
val LOGGER = LoggerFactory.getLogger(RegisteredClientRepositoryImpl::class.java)
|
||||
|
||||
init {
|
||||
|
||||
val classLoader = ExposedOAuth2AuthorizationService::class.java.classLoader
|
||||
val modules = SecurityJackson2Modules.getModules(classLoader)
|
||||
this.objectMapper.registerModules(JavaTimeModule())
|
||||
this.objectMapper.registerModules(modules)
|
||||
this.objectMapper.registerModules(OAuth2AuthorizationServerJackson2Module())
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
fun ResultRow.toRegisteredClient(): SpringRegisteredClient {
|
||||
fun resolveClientAuthenticationMethods(string: String): ClientAuthenticationMethod {
|
||||
return when (string) {
|
||||
|
@ -175,6 +162,20 @@ class RegisteredClientRepositoryImpl(private val database: Database) : Registere
|
|||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val objectMapper: ObjectMapper = ObjectMapper()
|
||||
val LOGGER = LoggerFactory.getLogger(RegisteredClientRepositoryImpl::class.java)
|
||||
|
||||
init {
|
||||
|
||||
val classLoader = ExposedOAuth2AuthorizationService::class.java.classLoader
|
||||
val modules = SecurityJackson2Modules.getModules(classLoader)
|
||||
this.objectMapper.registerModules(JavaTimeModule())
|
||||
this.objectMapper.registerModules(modules)
|
||||
this.objectMapper.registerModules(OAuth2AuthorizationServerJackson2Module())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// org/springframework/security/oauth2/server/authorization/client/oauth2-registered-client-schema.sql
|
||||
|
|
|
@ -83,7 +83,8 @@ class APReactionServiceImpl(
|
|||
`object` = postUrl,
|
||||
id = "${Config.configData.url}/like/note/$id",
|
||||
content = content
|
||||
), objectMapper
|
||||
),
|
||||
objectMapper
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -100,7 +101,8 @@ class APReactionServiceImpl(
|
|||
`object` = like,
|
||||
id = "${Config.configData.url}/undo/note/${like.id}",
|
||||
published = Instant.now()
|
||||
), objectMapper
|
||||
),
|
||||
objectMapper
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import kjob.core.job.JobProps
|
|||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
|
||||
interface APReceiveFollowService {
|
||||
suspend fun receiveFollow(follow: Follow): ActivityPubResponse
|
||||
suspend fun receiveFollowJob(props: JobProps<ReceiveFollowJob>)
|
||||
|
@ -58,7 +57,8 @@ class APReceiveFollowServiceImpl(
|
|||
name = "Follow",
|
||||
`object` = follow,
|
||||
actor = targetActor
|
||||
), objectMapper
|
||||
),
|
||||
objectMapper
|
||||
)
|
||||
|
||||
val targetEntity = userQueryService.findByUrl(targetActor)
|
||||
|
|
|
@ -18,10 +18,10 @@ class AccountApiServiceImpl(private val accountService: AccountService, private
|
|||
AccountApiService {
|
||||
override suspend fun verifyCredentials(userid: Long): CredentialAccount = transaction.transaction {
|
||||
val account = accountService.findById(userid)
|
||||
of(account)
|
||||
from(account)
|
||||
}
|
||||
|
||||
private fun of(account: Account): CredentialAccount {
|
||||
private fun from(account: Account): CredentialAccount {
|
||||
return CredentialAccount(
|
||||
id = account.id,
|
||||
username = account.username,
|
||||
|
|
|
@ -55,7 +55,5 @@ class AppApiServiceImpl(
|
|||
}
|
||||
}
|
||||
|
||||
private fun parseScope(string: String): Set<String> {
|
||||
return string.split(" ").toSet()
|
||||
}
|
||||
private fun parseScope(string: String): Set<String> = string.split(" ").toSet()
|
||||
}
|
||||
|
|
|
@ -11,13 +11,15 @@ interface InstanceApiService {
|
|||
|
||||
@Service
|
||||
class InstanceApiServiceImpl(private val applicationConfig: ApplicationConfig) : InstanceApiService {
|
||||
@Suppress("LongMethod")
|
||||
override suspend fun v1Instance(): V1Instance {
|
||||
val url = applicationConfig.url
|
||||
return V1Instance(
|
||||
uri = url.host,
|
||||
title = "Hideout Server",
|
||||
shortDescription = "Hideout test server",
|
||||
description = "This server is operated for testing of Hideout. We are not responsible for any events that occur when associating with this server",
|
||||
description = "This server is operated for testing of Hideout." +
|
||||
" We are not responsible for any events that occur when associating with this server",
|
||||
email = "i@usbharu.dev",
|
||||
version = "0.0.1",
|
||||
urls = V1InstanceUrls("wss://${url.host}"),
|
||||
|
@ -35,7 +37,7 @@ class InstanceApiServiceImpl(private val applicationConfig: ApplicationConfig) :
|
|||
23
|
||||
),
|
||||
mediaAttachments = V1InstanceConfigurationMediaAttachments(
|
||||
listOf(),
|
||||
emptyList(),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
|
|
@ -26,6 +26,7 @@ class StatsesApiServiceImpl(
|
|||
private val userQueryService: UserQueryService
|
||||
) :
|
||||
StatusesApiService {
|
||||
@Suppress("LongMethod")
|
||||
override suspend fun postStatus(statusesRequest: StatusesRequest, user: UserDetailsImpl): Status {
|
||||
val visibility = when (statusesRequest.visibility) {
|
||||
StatusesRequest.Visibility.public -> Visibility.PUBLIC
|
||||
|
@ -37,12 +38,12 @@ class StatsesApiServiceImpl(
|
|||
|
||||
val post = postService.createLocal(
|
||||
PostCreateDto(
|
||||
statusesRequest.status.orEmpty(),
|
||||
statusesRequest.spoilerText,
|
||||
visibility,
|
||||
null,
|
||||
statusesRequest.inReplyToId?.toLongOrNull(),
|
||||
user.id
|
||||
text = statusesRequest.status.orEmpty(),
|
||||
overview = statusesRequest.spoilerText,
|
||||
visibility = visibility,
|
||||
repostId = null,
|
||||
repolyId = statusesRequest.inReplyToId?.toLongOrNull(),
|
||||
userId = user.id
|
||||
)
|
||||
)
|
||||
val account = accountService.findById(user.id)
|
||||
|
@ -58,7 +59,7 @@ class StatsesApiServiceImpl(
|
|||
val replyUser = if (post.replyId != null) {
|
||||
try {
|
||||
userQueryService.findById(postQueryService.findById(post.replyId).userId).id
|
||||
} catch (e: FailedToGetResourcesException) {
|
||||
} catch (ignore: FailedToGetResourcesException) {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
|
@ -82,7 +83,7 @@ class StatsesApiServiceImpl(
|
|||
favouritesCount = 0,
|
||||
repliesCount = 0,
|
||||
url = post.url,
|
||||
post.replyId?.toString(),
|
||||
inReplyToId = post.replyId?.toString(),
|
||||
inReplyToAccountId = replyUser?.toString(),
|
||||
reblog = null,
|
||||
language = null,
|
||||
|
|
|
@ -40,6 +40,7 @@ class ExposedOAuth2AuthorizationService(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||
override fun save(authorization: OAuth2Authorization?): Unit = runBlocking {
|
||||
requireNotNull(authorization)
|
||||
transaction.transaction {
|
||||
|
@ -56,7 +57,8 @@ class ExposedOAuth2AuthorizationService(
|
|||
it[registeredClientId] = authorization.registeredClientId
|
||||
it[principalName] = authorization.principalName
|
||||
it[authorizationGrantType] = authorization.authorizationGrantType.value
|
||||
it[authorizedScopes] = authorization.authorizedScopes.joinToString(",").takeIf { it.isNotEmpty() }
|
||||
it[authorizedScopes] =
|
||||
authorization.authorizedScopes.joinToString(",").takeIf { s -> s.isNotEmpty() }
|
||||
it[attributes] = mapToJson(authorization.attributes)
|
||||
it[state] = authorization.getAttribute(OAuth2ParameterNames.STATE)
|
||||
it[authorizationCodeValue] = authorizationCodeToken?.token?.tokenValue
|
||||
|
@ -99,7 +101,8 @@ class ExposedOAuth2AuthorizationService(
|
|||
it[registeredClientId] = authorization.registeredClientId
|
||||
it[principalName] = authorization.principalName
|
||||
it[authorizationGrantType] = authorization.authorizationGrantType.value
|
||||
it[authorizedScopes] = authorization.authorizedScopes.joinToString(",").takeIf { it.isNotEmpty() }
|
||||
it[authorizedScopes] =
|
||||
authorization.authorizedScopes.joinToString(",").takeIf { s -> s.isNotEmpty() }
|
||||
it[attributes] = mapToJson(authorization.attributes)
|
||||
it[state] = authorization.getAttribute(OAuth2ParameterNames.STATE)
|
||||
it[authorizationCodeValue] = authorizationCodeToken?.token?.tokenValue
|
||||
|
@ -111,8 +114,9 @@ class ExposedOAuth2AuthorizationService(
|
|||
it[accessTokenIssuedAt] = accessToken?.token?.issuedAt
|
||||
it[accessTokenExpiresAt] = accessToken?.token?.expiresAt
|
||||
it[accessTokenMetadata] = accessToken?.metadata?.let { it1 -> mapToJson(it1) }
|
||||
it[accessTokenType] = accessToken?.token?.tokenType?.value
|
||||
it[accessTokenScopes] = accessToken?.token?.scopes?.joinToString(",")?.takeIf { it.isNotEmpty() }
|
||||
it[accessTokenType] = accessToken?.run { token.tokenType.value }
|
||||
it[accessTokenScopes] =
|
||||
accessToken?.run { token.scopes.joinToString(",").takeIf { s -> s.isNotEmpty() } }
|
||||
it[refreshTokenValue] = refreshToken?.token?.tokenValue
|
||||
it[refreshTokenIssuedAt] = refreshToken?.token?.issuedAt
|
||||
it[refreshTokenExpiresAt] = refreshToken?.token?.expiresAt
|
||||
|
@ -203,6 +207,7 @@ class ExposedOAuth2AuthorizationService(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||
fun ResultRow.toAuthorization(): OAuth2Authorization {
|
||||
val registeredClientId = this[Authorization.registeredClientId]
|
||||
|
||||
|
|
|
@ -24,14 +24,14 @@ class UserDetailsServiceImpl(
|
|||
transaction.transaction {
|
||||
val findById = userQueryService.findByNameAndDomain(username, applicationConfig.url.host)
|
||||
UserDetailsImpl(
|
||||
findById.id,
|
||||
findById.name,
|
||||
findById.password,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
mutableListOf()
|
||||
id = findById.id,
|
||||
username = findById.name,
|
||||
password = findById.password,
|
||||
enabled = true,
|
||||
accountNonExpired = true,
|
||||
credentialsNonExpired = true,
|
||||
accountNonLocked = true,
|
||||
authorities = mutableListOf()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package dev.usbharu.hideout.service.job
|
||||
|
||||
import dev.usbharu.hideout.domain.model.job.HideoutJob
|
||||
import kjob.core.dsl.KJobFunctions
|
||||
import org.springframework.stereotype.Service
|
||||
import dev.usbharu.hideout.domain.model.job.HideoutJob as HJ
|
||||
import kjob.core.dsl.JobContextWithProps as JCWP
|
||||
import kjob.core.dsl.JobRegisterContext as JRC
|
||||
|
||||
@Service
|
||||
interface JobQueueWorkerService {
|
||||
fun init(defines: List<Pair<HideoutJob, JRC<HideoutJob, JCWP<HideoutJob>>.(HideoutJob) -> KJobFunctions<HideoutJob, JCWP<HideoutJob>>>>)
|
||||
fun init(
|
||||
defines: List<Pair<HJ, JRC<HJ, JCWP<HJ>>.(HJ) -> KJobFunctions<HJ, JCWP<HJ>>>>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package dev.usbharu.hideout.service.job
|
||||
|
||||
import dev.usbharu.hideout.domain.model.job.HideoutJob
|
||||
import dev.usbharu.kjob.exposed.ExposedKJob
|
||||
import kjob.core.dsl.JobContextWithProps
|
||||
import kjob.core.dsl.JobRegisterContext
|
||||
import kjob.core.dsl.KJobFunctions
|
||||
import kjob.core.kjob
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.springframework.stereotype.Service
|
||||
import dev.usbharu.hideout.domain.model.job.HideoutJob as HJ
|
||||
import kjob.core.dsl.JobContextWithProps as JCWP
|
||||
|
||||
@Service
|
||||
class KJobJobQueueWorkerService(private val database: Database) : JobQueueWorkerService {
|
||||
|
@ -21,7 +21,9 @@ class KJobJobQueueWorkerService(private val database: Database) : JobQueueWorker
|
|||
}.start()
|
||||
}
|
||||
|
||||
override fun init(defines: List<Pair<HideoutJob, JobRegisterContext<HideoutJob, JobContextWithProps<HideoutJob>>.(HideoutJob) -> KJobFunctions<HideoutJob, JobContextWithProps<HideoutJob>>>>) {
|
||||
override fun init(
|
||||
defines: List<Pair<HJ, JobRegisterContext<HJ, JCWP<HJ>>.(HJ) -> KJobFunctions<HJ, JCWP<HJ>>>>
|
||||
) {
|
||||
defines.forEach { job ->
|
||||
kjob.register(job.first, job.second)
|
||||
}
|
||||
|
|
|
@ -25,15 +25,15 @@ class AccountServiceImpl(private val userQueryService: UserQueryService) : Accou
|
|||
header = findById.url + "/header.jpg",
|
||||
headerStatic = findById.url + "/header.jpg",
|
||||
locked = false,
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
findById.createdAt.toString(),
|
||||
findById.createdAt.toString(),
|
||||
0,
|
||||
0,
|
||||
fields = emptyList(),
|
||||
emojis = emptyList(),
|
||||
bot = false,
|
||||
group = false,
|
||||
discoverable = false,
|
||||
createdAt = findById.createdAt.toString(),
|
||||
lastStatusAt = findById.createdAt.toString(),
|
||||
statusesCount = 0,
|
||||
followersCount = 0,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,7 @@ class UserAuthServiceImpl(
|
|||
val userQueryService: UserQueryService
|
||||
) : UserAuthService {
|
||||
|
||||
override fun hash(password: String): String {
|
||||
return BCryptPasswordEncoder().encode(password)
|
||||
}
|
||||
override fun hash(password: String): String = BCryptPasswordEncoder().encode(password)
|
||||
|
||||
override suspend fun usernameAlreadyUse(username: String): Boolean {
|
||||
userQueryService.findByName(username)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package dev.usbharu.hideout.util
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
|
||||
object JsonUtil {
|
||||
val objectMapper = jacksonObjectMapper().registerModule(JavaTimeModule())
|
||||
|
||||
fun mapToJson(map: Map<*, *>, objectMapper: ObjectMapper = this.objectMapper): String =
|
||||
objectMapper.writeValueAsString(map)
|
||||
|
||||
fun <K, V> jsonToMap(json: String, objectMapper: ObjectMapper = this.objectMapper): Map<K, V> =
|
||||
objectMapper.readValue(json)
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package dev.usbharu.hideout.util
|
||||
|
||||
import java.math.BigInteger
|
||||
import java.security.KeyFactory
|
||||
import java.security.interfaces.RSAPublicKey
|
||||
import java.security.spec.X509EncodedKeySpec
|
||||
import java.util.*
|
||||
|
||||
object JsonWebKeyUtil {
|
||||
|
||||
fun publicKeyToJwk(publicKey: String, kid: String): String {
|
||||
val x509EncodedKeySpec = X509EncodedKeySpec(Base64.getDecoder().decode(publicKey))
|
||||
val generatePublic = KeyFactory.getInstance("RSA").generatePublic(x509EncodedKeySpec)
|
||||
return publicKeyToJwk(generatePublic as RSAPublicKey, kid)
|
||||
}
|
||||
|
||||
fun publicKeyToJwk(publicKey: RSAPublicKey, kid: String): String {
|
||||
val e = encodeBase64UInt(publicKey.publicExponent)
|
||||
val n = encodeBase64UInt(publicKey.modulus)
|
||||
return """{"keys":[{"e":"$e","n":"$n","use":"sig","kid":"$kid","kty":"RSA"}]}"""
|
||||
}
|
||||
|
||||
private fun encodeBase64UInt(bigInteger: BigInteger, minLength: Int = -1): String {
|
||||
require(bigInteger.signum() >= 0) { "Cannot encode negative numbers" }
|
||||
|
||||
var bytes = bigInteger.toByteArray()
|
||||
if (bigInteger.bitLength() % 8 == 0 && (bytes[0] == 0.toByte()) && bytes.size > 1) {
|
||||
bytes = Arrays.copyOfRange(bytes, 1, bytes.size)
|
||||
}
|
||||
if (minLength != -1) {
|
||||
if (bytes.size < minLength) {
|
||||
val array = ByteArray(minLength)
|
||||
System.arraycopy(bytes, 0, array, minLength - bytes.size, bytes.size)
|
||||
bytes = array
|
||||
}
|
||||
}
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue