Skip to content
Snippets Groups Projects
Verified Commit d4eae06d authored by Jan-Niclas Strüwer's avatar Jan-Niclas Strüwer
Browse files

added minimum length of 30 characters for api key

parent 47b27118
No related branches found
No related tags found
1 merge request!9add deploy stage to gitlab ci/cd pipeline
package de.fraunhofer.iem.dataprovider.configuration.security
import jakarta.annotation.PostConstruct
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
......@@ -7,6 +8,7 @@ import org.springframework.web.server.ServerWebExchange
import org.springframework.web.server.WebFilter
import org.springframework.web.server.WebFilterChain
import reactor.core.publisher.Mono
import java.security.InvalidKeyException
const val API_KEY_HEADER = "Api-Key"
const val API_HEADER_NOT_FOUND_MSG = "Api-Key header not found."
......@@ -16,6 +18,14 @@ class ApiKeyFilter : WebFilter {
@Value("\${API_KEY}")
lateinit var API_KEY: String
@PostConstruct
fun postConstruct() {
if (API_KEY.length < 30) {
throw InvalidKeyException("Provided API_KEY is too short. Minimum key length is 30 characters.")
}
}
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
val apiKey = exchange.request.headers.getFirst(API_KEY_HEADER)
return if (apiKey == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.