Skip to content

Commit

Permalink
dependency upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-coding committed Dec 15, 2023
1 parent a81c205 commit e6d9d31
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object DefaultSchemaGeneratorHooks : SchemaGeneratorHooks {
}
}

override fun willBuildSchema(builder: GraphQLSchema.Builder): GraphQLSchema.Builder {
override fun didBuildSchema(builder: GraphQLSchema.Builder): GraphQLSchema.Builder {
val oldCodeRegistry = builder.build().codeRegistry
val newCodeRegistry = oldCodeRegistry.transform {
it.dataFetchers(codeRegistry.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.springframework.web.server.ResponseStatusException
import java.net.URI
import java.time.Duration
import java.time.OffsetDateTime
import kotlin.reflect.KClass
import kotlin.reflect.KFunction
import kotlin.reflect.full.createType

Expand Down Expand Up @@ -232,7 +233,7 @@ class GraphQLConfiguration {
@Bean
fun kotlinDataFetcherFactory(applicationContext: ApplicationContext): KotlinDataFetcherFactoryProvider =
object : SimpleKotlinDataFetcherFactoryProvider() {
override fun functionDataFetcherFactory(target: Any?, kFunction: KFunction<*>) = DataFetcherFactory {
override fun functionDataFetcherFactory(target: Any?, kClass: KClass<*>, kFunction: KFunction<*>) = DataFetcherFactory {
GropiusFunctionDataFetcher(target, kFunction, applicationContext)
}
}
Expand All @@ -248,7 +249,7 @@ class GraphQLConfiguration {
@Bean
fun springGraphQLServer(
requestParser: SpringGraphQLRequestParser,
contextFactory: SpringGraphQLContextFactory<*>,
contextFactory: SpringGraphQLContextFactory,
requestHandler: GraphQLRequestHandler
): SpringGraphQLServer = object : SpringGraphQLServer(requestParser, contextFactory, requestHandler) {
override suspend fun execute(request: ServerRequest): GraphQLServerResponse? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gropius.graphql

import com.expediagroup.graphql.server.spring.execution.DefaultSpringGraphQLContextFactory
import graphql.GraphQLContext
import gropius.GropiusInternalApiConfigurationProperties
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
Expand All @@ -17,12 +18,12 @@ class GropiusGraphQLContextFactory(
private val gropiusInternalApiConfigurationProperties: GropiusInternalApiConfigurationProperties
) : DefaultSpringGraphQLContextFactory() {

override suspend fun generateContextMap(request: ServerRequest): Map<*, Any> {
override suspend fun generateContext(request: ServerRequest): GraphQLContext {
val token = request.headers().firstHeader("Authorization")?.replace("Bearer ", "", true) ?: ""
if (gropiusInternalApiConfigurationProperties.apiToken.let { it != null && it != token }) {
throw ResponseStatusException(HttpStatus.FORBIDDEN, "No or invalid authentication token provided")
}
return super.generateContextMap(request)
return super.generateContext(request)
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gropius.graphql

import com.expediagroup.graphql.generator.extensions.plus
import com.expediagroup.graphql.server.spring.execution.DefaultSpringGraphQLContextFactory
import graphql.GraphQLContext
import gropius.GropiusPublicApiConfigurationProperties
import gropius.authorization.GropiusAuthorizationContext
import gropius.model.user.GropiusUser
Expand Down Expand Up @@ -38,11 +40,11 @@ class GropiusGraphQLContextFactory(
/**
* Jwt parser based on the secret defined by [gropiusPublicApiConfigurationProperties]
*/
private val jwtParser = Jwts.parserBuilder()
.setSigningKey(Keys.hmacShaKeyFor(Decoders.BASE64.decode(gropiusPublicApiConfigurationProperties.jwtSecret)))
private val jwtParser = Jwts.parser()
.verifyWith(Keys.hmacShaKeyFor(Decoders.BASE64.decode(gropiusPublicApiConfigurationProperties.jwtSecret)))
.build()

override suspend fun generateContextMap(request: ServerRequest): Map<*, Any> {
override suspend fun generateContext(request: ServerRequest): GraphQLContext {
val token = request.headers().firstHeader("Authorization")
val additionalContextEntries = if (token == null) {
if (gropiusPublicApiConfigurationProperties.debugNoAuthentication) {
Expand All @@ -61,7 +63,7 @@ class GropiusGraphQLContextFactory(
}

}
return super.generateContextMap(request) + additionalContextEntries
return super.generateContext(request) + additionalContextEntries
}

/**
Expand All @@ -74,14 +76,14 @@ class GropiusGraphQLContextFactory(
private suspend fun verifyToken(token: String): GropiusUser {
val tokenWithoutBearer = token.replace("Bearer ", "", true)
val jwt = try {
jwtParser.parseClaimsJws(tokenWithoutBearer)
jwtParser.parseSignedClaims(tokenWithoutBearer)
} catch (e: JwtException) {
throw ResponseStatusException(HttpStatus.FORBIDDEN, "Invalid jwt")
}
if (!jwt.body.audience.contains(JWT_AUDIENCE_BACKEND)) {
if (!jwt.payload.audience.contains(JWT_AUDIENCE_BACKEND)) {
throw ResponseStatusException(HttpStatus.FORBIDDEN, "Not a backend token")
}
val user = jwt.body.subject!!
val user = jwt.payload.subject!!
return gropiusUserRepository.findById(user).awaitSingle()
}

Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ org.gradle.jvmargs=-Xmx2g
javaVersion = 17

# dependencies
springBootVersion = 3.1.3
graphglueVersion = 5.1.2
graphqlJavaVersion = 20.2
springBootVersion = 3.2.0
graphglueVersion = 5.2.0
graphqlJavaVersion = 21.0
apolloVersion = 3.8.2
kosonVersion = 1.2.8
ktorVersion = 2.3.4
jsonSchemaValidatorVersion = 1.0.87
jjwtVersion = 0.11.5
ktorVersion = 2.3.7
jsonSchemaValidatorVersion = 1.0.88
jjwtVersion = 0.12.3
dokkaGraphQLDescriptionPluginVersion = 1.1.0
kotlinxSerializationVersion = 1.6.0
kotlinxSerializationVersion = 1.6.2

# plugins
kotlinVersion = 1.9.10
dokkaVersion = 1.9.0
nodeGradleVersion = 7.0.0
kotlinVersion = 1.9.21
dokkaVersion = 1.9.10
nodeGradleVersion = 7.0.1

0 comments on commit e6d9d31

Please sign in to comment.