Skip to content

Commit

Permalink
Merge pull request #443 from espoon-voltti/dependabot/gradle/service/…
Browse files Browse the repository at this point in the history
…plugin.spring-2.1.0

Bump plugin.spring from 2.0.0 to 2.1.0 in /service
  • Loading branch information
juhenius authored Dec 3, 2024
2 parents 7c608d7 + dab0da3 commit 37a0a0b
Show file tree
Hide file tree
Showing 24 changed files with 363 additions and 253 deletions.
16 changes: 9 additions & 7 deletions service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
id("org.springframework.boot") version "3.4.0"
id("io.spring.dependency-management") version "1.1.5"
kotlin("jvm") version "2.0.0"
kotlin("plugin.spring") version "2.0.0"
kotlin("jvm") version "2.1.0"
kotlin("plugin.spring") version "2.1.0"
id("org.flywaydb.flyway") version "11.0.0"
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
id("org.jlleitschuh.gradle.ktlint") version "12.1.2"
id("org.owasp.dependencycheck") version "11.1.0"

idea
Expand Down Expand Up @@ -45,6 +45,10 @@ idea {
}
}

ktlint {
version.set("1.4.1")
}

dependencies {
api(kotlin("stdlib"))
implementation("org.jetbrains.kotlin:kotlin-reflect")
Expand Down Expand Up @@ -116,12 +120,10 @@ tasks.register("resolveDependencies") {
it.isCanBeResolved &&
// ignore configurations that fetch sources (e.g. Java source code)
!it.name.endsWith("dependencySources", ignoreCase = true)
}
.map {
}.map {
val files = it.resolve()
it.name to files.size
}
.groupBy({ (_, count) -> count }) { (name, _) -> name }
}.groupBy({ (_, count) -> count }) { (name, _) -> name }
.forEach { (count, names) ->
println(
"Resolved $count dependency files for configurations: ${names.joinToString(", ")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ abstract class PlaywrightTest {
playwright = Playwright.create()
browser =
playwright.chromium().launch(
BrowserType.LaunchOptions()
BrowserType
.LaunchOptions()
.setHeadless(runningInDocker)
.setTimeout(10_000.0)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat
import fi.espoo.oppivelvollisuus.baseUrl
import fi.espoo.oppivelvollisuus.dataQa

class CreateStudentPage(private val page: Page) {
class CreateStudentPage(
private val page: Page
) {
val saveButton = page.locator(dataQa("save-button"))
val dateOfBirthInput = page.locator(dataQa("date-of-birth-input"))
val lastNameInput = page.locator(dataQa("last-name-input"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat
import fi.espoo.oppivelvollisuus.baseUrl
import fi.espoo.oppivelvollisuus.dataQa

class LoginPage(private val page: Page) {
class LoginPage(
private val page: Page
) {
val startLoginButton = page.locator(dataQa("start-login"))
val loggedInUser = page.locator(dataQa("logged-in-user"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import fi.espoo.oppivelvollisuus.baseUrl
import fi.espoo.oppivelvollisuus.dataQa
import java.util.regex.Pattern

class StudentPage(private val page: Page) {
class StudentPage(
private val page: Page
) {
val studentName = page.locator(dataQa("student-name"))

fun assertUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat
import fi.espoo.oppivelvollisuus.baseUrl
import fi.espoo.oppivelvollisuus.dataQa

class StudentsSearchPage(private val page: Page) {
class StudentsSearchPage(
private val page: Page
) {
val createStudentButton = page.locator(dataQa("create-student-button"))

fun assertUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ class SystemController {
@PostMapping("/user-login")
fun userLogin(
@RequestBody adUser: AdUser
): AppUser {
return jdbi.inTransactionUnchecked { it.upsertAppUserFromAd(adUser) }.also {
): AppUser =
jdbi.inTransactionUnchecked { it.upsertAppUserFromAd(adUser) }.also {
logger.audit(AuthenticatedUser(it.id), "USER_LOGIN")
}
}

@GetMapping("/users/{id}")
fun getUser(
@PathVariable id: UUID
): AppUser? {
return jdbi.inTransactionUnchecked { it.getAppUser(id) }
}
): AppUser? = jdbi.inTransactionUnchecked { it.getAppUser(id) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ VALUES (:externalId, :firstName, :lastName, :email)
ON CONFLICT (external_id) DO UPDATE
SET updated = now(), first_names = :firstName, last_name = :lastName, email = :email
RETURNING id, external_id, first_name, last_name, email
"""
.trimIndent()
)
.bindKotlin(adUser)
""".trimIndent()
).bindKotlin(adUser)
.mapTo<AppUser>()
.one()

Expand All @@ -63,10 +61,8 @@ fun Handle.getAppUser(id: UUID) =
SELECT id, external_id, first_name, last_name, email
FROM users
WHERE id = :id AND NOT system_user
"""
.trimIndent()
)
.bind("id", id)
""".trimIndent()
).bind("id", id)
.mapTo<AppUser>()
.findOne()
.getOrNull()
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class HttpAccessControl : HttpFilter() {
}
}

class JwtTokenDecoder(private val jwtVerifier: JWTVerifier) : HttpFilter() {
class JwtTokenDecoder(
private val jwtVerifier: JWTVerifier
) : HttpFilter() {
private val logger = KotlinLogging.logger {}

override fun doFilter(
Expand All @@ -78,7 +80,8 @@ class JwtTokenDecoder(private val jwtVerifier: JWTVerifier) : HttpFilter() {
chain: FilterChain
) {
try {
request.getBearerToken()
request
.getBearerToken()
?.takeIf { it.isNotEmpty() }
?.let { request.setDecodedJwt(jwtVerifier.verify(it)) }
} catch (e: JWTVerificationException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class ExceptionHandler : ResponseEntityExceptionHandler() {
ex: BadRequest
): ResponseEntity<ErrorResponse> {
logger.warn("Bad request (${ex.message})", ex)
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(ErrorResponse(errorCode = ex.errorCode))
}

Expand All @@ -45,7 +46,8 @@ class ExceptionHandler : ResponseEntityExceptionHandler() {
ex: NotFound
): ResponseEntity<ErrorResponse> {
logger.warn("Not found (${ex.message})", ex)
return ResponseEntity.status(HttpStatus.NOT_FOUND)
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.body(ErrorResponse(errorCode = ex.errorCode))
}

Expand All @@ -55,7 +57,8 @@ class ExceptionHandler : ResponseEntityExceptionHandler() {
ex: Conflict
): ResponseEntity<ErrorResponse> {
logger.warn("fi.espoo.oppivelvollisuus.common.Conflict (${ex.message})", ex)
return ResponseEntity.status(HttpStatus.CONFLICT)
return ResponseEntity
.status(HttpStatus.CONFLICT)
.body(ErrorResponse(errorCode = ex.errorCode))
}

Expand All @@ -65,7 +68,8 @@ class ExceptionHandler : ResponseEntityExceptionHandler() {
ex: Unauthorized
): ResponseEntity<ErrorResponse> {
logger.warn("fi.espoo.oppivelvollisuus.common.Unauthorized (${ex.message})", ex)
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
return ResponseEntity
.status(HttpStatus.UNAUTHORIZED)
.body(ErrorResponse(errorCode = ex.errorCode))
}

Expand All @@ -75,7 +79,8 @@ class ExceptionHandler : ResponseEntityExceptionHandler() {
ex: Forbidden
): ResponseEntity<ErrorResponse> {
logger.warn("fi.espoo.oppivelvollisuus.common.Forbidden (${ex.message})", ex)
return ResponseEntity.status(HttpStatus.FORBIDDEN)
return ResponseEntity
.status(HttpStatus.FORBIDDEN)
.body(ErrorResponse(errorCode = ex.errorCode))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

fun defaultJsonMapperBuilder(): JsonMapper.Builder =
JsonMapper.builder()
JsonMapper
.builder()
.addModules(
KotlinModule.Builder()
KotlinModule
.Builder()
.enable(KotlinFeature.SingletonSupport)
.build(),
JavaTimeModule(),
Jdk8Module(),
ParameterNamesModule()
)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

@Configuration
class JacksonConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ import java.security.spec.RSAPublicKeySpec
class JwtConfig {
@Bean
fun rsaJwtAlgorithm(env: AppEnv): Algorithm {
val publicKeys = env.jwt.publicKeysUrl.toURL().openStream().use { loadPublicKeys(it) }
val publicKeys =
env.jwt.publicKeysUrl
.toURL()
.openStream()
.use { loadPublicKeys(it) }
return Algorithm.RSA256(JwtKeys(publicKeys))
}

@Bean
fun jwtVerifier(algorithm: Algorithm): JWTVerifier = JWT.require(algorithm).acceptLeeway(1).build()
}

class JwtKeys(private val publicKeys: Map<String, RSAPublicKey>) : RSAKeyProvider {
class JwtKeys(
private val publicKeys: Map<String, RSAPublicKey>
) : RSAKeyProvider {
override fun getPrivateKeyId(): String? = null

override fun getPrivateKey(): RSAPrivateKey? = null
Expand All @@ -44,15 +50,23 @@ class JwtKeys(private val publicKeys: Map<String, RSAPublicKey>) : RSAKeyProvide

fun loadPublicKeys(inputStream: InputStream): Map<String, RSAPublicKey> {
@JsonIgnoreProperties(ignoreUnknown = true)
class Jwk(val kid: String, val n: ByteArray, val e: ByteArray)
class Jwk(
val kid: String,
val n: ByteArray,
val e: ByteArray
)

class JwkSet(val keys: List<Jwk>)
class JwkSet(
val keys: List<Jwk>
)

val kf = KeyFactory.getInstance("RSA")
return jacksonMapperBuilder()
.defaultBase64Variant(Base64Variants.MODIFIED_FOR_URL)
.build()
.readValue<JwkSet>(inputStream).keys.associate {
.readValue<JwkSet>(inputStream)
.keys
.associate {
it.kid to
kf.generatePublic(
RSAPublicKeySpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class SpringMvcConfig : WebMvcConfigurer {
}

object AuthenticatedUserResolver : HandlerMethodArgumentResolver {
override fun supportsParameter(parameter: MethodParameter): Boolean {
return AuthenticatedUser::class.java.isAssignableFrom(parameter.parameterType)
}
override fun supportsParameter(parameter: MethodParameter): Boolean =
AuthenticatedUser::class.java.isAssignableFrom(parameter.parameterType)

override fun resolveArgument(
parameter: MethodParameter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class SsnMasker : ValueMasker {
override fun mask(
context: JsonStreamContext?,
value: Any?
): Any {
return if (value is String) {
): Any =
if (value is String) {
value.replace(
Regex(
"(?<!-|[\\dA-z])(\\d{2})(\\d{2})(\\d{2})[-+ABCDEFUVWXY](\\d{3})[\\dA-Z](?!-)",
Expand All @@ -23,5 +23,4 @@ class SsnMasker : ValueMasker {
} else {
value ?: "null"
}
}
}
Loading

0 comments on commit 37a0a0b

Please sign in to comment.