From 6b56e92de4d02a917e57dc9d45782d9baf3ff498 Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Wed, 2 Oct 2024 13:50:26 +0200 Subject: [PATCH 1/8] FDP-2318: spotless Signed-off-by: Loes Immens --- build.gradle.kts | 35 +++++++++++++++++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../utilities/kafka/avro/AvroDeserializer.kt | 18 ++++------ license-template.kt | 3 ++ scripts/pre-commit | 35 +++++++++++++++++++ 5 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 license-template.kt create mode 100755 scripts/pre-commit diff --git a/build.gradle.kts b/build.gradle.kts index b779d68..82cf7f0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ +import com.diffplug.gradle.spotless.SpotlessExtension import io.spring.gradle.dependencymanagement.internal.dsl.StandardDependencyManagementExtension import org.jetbrains.kotlin.com.github.gundy.semver4j.SemVer import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.net.URI plugins { @@ -8,6 +10,7 @@ plugins { kotlin("jvm") version "2.0.0" apply false kotlin("plugin.spring") version "2.0.0" apply false id("org.sonarqube") version "5.0.0.4638" + id("com.diffplug.spotless") version("6.25.0") } sonar { @@ -31,6 +34,7 @@ subprojects { apply(plugin = "org.gradle.maven-publish") apply(plugin = "jacoco") apply(plugin = "jacoco-report-aggregation") + apply(plugin = "com.diffplug.spotless") group = rootProject.group version = rootProject.version @@ -59,8 +63,18 @@ subprojects { } } - tasks.withType { - useJUnitPlatform() + + extensions.configure { + kotlin { + // by default the target is every '.kt' and '.kts' file in the java source sets + ktfmt().dropboxStyle().configure { + it.setMaxWidth(120) + } + licenseHeaderFile( + "${project.rootDir}/license-template.kt", + "package") + .updateYearWithLatest(false) + } } extensions.configure { @@ -81,4 +95,21 @@ subprojects { } } } + + tasks.withType { + useJUnitPlatform() + } + + tasks.register("updateGitHooks") { + description = "Copies the pre-commit Git Hook to the .git/hooks folder." + group = "verification" + from("${project.rootDir}/scripts/pre-commit") + into("${project.rootDir}/.git/hooks") + } + + tasks.withType { + dependsOn( + tasks.named("updateGitHooks") + ) + } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 09523c0..df97d72 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt index 1db7952..08df5ca 100644 --- a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt +++ b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt @@ -1,8 +1,6 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro import org.apache.avro.Schema @@ -21,14 +19,11 @@ class AvroDeserializer(deserializerSchemas: List) : Deserializer(SpecificData(), null) init { - // Add all schema's to the decoder - deserializerSchemas - .forEach { decoder.addSchema(it) } + // Add all schemas to the decoder + deserializerSchemas.forEach { decoder.addSchema(it) } } - /** - * Deserializes a Byte Array to an Avro SpecificRecordBase - */ + /** Deserializes a Byte Array to an Avro SpecificRecordBase */ override fun deserialize(topic: String, payload: ByteArray): SpecificRecordBase { try { logger.trace("Deserializing for {}", topic) @@ -38,4 +33,3 @@ class AvroDeserializer(deserializerSchemas: List) : Deserializer&2 "Spotless Apply found violations it could not fix." + echo "Run spotless apply in your terminal and fix the issues before trying to commit again." + echo " ******************************************** " + echo "*********************************************************" + #Exit + exit 1 +fi From 0a84dfc6fec241e7c42b5c1b157c23b4251ce9cf Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Wed, 2 Oct 2024 13:52:06 +0200 Subject: [PATCH 2/8] FDP-2318: Sonar issue fixed Signed-off-by: Loes Immens --- .../utilities/spring/oauth/providers/TokenProvider.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt index d4898bf..a9638bc 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt @@ -1,11 +1,14 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.providers import java.util.* -interface TokenProvider { +fun interface TokenProvider { /** - * Retrieve an access token for instance from an oauth provider. - * Tokens are cached internally, there is no need to cache them outside of this library. + * Retrieve an access token for instance from an oauth provider. Tokens are cached internally, there is no need to + * cache them outside of this library. */ fun getAccessToken(): Optional } From b0696aee4cbe6de93f2e6b8812e51f0c6ba10404 Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Wed, 2 Oct 2024 13:53:03 +0200 Subject: [PATCH 3/8] FDP-2318: formatting Signed-off-by: Loes Immens --- .../gxf/utilities/kafka/avro/AvroEncoder.kt | 11 +- .../utilities/kafka/avro/AvroSerializer.kt | 15 +-- .../kafka/avro/AvroDeserializerTest.kt | 14 +-- .../utilities/kafka/avro/AvroEncoderTest.kt | 6 +- .../kafka/avro/AvroSerializerTest.kt | 3 + .../oauth/handler/KafkaOAuthException.kt | 8 +- .../OAuthAuthenticateCallbackHandler.kt | 44 +++---- .../OAuthAuthenticateCallbackHandlerTest.kt | 40 +++---- .../kafka/message/signing/MessageSigner.kt | 110 +++++++++--------- .../MessageSigningAutoConfiguration.kt | 3 +- .../signing/MessageSigningProperties.kt | 3 +- .../signing/UncheckedSecurityException.kt | 7 +- .../message/wrapper/SignableMessageWrapper.kt | 22 ++-- .../message/signing/MessageSignerTest.kt | 38 +++--- .../MessageSigningAutoConfigurationTest.kt | 6 +- .../spring/oauth/NoTokenProviderTest.kt | 7 +- .../spring/oauth/OAuthTokenProviderTest.kt | 7 +- .../spring/oauth/OAuthTokenClientContext.kt | 8 +- .../spring/oauth/config/OAuthClientConfig.kt | 48 ++++---- .../oauth/config/OAuthClientProperties.kt | 23 ++-- .../oauth/config/condition/OAuthCondition.kt | 12 +- .../condition/OAuthDisabledCondition.kt | 15 +-- .../config/condition/OAuthEnabledCondition.kt | 15 +-- .../oauth/exceptions/OAuthTokenException.kt | 8 +- .../spring/oauth/providers/NoTokenProvider.kt | 12 +- .../oauth/providers/OAuthTokenProvider.kt | 24 ++-- .../oauth/config/OAuthClientConfigTest.kt | 14 +-- 27 files changed, 226 insertions(+), 297 deletions(-) diff --git a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt index 9cee34f..b1d2590 100644 --- a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt +++ b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt @@ -1,12 +1,15 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro +import java.io.IOException +import java.io.OutputStream +import kotlin.reflect.KClass import org.apache.avro.message.BinaryMessageEncoder import org.apache.avro.specific.SpecificData import org.apache.avro.specific.SpecificRecordBase import org.slf4j.LoggerFactory -import java.io.IOException -import java.io.OutputStream -import kotlin.reflect.KClass object AvroEncoder { val encoders: HashMap, BinaryMessageEncoder> = HashMap() @@ -31,7 +34,7 @@ object AvroEncoder { private fun getEncoder(message: SpecificRecordBase): BinaryMessageEncoder { val existingEncoder = encoders[message::class] - if(existingEncoder != null) { + if (existingEncoder != null) { return existingEncoder } diff --git a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt index 62ada15..a8da05e 100644 --- a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt +++ b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt @@ -1,24 +1,20 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro +import java.io.ByteArrayOutputStream import org.apache.avro.specific.SpecificRecordBase import org.apache.kafka.common.errors.SerializationException import org.apache.kafka.common.serialization.Serializer import org.slf4j.LoggerFactory -import java.io.ByteArrayOutputStream class AvroSerializer : Serializer { companion object { private val logger = LoggerFactory.getLogger(AvroSerializer::class.java) } - /** - * Serializes a Byte Array to an Avro specific record - */ + /** Serializes a Byte Array to an Avro specific record */ override fun serialize(topic: String?, data: SpecificRecordBase): ByteArray { try { logger.trace("Serializing for {}", topic) @@ -30,4 +26,3 @@ class AvroSerializer : Serializer { } } } - diff --git a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt index 8141af8..2443b5f 100644 --- a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt +++ b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro import com.alliander.gxf.utilities.kafka.avro.AvroSchema1 @@ -17,14 +20,11 @@ class AvroDeserializerTest { val message3 = AvroSchema3("message in a bottle") val deserializer = AvroDeserializer(listOf(AvroSchema1.getClassSchema(), AvroSchema2.getClassSchema())) - assertThat(deserializer.deserialize("topic1", message1.toByteBuffer().array())) - .isEqualTo(message1) - assertThat(deserializer.deserialize("topic2", message2.toByteBuffer().array())) - .isEqualTo(message2) + assertThat(deserializer.deserialize("topic1", message1.toByteBuffer().array())).isEqualTo(message1) + assertThat(deserializer.deserialize("topic2", message2.toByteBuffer().array())).isEqualTo(message2) - assertThatThrownBy({deserializer.deserialize("topic3", message3.toByteBuffer().array())}) + assertThatThrownBy({ deserializer.deserialize("topic3", message3.toByteBuffer().array()) }) .isInstanceOf(SerializationException::class.java) - .hasMessageContaining("Error deserializing Avro message for topic: topic3"); - + .hasMessageContaining("Error deserializing Avro message for topic: topic3") } } diff --git a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt index 66177d2..793ddee 100644 --- a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt +++ b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt @@ -1,11 +1,13 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro import com.alliander.gxf.utilities.kafka.avro.AvroSchema1 import com.alliander.gxf.utilities.kafka.avro.AvroSchema2 -import org.assertj.core.api.AbstractIntegerAssert +import java.io.ByteArrayOutputStream import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import java.io.ByteArrayOutputStream class AvroEncoderTest { @Test diff --git a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt index 71ba26e..b4add06 100644 --- a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt +++ b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro import com.alliander.gxf.utilities.kafka.avro.AvroSchema1 diff --git a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt index c2393e5..37617a6 100644 --- a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt +++ b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt @@ -1,8 +1,6 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.oauth.handler class KafkaOAuthException(s: String, e: Exception) : Throwable(s, e) diff --git a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt index bb508d3..8e96afc 100644 --- a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt +++ b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt @@ -1,13 +1,18 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.oauth.handler import com.microsoft.aad.msal4j.ClientCredentialFactory import com.microsoft.aad.msal4j.ClientCredentialParameters import com.microsoft.aad.msal4j.ConfidentialClientApplication +import java.io.File +import java.io.IOException +import java.nio.charset.StandardCharsets +import java.nio.file.Files +import javax.security.auth.callback.Callback +import javax.security.auth.callback.UnsupportedCallbackException +import javax.security.auth.login.AppConfigurationEntry import org.apache.kafka.common.config.ConfigException import org.apache.kafka.common.security.auth.AuthenticateCallbackHandler import org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule @@ -16,13 +21,6 @@ import org.apache.kafka.common.security.oauthbearer.OAuthBearerTokenCallback import org.apache.kafka.common.security.oauthbearer.OAuthBearerValidatorCallback import org.apache.kafka.common.security.oauthbearer.internals.secured.BasicOAuthBearerToken import org.slf4j.LoggerFactory -import java.io.File -import java.io.IOException -import java.nio.charset.StandardCharsets -import java.nio.file.Files -import javax.security.auth.callback.Callback -import javax.security.auth.callback.UnsupportedCallbackException -import javax.security.auth.login.AppConfigurationEntry class OAuthAuthenticateCallbackHandler : AuthenticateCallbackHandler { internal lateinit var tokenFilePath: String @@ -44,13 +42,10 @@ class OAuthAuthenticateCallbackHandler : AuthenticateCallbackHandler { saslMechanism: String, jaasConfigEntries: List ) { - getOptions(saslMechanism, jaasConfigEntries) - .let { setFields(it) } + getOptions(saslMechanism, jaasConfigEntries).let { setFields(it) } } - private fun getOptions( - saslMechanism: String, jaasConfigEntries: List - ): Map { + private fun getOptions(saslMechanism: String, jaasConfigEntries: List): Map { require(saslMechanism == OAuthBearerLoginModule.OAUTHBEARER_MECHANISM) { "Unexpected SASL mechanism: ${saslMechanism}" } @@ -63,10 +58,7 @@ class OAuthAuthenticateCallbackHandler : AuthenticateCallbackHandler { private fun setFields(options: Map) { clientId = options.getProperty(CLIENT_ID_CONFIG) tokenEndpoint = options.getProperty(TOKEN_ENDPOINT_CONFIG) - scopes = options.getProperty(SCOPE_CONFIG) - .split(",".toRegex()) - .dropLastWhile { it.isEmpty() } - .toSet() + scopes = options.getProperty(SCOPE_CONFIG).split(",".toRegex()).dropLastWhile { it.isEmpty() }.toSet() tokenFilePath = options.getProperty(TOKEN_FILE_CONFIG) } @@ -89,8 +81,7 @@ class OAuthAuthenticateCallbackHandler : AuthenticateCallbackHandler { is OAuthBearerTokenCallback -> callback.token(getToken()) is OAuthBearerValidatorCallback -> throw UnsupportedCallbackException(callback, "Validate callback not yet implemented") - else -> - throw UnsupportedCallbackException(callback, "Unknown callback type ${callback.javaClass.name}") + else -> throw UnsupportedCallbackException(callback, "Unknown callback type ${callback.javaClass.name}") } } } @@ -102,9 +93,7 @@ class OAuthAuthenticateCallbackHandler : AuthenticateCallbackHandler { val token = readTokenFile(tokenFilePath) val credential = ClientCredentialFactory.createFromClientAssertion(token) val aadParameters = ClientCredentialParameters.builder(scopes).build() - val aadClient = ConfidentialClientApplication.builder(clientId, credential) - .authority(tokenEndpoint) - .build() + val aadClient = ConfidentialClientApplication.builder(clientId, credential).authority(tokenEndpoint).build() val authResult = aadClient.acquireToken(aadParameters).get() return BasicOAuthBearerToken( @@ -112,8 +101,7 @@ class OAuthAuthenticateCallbackHandler : AuthenticateCallbackHandler { aadParameters.scopes(), authResult.expiresOnDate().toInstant().toEpochMilli(), aadClient.clientId(), - System.currentTimeMillis() - ) + System.currentTimeMillis()) } catch (e: InterruptedException) { Thread.currentThread().interrupt() throw KafkaOAuthException("Retrieving JWT token was interrupted", e) diff --git a/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt b/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt index 38b4c5f..c9649a6 100644 --- a/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt +++ b/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt @@ -1,22 +1,19 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.oauth.handler import com.gxf.utilities.kafka.oauth.handler.OAuthAuthenticateCallbackHandler.Companion.CLIENT_ID_CONFIG import com.gxf.utilities.kafka.oauth.handler.OAuthAuthenticateCallbackHandler.Companion.SCOPE_CONFIG import com.gxf.utilities.kafka.oauth.handler.OAuthAuthenticateCallbackHandler.Companion.TOKEN_ENDPOINT_CONFIG import com.gxf.utilities.kafka.oauth.handler.OAuthAuthenticateCallbackHandler.Companion.TOKEN_FILE_CONFIG +import java.lang.IllegalArgumentException +import javax.security.auth.login.AppConfigurationEntry +import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag.REQUIRED import org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule import org.assertj.core.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import java.lang.IllegalArgumentException -import javax.security.auth.login.AppConfigurationEntry -import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag.REQUIRED - class OAuthAuthenticateCallbackHandlerTest { @@ -29,16 +26,10 @@ class OAuthAuthenticateCallbackHandlerTest { fun configure() { val handler = OAuthAuthenticateCallbackHandler() - val appConfig = AppConfigurationEntry( - "org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule", - REQUIRED, - options() - ) - handler.configure( - emptyMap(), - OAuthBearerLoginModule.OAUTHBEARER_MECHANISM, - listOf(appConfig) - ) + val appConfig = + AppConfigurationEntry( + "org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule", REQUIRED, options()) + handler.configure(emptyMap(), OAuthBearerLoginModule.OAUTHBEARER_MECHANISM, listOf(appConfig)) assertEquals(clientId, handler.clientId) assertEquals(tokenEndpoint, handler.tokenEndpoint) @@ -51,12 +42,8 @@ class OAuthAuthenticateCallbackHandlerTest { val handler = OAuthAuthenticateCallbackHandler() Assertions.assertThatThrownBy { - handler.configure( - emptyMap(), - OAuthBearerLoginModule.OAUTHBEARER_MECHANISM, - emptyList() - ) - } + handler.configure(emptyMap(), OAuthBearerLoginModule.OAUTHBEARER_MECHANISM, emptyList()) + } .isInstanceOf(IllegalArgumentException::class.java) .hasMessage("Must supply exactly 1 non-null JAAS mechanism configuration (size was 0)") } @@ -82,6 +69,5 @@ class OAuthAuthenticateCallbackHandlerTest { CLIENT_ID_CONFIG to clientId, TOKEN_ENDPOINT_CONFIG to tokenEndpoint, SCOPE_CONFIG to scopes, - TOKEN_FILE_CONFIG to tokenFilePath - ) + TOKEN_FILE_CONFIG to tokenFilePath) } diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt index 4a31737..80d1efa 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt @@ -1,11 +1,17 @@ -// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// SPDX-FileCopyrightText: Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 - package com.gxf.utilities.kafka.message.signing import com.gxf.utilities.kafka.avro.AvroEncoder import com.gxf.utilities.kafka.message.wrapper.SignableMessageWrapper +import java.io.IOException +import java.io.UncheckedIOException +import java.nio.charset.StandardCharsets +import java.security.* +import java.security.spec.X509EncodedKeySpec +import java.util.* +import java.util.regex.Pattern import org.apache.avro.specific.SpecificRecordBase import org.apache.kafka.clients.consumer.ConsumerRecord import org.apache.kafka.clients.producer.ProducerRecord @@ -15,13 +21,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.ssl.pem.PemContent import org.springframework.core.io.Resource import org.springframework.stereotype.Component -import java.io.IOException -import java.io.UncheckedIOException -import java.nio.charset.StandardCharsets -import java.security.* -import java.security.spec.X509EncodedKeySpec -import java.util.* -import java.util.regex.Pattern @Component // Only instantiate when no other bean has been configured @@ -40,7 +39,9 @@ class MessageSigner(properties: MessageSigningProperties) { init { if (properties.signingEnabled) { - require(!(signingKey == null && verificationKey == null)) { "A signing key (PrivateKey) or verification key (PublicKey) must be provided" } + require(!(signingKey == null && verificationKey == null)) { + "A signing key (PrivateKey) or verification key (PublicKey) must be provided" + } } } @@ -52,11 +53,11 @@ class MessageSigner(properties: MessageSigningProperties) { * Signs the provided `message`, overwriting an existing signature field inside the message object. * * @param message the message to be signed - * @return Returns the signed (unwrapped) message. If signing is disabled through configuration, the message will be returned unchanged. - * - * @throws IllegalStateException if this message signer has a public key for signature - * verification, but does not have the private key needed for signing messages. - * @throws UncheckedIOException if determining the bytes for the message throws an IOException. + * @return Returns the signed (unwrapped) message. If signing is disabled through configuration, the message will be + * returned unchanged. + * @throws IllegalStateException if this message signer has a public key for signature verification, but does not + * have the private key needed for signing messages. + * @throws UncheckedIOException if determining the bytes for the message throws an IOException. * @throws UncheckedSecurityException if the signing process throws a SignatureException. */ fun signUsingField(message: SignableMessageWrapper): T { @@ -72,12 +73,14 @@ class MessageSigner(properties: MessageSigningProperties) { * already set. * * @param producerRecord the record to be signed - * @throws IllegalStateException if this message signer has a public key for signature - * verification, but does not have the private key needed for signing messages. - * @throws UncheckedIOException if determining the bytes for the message throws an IOException. + * @throws IllegalStateException if this message signer has a public key for signature verification, but does not + * have the private key needed for signing messages. + * @throws UncheckedIOException if determining the bytes for the message throws an IOException. * @throws UncheckedSecurityException if the signing process throws a SignatureException. */ - fun signUsingHeader(producerRecord: ProducerRecord): ProducerRecord { + fun signUsingHeader( + producerRecord: ProducerRecord + ): ProducerRecord { if (this.signingEnabled) { val signature = this.signature(producerRecord) producerRecord.headers().add(RECORD_HEADER_KEY_SIGNATURE, signature) @@ -88,19 +91,20 @@ class MessageSigner(properties: MessageSigningProperties) { /** * Determines the signature for the given `message`. * - * - * The value for the signature in the message will be set to `null` to properly determine - * the signature, but is restored to its original value before this method returns. + * The value for the signature in the message will be set to `null` to properly determine the signature, but is + * restored to its original value before this method returns. * * @param message the message to be signed * @return the signature for the message - * @throws IllegalStateException if this message signer has a public key for signature - * verification, but does not have the private key needed for signing messages. - * @throws UncheckedIOException if determining the bytes for the message throws an IOException. + * @throws IllegalStateException if this message signer has a public key for signature verification, but does not + * have the private key needed for signing messages. + * @throws UncheckedIOException if determining the bytes for the message throws an IOException. * @throws UncheckedSecurityException if the signing process throws a SignatureException. */ private fun signature(message: SignableMessageWrapper<*>): ByteArray { - check(this.canSignMessages()) { "This MessageSigner is not configured for signing, it can only be used for verification" } + check(this.canSignMessages()) { + "This MessageSigner is not configured for signing, it can only be used for verification" + } val oldSignature = message.getSignature() message.setSignature(null) val byteArray = this.toByteArray(message) @@ -116,19 +120,20 @@ class MessageSigner(properties: MessageSigningProperties) { /** * Determines the signature for the given `producerRecord`. * - * - * The value for the signature in the record will be set to `null` to properly determine - * the signature, but is restored to its original value before this method returns. + * The value for the signature in the record will be set to `null` to properly determine the signature, but is + * restored to its original value before this method returns. * * @param producerRecord the record to be signed * @return the signature for the record - * @throws IllegalStateException if this message signer has a public key for signature - * verification, but does not have the private key needed for signing messages. - * @throws UncheckedIOException if determining the bytes throws an IOException. + * @throws IllegalStateException if this message signer has a public key for signature verification, but does not + * have the private key needed for signing messages. + * @throws UncheckedIOException if determining the bytes throws an IOException. * @throws UncheckedSecurityException if the signing process throws a SignatureException. */ private fun signature(producerRecord: ProducerRecord): ByteArray { - check(this.canSignMessages()) { "This MessageSigner is not configured for signing, it can only be used for verification" } + check(this.canSignMessages()) { + "This MessageSigner is not configured for signing, it can only be used for verification" + } val oldSignatureHeader = producerRecord.headers().lastHeader(RECORD_HEADER_KEY_SIGNATURE) producerRecord.headers().remove(RECORD_HEADER_KEY_SIGNATURE) val specificRecordBase = producerRecord.value() @@ -145,11 +150,12 @@ class MessageSigner(properties: MessageSigningProperties) { } private fun signature(byteArray: ByteArray): ByteArray { - val messageBytes: ByteArray = if (this.stripAvroHeader) { - this.stripAvroHeader(byteArray) - } else { - byteArray - } + val messageBytes: ByteArray = + if (this.stripAvroHeader) { + this.stripAvroHeader(byteArray) + } else { + byteArray + } val signingSignature = signatureInstance(signatureAlgorithm, signatureProvider, signingKey!!) signingSignature.update(messageBytes) return signingSignature.sign() @@ -163,8 +169,7 @@ class MessageSigner(properties: MessageSigningProperties) { * Verifies the signature of the provided `message` using the signature in a message field. * * @param message the message to be verified - * @return `true` if the signature of the given `message` was verified; `false` - * if not. + * @return `true` if the signature of the given `message` was verified; `false` if not. */ fun verifyUsingField(message: SignableMessageWrapper): Boolean { if (!this.canVerifyMessageSignatures()) { @@ -194,9 +199,7 @@ class MessageSigner(properties: MessageSigningProperties) { * Verifies the signature of the provided `consumerRecord` using the signature from the message header. * * @param consumerRecord the record to be verified - * @return `true` if the signature of the given `consumerRecord` was verified; `false` - * if not. - * SignatureException. + * @return `true` if the signature of the given `consumerRecord` was verified; `false` if not. SignatureException. */ fun verifyUsingHeader(consumerRecord: ConsumerRecord): Boolean { if (!this.canVerifyMessageSignatures()) { @@ -227,20 +230,21 @@ class MessageSigner(properties: MessageSigningProperties) { @Throws(SignatureException::class) private fun verifySignatureBytes(signatureBytes: ByteArray, messageByteArray: ByteArray): Boolean { - val messageBytes: ByteArray = if (this.stripAvroHeader) { - this.stripAvroHeader(messageByteArray) - } else { - messageByteArray - } + val messageBytes: ByteArray = + if (this.stripAvroHeader) { + this.stripAvroHeader(messageByteArray) + } else { + messageByteArray + } val verificationSignature = signatureInstance(signatureAlgorithm, signatureProvider, verificationKey!!) verificationSignature.update(messageBytes) return verificationSignature.verify(signatureBytes) } private fun hasAvroHeader(bytes: ByteArray): Boolean { - return (bytes.size >= AVRO_HEADER_LENGTH) - && ((bytes[0].toInt() and 0xFF) == 0xC3) - && ((bytes[1].toInt() and 0xFF) == 0x01) + return (bytes.size >= AVRO_HEADER_LENGTH) && + ((bytes[0].toInt() and 0xFF) == 0xC3) && + ((bytes[1].toInt() and 0xFF) == 0x01) } private fun stripAvroHeader(bytes: ByteArray): ByteArray { @@ -273,8 +277,7 @@ class MessageSigner(properties: MessageSigningProperties) { this.keyAlgorithm, this.signatureProvider, this.canSignMessages(), - this.canVerifyMessageSignatures() - ) + this.canVerifyMessageSignatures()) } companion object { @@ -360,5 +363,4 @@ class MessageSigner(properties: MessageSigningProperties) { } } } - } diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt index b23ea10..293ddb6 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt @@ -1,7 +1,6 @@ -// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// SPDX-FileCopyrightText: Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 - package com.gxf.utilities.kafka.message.signing import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt index ebde4b6..83d53d8 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt @@ -1,7 +1,6 @@ -// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// SPDX-FileCopyrightText: Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 - package com.gxf.utilities.kafka.message.signing import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt index 52c6cd4..ba518aa 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt @@ -1,18 +1,15 @@ -// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// SPDX-FileCopyrightText: Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 - package com.gxf.utilities.kafka.message.signing import java.io.Serial import java.security.GeneralSecurityException - class UncheckedSecurityException @JvmOverloads constructor(message: String? = null, cause: GeneralSecurityException) : RuntimeException(message, cause) { - @Serial - private val serialVersionUID = 5152038114753546167L + @Serial private val serialVersionUID = 5152038114753546167L override val cause: GeneralSecurityException get() = super.cause as GeneralSecurityException diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt index 853b392..d6d35a3 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt @@ -1,30 +1,22 @@ -// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// SPDX-FileCopyrightText: Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 - package com.gxf.utilities.kafka.message.wrapper import java.io.IOException /** - * Wrapper for signable messages. Because these messages are generated from Avro schemas, they can't be changed. - * This wrapper unifies them for the MessageSigner. + * Wrapper for signable messages. Because these messages are generated from Avro schemas, they can't be changed. This + * wrapper unifies them for the MessageSigner. */ abstract class SignableMessageWrapper(val message: T) { - /** - * @return ByteArray of the whole message - */ - @Throws(IOException::class) - abstract fun toByteArray(): ByteArray + /** @return ByteArray of the whole message */ + @Throws(IOException::class) abstract fun toByteArray(): ByteArray - /** - * @return ByteArray of the signature in the message - */ + /** @return ByteArray of the signature in the message */ abstract fun getSignature(): ByteArray? - /** - * @param signature The signature in ByteArray form to be set on the message - */ + /** @param signature The signature in ByteArray form to be set on the message */ abstract fun setSignature(signature: ByteArray?) } diff --git a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt index 03c6e9f..d9921a8 100644 --- a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt +++ b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt @@ -1,10 +1,13 @@ -// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// SPDX-FileCopyrightText: Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 - package com.gxf.utilities.kafka.message.signing import com.gxf.utilities.kafka.message.wrapper.SignableMessageWrapper +import java.nio.charset.StandardCharsets +import java.security.SecureRandom +import java.util.Random +import java.util.function.Consumer import org.apache.avro.Schema import org.apache.avro.specific.SpecificRecordBase import org.apache.kafka.clients.consumer.ConsumerRecord @@ -13,22 +16,18 @@ import org.apache.kafka.common.header.Header import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.core.io.ClassPathResource -import java.nio.charset.StandardCharsets -import java.security.SecureRandom -import java.util.Random -import java.util.function.Consumer class MessageSignerTest { - private val messageSignerProperties = MessageSigningProperties( - signingEnabled = true, - stripAvroHeader = true, - signatureAlgorithm = "SHA256withRSA", - signatureProvider = "SunRsaSign", - keyAlgorithm = "RSA", - privateKeyFile = ClassPathResource("/rsa-private.pem"), - publicKeyFile = ClassPathResource("/rsa-public.pem") - ) + private val messageSignerProperties = + MessageSigningProperties( + signingEnabled = true, + stripAvroHeader = true, + signatureAlgorithm = "SHA256withRSA", + signatureProvider = "SunRsaSign", + keyAlgorithm = "RSA", + privateKeyFile = ClassPathResource("/rsa-private.pem"), + publicKeyFile = ClassPathResource("/rsa-public.pem")) private val messageSigner = MessageSigner(messageSignerProperties) @@ -121,7 +120,7 @@ class MessageSignerTest { val randomSignature = this.randomSignature() val messageWrapper = this.messageWrapper(randomSignature) - val validSignature =messageSigner.verifyUsingField(messageWrapper) + val validSignature = messageSigner.verifyUsingField(messageWrapper) assertThat(validSignature).isFalse() } @@ -182,9 +181,7 @@ class MessageSignerTest { private fun producerRecordToConsumerRecord(producerRecord: ProducerRecord): ConsumerRecord { val consumerRecord = ConsumerRecord(producerRecord.topic(), 0, 123L, producerRecord.key(), producerRecord.value()) - producerRecord.headers().forEach(Consumer { header: Header? -> - consumerRecord.headers().add(header) - }) + producerRecord.headers().forEach(Consumer { header: Header? -> consumerRecord.headers().add(header) }) return consumerRecord } @@ -214,7 +211,8 @@ class MessageSignerTest { override fun getSchema(): Schema { return Schema.Parser() - .parse("""{"type":"record","name":"Message","namespace":"com.alliander.osgp.kafka.message.signing","fields":[{"name":"message","type":{"type":"string","avro.java.string":"String"}}]}""") + .parse( + """{"type":"record","name":"Message","namespace":"com.alliander.osgp.kafka.message.signing","fields":[{"name":"message","type":{"type":"string","avro.java.string":"String"}}]}""") } override fun get(field: Int): Any { diff --git a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt index 6474d2e..52fe3b8 100644 --- a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt +++ b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.signing import org.assertj.core.api.Assertions.assertThat @@ -13,8 +16,7 @@ import org.springframework.test.context.TestPropertySource @EnableConfigurationProperties(MessageSigningProperties::class) @TestPropertySource("classpath:/application.yaml") class MessageSigningAutoConfigurationTest { - @Autowired - private lateinit var messageSigner: MessageSigner + @Autowired private lateinit var messageSigner: MessageSigner @Test fun autoConfigurationIntegrationTest() { diff --git a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt index 3e1df37..bcbfb1d 100644 --- a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt +++ b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth import com.gxf.utilities.spring.oauth.providers.NoTokenProvider @@ -7,13 +10,11 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit.jupiter.SpringJUnitConfig - @SpringJUnitConfig(OAuthTokenClientContext::class) @TestPropertySource("classpath:oauth-disabled.properties") class NoTokenProviderTest { - @Autowired - lateinit var tokenProvider: TokenProvider + @Autowired lateinit var tokenProvider: TokenProvider @Test fun test() { diff --git a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt index d085108..cb272c5 100644 --- a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt +++ b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth import com.gxf.utilities.spring.oauth.providers.OAuthTokenProvider @@ -7,13 +10,11 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit.jupiter.SpringJUnitConfig - @SpringJUnitConfig(OAuthTokenClientContext::class) @TestPropertySource("classpath:oauth-enabled.properties") class OAuthTokenProviderTest { - @Autowired - lateinit var tokenProvider: TokenProvider + @Autowired lateinit var tokenProvider: TokenProvider @Test fun test() { diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt index 4ec265f..4a6f737 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt @@ -1,8 +1,6 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth import com.gxf.utilities.spring.oauth.config.OAuthClientConfig diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt index cbe1852..e4aab41 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt @@ -1,8 +1,6 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config import com.gxf.utilities.spring.oauth.config.condition.OAuthEnabledCondition @@ -11,11 +9,6 @@ import com.microsoft.aad.msal4j.ClientCredentialFactory import com.microsoft.aad.msal4j.ClientCredentialParameters import com.microsoft.aad.msal4j.ConfidentialClientApplication import com.microsoft.aad.msal4j.IClientCredential -import org.slf4j.LoggerFactory -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Conditional -import org.springframework.context.annotation.Configuration -import org.springframework.core.io.Resource import java.io.ByteArrayInputStream import java.nio.file.Files import java.security.KeyFactory @@ -25,6 +18,11 @@ import java.security.cert.X509Certificate import java.security.spec.PKCS8EncodedKeySpec import java.util.* import java.util.stream.Collectors +import org.slf4j.LoggerFactory +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Conditional +import org.springframework.context.annotation.Configuration +import org.springframework.core.io.Resource @Configuration @Conditional(OAuthEnabledCondition::class) @@ -36,17 +34,15 @@ class OAuthClientConfig { @Bean fun clientCredentialParameters(clientData: OAuthClientProperties): ClientCredentialParameters { - return ClientCredentialParameters - .builder(setOf(clientData.scope)) - .build() + return ClientCredentialParameters.builder(setOf(clientData.scope)).build() } @Bean fun confidentialClientApplication(clientData: OAuthClientProperties): ConfidentialClientApplication { - val credential: IClientCredential = ClientCredentialFactory.createFromCertificate( - getPrivateKey(Objects.requireNonNull(clientData.privateKey)), - getCertificate(Objects.requireNonNull(clientData.certificate)) - ) + val credential: IClientCredential = + ClientCredentialFactory.createFromCertificate( + getPrivateKey(Objects.requireNonNull(clientData.privateKey)), + getCertificate(Objects.requireNonNull(clientData.certificate))) return try { ConfidentialClientApplication.builder(clientData.clientId, credential) .authority(clientData.tokenEndpoint) @@ -56,15 +52,15 @@ class OAuthClientConfig { } } - /** - * Reads a private key file and puts - */ + /** Reads a private key file and puts */ fun getPrivateKey(resource: Resource): PrivateKey { try { LOGGER.info("Reading private key from: ${resource.uri}") Files.lines(resource.file.toPath()).use { lines -> - val privateKeyContent = lines.filter { line: String -> !line.matches("-----[A-Z ]*-----".toRegex()) } - .collect(Collectors.joining()) + val privateKeyContent = + lines + .filter { line: String -> !line.matches("-----[A-Z ]*-----".toRegex()) } + .collect(Collectors.joining()) val kf = KeyFactory.getInstance("RSA") val keySpecPKCS8 = PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyContent)) return kf.generatePrivate(keySpecPKCS8) @@ -78,8 +74,10 @@ class OAuthClientConfig { try { LOGGER.info("Reading certificate from: ${resource.uri}") Files.lines(resource.file.toPath()).use { lines -> - val certificateContent = lines.filter { line: String -> !line.matches("-----[A-Z ]*-----".toRegex()) } - .collect(Collectors.joining()) + val certificateContent = + lines + .filter { line: String -> !line.matches("-----[A-Z ]*-----".toRegex()) } + .collect(Collectors.joining()) val inputStream = ByteArrayInputStream(Base64.getDecoder().decode(certificateContent)) return CertificateFactory.getInstance("X.509").generateCertificate(inputStream) as X509Certificate } @@ -87,6 +85,4 @@ class OAuthClientConfig { throw OAuthTokenException("Error getting certificate", e) } } - - } diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt index 17e4a83..7ed20cc 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt @@ -1,8 +1,6 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config import com.gxf.utilities.spring.oauth.config.condition.OAuthEnabledCondition @@ -14,14 +12,9 @@ import org.springframework.core.io.Resource @Configuration @Conditional(OAuthEnabledCondition::class) class OAuthClientProperties( - @Value("\${oauth.client.client-id}") - val clientId: String, - @Value("\${oauth.client.scope}") - val scope: String, - @Value("\${oauth.client.token-endpoint}") - val tokenEndpoint: String, - @Value("\${oauth.client.private-key}") - val privateKey: Resource, - @Value("\${oauth.client.certificate}") - val certificate: Resource + @Value("\${oauth.client.client-id}") val clientId: String, + @Value("\${oauth.client.scope}") val scope: String, + @Value("\${oauth.client.token-endpoint}") val tokenEndpoint: String, + @Value("\${oauth.client.private-key}") val privateKey: Resource, + @Value("\${oauth.client.certificate}") val certificate: Resource ) diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt index d073812..c0c6b6e 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt @@ -1,16 +1,12 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config.condition import org.springframework.context.annotation.Condition import org.springframework.context.annotation.ConditionContext -/** - * Condition to enable or disable the Oauth Client components - */ +/** Condition to enable or disable the Oauth Client components */ abstract class OAuthCondition : Condition { fun oAuthEnabled(context: ConditionContext) = context.environment.getProperty("oauth.client.enabled").equals("true", ignoreCase = true) diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt index c78fab5..4b133f2 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt @@ -1,17 +1,12 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config.condition import org.springframework.context.annotation.ConditionContext import org.springframework.core.type.AnnotatedTypeMetadata -/** - * Condition if OAuth is disabled - */ +/** Condition if OAuth is disabled */ class OAuthDisabledCondition : OAuthCondition() { - override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean = - !oAuthEnabled(context) + override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean = !oAuthEnabled(context) } diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt index fbc2edc..e694919 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt @@ -1,17 +1,12 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config.condition import org.springframework.context.annotation.ConditionContext import org.springframework.core.type.AnnotatedTypeMetadata -/** - * Condition if OAuth is enabled - */ +/** Condition if OAuth is enabled */ class OAuthEnabledCondition : OAuthCondition() { - override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean = - oAuthEnabled(context) + override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean = oAuthEnabled(context) } diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt index 8d3e2df..9bca94d 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt @@ -1,8 +1,6 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.exceptions class OAuthTokenException(message: String?, cause: Throwable?) : RuntimeException(message, cause) diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt index 81bc8c0..131901b 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt @@ -1,16 +1,16 @@ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.providers import com.gxf.utilities.spring.oauth.config.condition.OAuthDisabledCondition +import java.util.* import org.springframework.context.annotation.Conditional import org.springframework.stereotype.Service -import java.util.* @Service @Conditional(OAuthDisabledCondition::class) class NoTokenProvider : TokenProvider { - /** - * Returns an empty optional indicating that no oauth provider is configured. - */ - override fun getAccessToken(): Optional = - Optional.empty() + /** Returns an empty optional indicating that no oauth provider is configured. */ + override fun getAccessToken(): Optional = Optional.empty() } diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt index 2b60c45..287e1a3 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt @@ -1,18 +1,16 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.providers import com.gxf.utilities.spring.oauth.config.condition.OAuthEnabledCondition import com.microsoft.aad.msal4j.ClientCredentialParameters import com.microsoft.aad.msal4j.ConfidentialClientApplication import com.microsoft.aad.msal4j.IAuthenticationResult +import java.util.Optional import org.springframework.context.annotation.Conditional import org.springframework.context.annotation.Primary import org.springframework.stereotype.Service -import java.util.Optional @Service @Primary @@ -23,16 +21,14 @@ class OAuthTokenProvider( ) : TokenProvider { /** - * Retrieve an oauth token from the oauth provider. - * Tokens are cached by the msal4j Library so no caching needed here. + * Retrieve an oauth token from the oauth provider. Tokens are cached by the msal4j Library so no caching needed + * here. */ - override fun getAccessToken(): Optional = - Optional.of(getOAuthToken().accessToken()) + override fun getAccessToken(): Optional = Optional.of(getOAuthToken().accessToken()) /** - * Retrieve an oauth object from the oauth provider. - * Tokens are cached by the msal4j Library so no caching needed here. + * Retrieve an oauth object from the oauth provider. Tokens are cached by the msal4j Library so no caching needed + * here. */ - fun getOAuthToken(): IAuthenticationResult = - confidentialClientApplication.acquireToken(parameters).join() + fun getOAuthToken(): IAuthenticationResult = confidentialClientApplication.acquireToken(parameters).join() } diff --git a/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt b/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt index b01cd1f..db90465 100644 --- a/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt +++ b/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt @@ -1,8 +1,6 @@ -/* -SPDX-FileCopyrightText: Contributors to the GXF project - -SPDX-License-Identifier: Apache-2.0 -*/ +// SPDX-FileCopyrightText: Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config import com.gxf.utilities.spring.oauth.exceptions.OAuthTokenException @@ -11,7 +9,6 @@ import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Test import org.springframework.core.io.ClassPathResource - internal class OAuthClientConfigTest { @Test @@ -24,7 +21,7 @@ internal class OAuthClientConfigTest { @Test fun `should throw exception for non existent private key`() { val client = OAuthClientConfig() - assertThatThrownBy { client.getPrivateKey(ClassPathResource("keys/does-not-exist.key"))} + assertThatThrownBy { client.getPrivateKey(ClassPathResource("keys/does-not-exist.key")) } .isInstanceOf(OAuthTokenException::class.java) .hasMessage("Error getting private key") } @@ -40,9 +37,8 @@ internal class OAuthClientConfigTest { fun `should throw exception for non existent certificate`() { val client = OAuthClientConfig() - assertThatThrownBy { client.getCertificate(ClassPathResource("keys/does-not-exist.key"))} + assertThatThrownBy { client.getCertificate(ClassPathResource("keys/does-not-exist.key")) } .isInstanceOf(OAuthTokenException::class.java) .hasMessage("Error getting certificate") } - } From 1509530af508751bb29eedfa29d98f4afcc4a304 Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Wed, 2 Oct 2024 14:00:15 +0200 Subject: [PATCH 4/8] FDP-2318: declare dependsOn Signed-off-by: Loes Immens --- kafka-avro/build.gradle.kts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kafka-avro/build.gradle.kts b/kafka-avro/build.gradle.kts index 79c96d3..765d325 100644 --- a/kafka-avro/build.gradle.kts +++ b/kafka-avro/build.gradle.kts @@ -1,3 +1,6 @@ +import com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { id("com.github.davidmc24.gradle.plugin.avro") version "1.9.1" } @@ -15,3 +18,9 @@ dependencies { testRuntimeOnly("org.junit.platform:junit-platform-launcher") } + +tasks.withType { + dependsOn( + tasks.withType() + ) +} From 3cffd2c93bbad0a021a8ca72b1ea4b708a904d11 Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Thu, 3 Oct 2024 10:02:49 +0200 Subject: [PATCH 5/8] FDP-2318: fixed copyright text Signed-off-by: Loes Immens --- license-template.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license-template.kt b/license-template.kt index 878d7ea..21caf6f 100644 --- a/license-template.kt +++ b/license-template.kt @@ -1,3 +1,3 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 From 887a5d0cabb11b58b708ef3a28a117b33035fcbd Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Thu, 3 Oct 2024 10:03:35 +0200 Subject: [PATCH 6/8] FDP-2318: fixed copyright text used Signed-off-by: Loes Immens --- .../kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt | 2 +- .../src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt | 2 +- .../main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt | 2 +- .../kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt | 2 +- .../test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt | 2 +- .../kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt | 2 +- .../gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt | 2 +- .../kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt | 2 +- .../kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt | 2 +- .../com/gxf/utilities/kafka/message/signing/MessageSigner.kt | 2 +- .../kafka/message/signing/MessageSigningAutoConfiguration.kt | 2 +- .../utilities/kafka/message/signing/MessageSigningProperties.kt | 2 +- .../kafka/message/signing/UncheckedSecurityException.kt | 2 +- .../utilities/kafka/message/wrapper/SignableMessageWrapper.kt | 2 +- .../gxf/utilities/kafka/message/signing/MessageSignerTest.kt | 2 +- .../message/signing/MessageSigningAutoConfigurationTest.kt | 2 +- .../com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt | 2 +- .../com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt | 2 +- .../com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt | 2 +- .../com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt | 2 +- .../gxf/utilities/spring/oauth/config/OAuthClientProperties.kt | 2 +- .../utilities/spring/oauth/config/condition/OAuthCondition.kt | 2 +- .../spring/oauth/config/condition/OAuthDisabledCondition.kt | 2 +- .../spring/oauth/config/condition/OAuthEnabledCondition.kt | 2 +- .../utilities/spring/oauth/exceptions/OAuthTokenException.kt | 2 +- .../com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt | 2 +- .../gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt | 2 +- .../com/gxf/utilities/spring/oauth/providers/TokenProvider.kt | 2 +- .../gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt | 2 +- 29 files changed, 29 insertions(+), 29 deletions(-) diff --git a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt index 08df5ca..4856f20 100644 --- a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt +++ b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializer.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro diff --git a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt index b1d2590..c3a143b 100644 --- a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt +++ b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroEncoder.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro diff --git a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt index a8da05e..599854b 100644 --- a/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt +++ b/kafka-avro/src/main/kotlin/com/gxf/utilities/kafka/avro/AvroSerializer.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro diff --git a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt index 2443b5f..7f3a2cb 100644 --- a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt +++ b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroDeserializerTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro diff --git a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt index 793ddee..fc025e0 100644 --- a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt +++ b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroEncoderTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro diff --git a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt index b4add06..35b1133 100644 --- a/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt +++ b/kafka-avro/src/test/kotlin/com/gxf/utilities/kafka/avro/AvroSerializerTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.avro diff --git a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt index 37617a6..f47f729 100644 --- a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt +++ b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/KafkaOAuthException.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.oauth.handler diff --git a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt index 8e96afc..a36ee08 100644 --- a/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt +++ b/kafka-azure-oauth/src/main/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandler.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.oauth.handler diff --git a/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt b/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt index c9649a6..71e57f0 100644 --- a/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt +++ b/kafka-azure-oauth/src/test/kotlin/com/gxf/utilities/kafka/oauth/handler/OAuthAuthenticateCallbackHandlerTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.oauth.handler diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt index 80d1efa..590374d 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigner.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.signing diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt index 293ddb6..c61a78a 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfiguration.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.signing diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt index 83d53d8..03b64b0 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningProperties.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.signing diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt index ba518aa..71096c6 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/signing/UncheckedSecurityException.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.signing diff --git a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt index d6d35a3..7033ae7 100644 --- a/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt +++ b/kafka-message-signing/src/main/kotlin/com/gxf/utilities/kafka/message/wrapper/SignableMessageWrapper.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.wrapper diff --git a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt index d9921a8..8027201 100644 --- a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt +++ b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSignerTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.signing diff --git a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt index 52fe3b8..5cfec14 100644 --- a/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt +++ b/kafka-message-signing/src/test/kotlin/com/gxf/utilities/kafka/message/signing/MessageSigningAutoConfigurationTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.kafka.message.signing diff --git a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt index bcbfb1d..a4688aa 100644 --- a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt +++ b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth diff --git a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt index cb272c5..75cf390 100644 --- a/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt +++ b/oauth-token-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt index 4a6f737..781603b 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientContext.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt index e4aab41..3f42b5a 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfig.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt index 7ed20cc..4274062 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientProperties.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt index c0c6b6e..7edc9f2 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config.condition diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt index 4b133f2..dfb08a9 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config.condition diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt index e694919..80e91f2 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config.condition diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt index 9bca94d..c491a70 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/exceptions/OAuthTokenException.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.exceptions diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt index 131901b..0d02244 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.providers diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt index 287e1a3..ddb26f4 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/OAuthTokenProvider.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.providers diff --git a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt index a9638bc..5cfe1af 100644 --- a/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt +++ b/oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.providers diff --git a/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt b/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt index db90465..0aa19c0 100644 --- a/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt +++ b/oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/config/OAuthClientConfigTest.kt @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Contributors to the GXF project +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project // // SPDX-License-Identifier: Apache-2.0 package com.gxf.utilities.spring.oauth.config From 2542201f87eb4625c8c56dfc451e5275a06d67d3 Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Thu, 3 Oct 2024 10:10:24 +0200 Subject: [PATCH 7/8] FDP-2318: added copyright to pre-commit script Signed-off-by: Loes Immens --- scripts/pre-commit | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index d8df2b1..f294e16 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -1,4 +1,8 @@ #!/bin/bash +# SPDX-FileCopyrightText: Copyright Contributors to the GXF project +# +# SPDX-License-Identifier: Apache-2.0 + echo "*********************************************************" echo "Running git pre-commit hook. Running Spotless Apply... " echo "*********************************************************" @@ -18,7 +22,7 @@ if [ "$status" = 0 ] ; then # Add staged file changes to git for file in $stagedFiles; do if test -f "$file"; then - git add $file + git add "$file" fi done #Exit From fcec6d5644ea53a6ad0acd06ac7f62c7e314bb9f Mon Sep 17 00:00:00 2001 From: Loes Immens Date: Thu, 3 Oct 2024 10:12:05 +0200 Subject: [PATCH 8/8] FDP-2318: testing pre-commit with comments Signed-off-by: Loes Immens