mirror of https://github.com/usbharu/Hideout.git
feat: 投稿できるように
This commit is contained in:
parent
e0c0c8b22a
commit
91867d6b83
|
@ -16,7 +16,14 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.config
|
package dev.usbharu.hideout.core.config
|
||||||
|
|
||||||
|
import com.nimbusds.jose.jwk.JWKSet
|
||||||
|
import com.nimbusds.jose.jwk.RSAKey
|
||||||
|
import com.nimbusds.jose.jwk.source.ImmutableJWKSet
|
||||||
|
import com.nimbusds.jose.jwk.source.JWKSource
|
||||||
|
import com.nimbusds.jose.proc.SecurityContext
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.HideoutUserDetails
|
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.HideoutUserDetails
|
||||||
|
import dev.usbharu.hideout.util.RsaUtil
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.core.annotation.Order
|
import org.springframework.core.annotation.Order
|
||||||
|
@ -118,6 +125,19 @@ class SecurityConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun loadJwkSource(jwkConfig: JwkConfig): JWKSource<SecurityContext> {
|
||||||
|
val rsaKey = RSAKey.Builder(RsaUtil.decodeRsaPublicKey(jwkConfig.publicKey))
|
||||||
|
.privateKey(RsaUtil.decodeRsaPrivateKey(jwkConfig.privateKey)).keyID(jwkConfig.keyId).build()
|
||||||
|
return ImmutableJWKSet(JWKSet(rsaKey))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigurationProperties("hideout.security.jwt")
|
||||||
|
data class JwkConfig(
|
||||||
|
val keyId: String,
|
||||||
|
val publicKey: String,
|
||||||
|
val privateKey: String,
|
||||||
|
)
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun roleHierarchy(): RoleHierarchy {
|
fun roleHierarchy(): RoleHierarchy {
|
||||||
|
|
|
@ -199,6 +199,7 @@ object Posts : Table("posts") {
|
||||||
val deleted = bool("deleted")
|
val deleted = bool("deleted")
|
||||||
val hide = bool("hide")
|
val hide = bool("hide")
|
||||||
val moveTo = long("move_to").references(id).nullable()
|
val moveTo = long("move_to").references(id).nullable()
|
||||||
|
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
object PostsMedia : Table("posts_media") {
|
object PostsMedia : Table("posts_media") {
|
||||||
|
|
|
@ -47,7 +47,7 @@ class PostFactoryImpl(
|
||||||
mediaIds: List<MediaId>,
|
mediaIds: List<MediaId>,
|
||||||
): Post {
|
): Post {
|
||||||
val id = idGenerateService.generateId()
|
val id = idGenerateService.generateId()
|
||||||
val url = URI.create(applicationConfig.url.toString() + "/users/" + actorName + "/posts/" + id)
|
val url = URI.create(applicationConfig.url.toString() + "/users/" + actorName.name + "/posts/" + id)
|
||||||
return Post.create(
|
return Post.create(
|
||||||
PostId(id),
|
PostId(id),
|
||||||
actorId,
|
actorId,
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
package dev.usbharu.hideout.util
|
package dev.usbharu.hideout.util
|
||||||
|
|
||||||
import java.security.KeyFactory
|
import java.security.KeyFactory
|
||||||
|
import java.security.interfaces.RSAPrivateKey
|
||||||
import java.security.interfaces.RSAPublicKey
|
import java.security.interfaces.RSAPublicKey
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec
|
||||||
import java.security.spec.X509EncodedKeySpec
|
import java.security.spec.X509EncodedKeySpec
|
||||||
|
|
||||||
object RsaUtil {
|
object RsaUtil {
|
||||||
|
@ -36,4 +38,11 @@ object RsaUtil {
|
||||||
return decodeRsaPublicKey(replace)
|
return decodeRsaPublicKey(replace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun decodeRsaPrivateKey(byteArray: ByteArray): RSAPrivateKey {
|
||||||
|
val pkcS8EncodedKeySpec = PKCS8EncodedKeySpec(byteArray)
|
||||||
|
return KeyFactory.getInstance("RSA").generatePrivate(pkcS8EncodedKeySpec) as RSAPrivateKey
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decodeRsaPrivateKey(encoded: String): RSAPrivateKey = decodeRsaPrivateKey(Base64Util.decode(encoded))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
</Root>
|
</Root>
|
||||||
<Logger name="dev.usbharu.owl.broker.service.QueuedTaskAssignerImpl" level="TRACE"/>
|
<Logger name="dev.usbharu.owl.broker.service.QueuedTaskAssignerImpl" level="TRACE"/>
|
||||||
<Logger name="org.mongodb.driver.cluster" level="WARN"/>
|
<Logger name="org.mongodb.driver.cluster" level="WARN"/>
|
||||||
|
<Logger name="org.apache.tomcat.util.net.NioEndpoint" level="INFO"/>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
</Configuration>
|
</Configuration>
|
Loading…
Reference in New Issue