Skip to content

Commit

Permalink
Updated pre-java-17 branch to latest dependencies and code (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
erkdahl authored Oct 11, 2023
1 parent c298de0 commit af568b4
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 26 deletions.
2 changes: 0 additions & 2 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ import no.digdir.logging.event.ActivityRecord;
.setCorrelationId(UUID.randomUUID().toString())
.setServiceProviderId("idPorten-123")
.setServiceProviderOrgno("123123123")
.setServiceProviderName("Provider AS")
.setServiceOwnerId("idPorten-123")
.setServiceOwnerOrgno("123123123")
.setServiceOwnerName("Owner Inc.")
.build();
eventLogger.log(record);
```
Expand Down Expand Up @@ -125,8 +127,10 @@ Currently we support three different types of records: ActivityRecord, MPAuthent
.setCorrelationId(UUID.randomUUID().toString())
.setServiceProviderId("idPorten-123")
.setServiceProviderOrgno("123123123")
.setServiceProviderName("Provider AS")
.setServiceOwnerId("idPorten-123")
.setServiceOwnerOrgno("123123123")
.setServiceOwnerName("Owner Inc.")
.build();

eventLogger.log(record);
Expand Down
5 changes: 5 additions & 0 deletions log-event-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
25 changes: 25 additions & 0 deletions log-event/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<exclusions>
<exclusion>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
Expand All @@ -40,6 +46,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -68,6 +75,12 @@
<version>${kafka.version}</version>
<classifier>test</classifier>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
Expand All @@ -90,6 +103,18 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <!-- CVE-2023-34455 -->
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>${snappy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
18 changes: 18 additions & 0 deletions log-event/src/main/avro/activity.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
"default": null,
"doc": "The org.no of the service targeted/requested by the event"
},
{
"name": "service_provider_name",
"type": [
"null",
"string"
],
"default": null,
"doc": "The humanly readable name of the service targeted/requested by the event"
},
{
"name": "service_owner_id",
"type": [
Expand All @@ -108,6 +117,15 @@
"default": null,
"doc": "The org.no of the owner of the provided service"
},
{
"name": "service_owner_name",
"type": [
"null",
"string"
],
"default": null,
"doc": "The humanly readable name of the owner of the provided service"
},
{
"name": "auth_eid",
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public class ActivityRecord extends EventRecordBase {
private final String eventSubjectPid;
private final String serviceProviderId;
private final String serviceProviderOrgno;
private final String serviceProviderName;
private final String serviceOwnerId;
private final String serviceOwnerOrgno;
private final String serviceOwnerName;
private final String authEid;
private final String authMethod;

Expand All @@ -31,8 +33,10 @@ public ActivityRecord(
String eventSubjectPid,
String serviceProviderId,
String serviceProviderOrgno,
String serviceProviderName,
String serviceOwnerId,
String serviceOwnerOrgno,
String serviceOwnerName,
String authEid,
String authMethod,
Instant eventCreated) {
Expand All @@ -41,8 +45,10 @@ public ActivityRecord(
this.eventSubjectPid = eventSubjectPid;
this.serviceProviderId = serviceProviderId;
this.serviceProviderOrgno = serviceProviderOrgno;
this.serviceProviderName = serviceProviderName;
this.serviceOwnerId = serviceOwnerId;
this.serviceOwnerOrgno = serviceOwnerOrgno;
this.serviceOwnerName = serviceOwnerName;
this.authEid = authEid;
this.authMethod = authMethod;
}
Expand All @@ -64,8 +70,10 @@ protected SpecificRecordBase toAvroObject() {
.setEventSubjectPid(eventSubjectPid)
.setServiceProviderId(serviceProviderId)
.setServiceProviderOrgno(serviceProviderOrgno)
.setServiceProviderName(serviceProviderName)
.setServiceOwnerId(serviceOwnerId)
.setServiceOwnerOrgno(serviceOwnerOrgno)
.setServiceOwnerName(serviceOwnerName)
.setAuthEid(authEid)
.setAuthMethod(authMethod)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
e.execute(r);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.config.SaslConfigs;
import org.apache.kafka.common.security.auth.SecurityProtocol;

import java.io.InputStream;
import java.net.URL;
Expand All @@ -31,7 +32,6 @@ public class EventLoggingConfig {
static final String MP_TOKEN_RECORD_TOPIC_KEY = "maskinporten-token-record.topic";
static final String THREAD_POOL_SIZE_KEY = "thread.pool.size";
static final String THREAD_POOL_QUEUE_SIZE_KEY = "thread.pool.queue.size";

private static final String PRODUCER_PROPERTIES_FILE_PATH = "kafka-producer.properties";
private static final String EVENT_LOGGER_PROPERTIES_FILE_PATH = "event-logger.properties";
private static final String JAAS_CONFIG_TEMPLATE = "org.apache.kafka.common.security.scram.ScramLoginModule " +
Expand Down Expand Up @@ -186,12 +186,36 @@ private static String resolveProperty(String key, String userSpecifiedValue, Pro
}
}


/**
* https://github.com/felleslosninger/eid-log-event/issues/174
*
* @param bootstrapServers URL to Kafka
* @param configured value
* @return SASL mechanism appropriate for external or internal URL
*/
static String resolveSaslMechanism(String bootstrapServers, String configured) {
if (bootstrapServers.contains("local")) {
if (!SecurityProtocol.SASL_PLAINTEXT.name().equals(configured)) {
log.info(
"{} overridden with value {}",
SaslConfigs.SASL_MECHANISM, SecurityProtocol.SASL_PLAINTEXT.name());
}
return SecurityProtocol.SASL_PLAINTEXT.name();
} else {
return configured;
}
}

private Map<String, Object> createProducerConfig() {
Properties kafkaProducerProperties = loadPropertiesFromFile(PRODUCER_PROPERTIES_FILE_PATH);
kafkaProducerProperties =
overrideWithOptionalConfig(kafkaProducerProperties, CUSTOM_PRODUCER_PROPERTIES_FILE_PATH);
Map<String, Object> producerConfig = new HashMap<>(propertiesToMap(kafkaProducerProperties));
producerConfig.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
producerConfig.put(SaslConfigs.SASL_MECHANISM, resolveSaslMechanism(
bootstrapServers,
kafkaProducerProperties.getProperty(SaslConfigs.SASL_MECHANISM)));
producerConfig.put(KafkaAvroSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl);
if (!Strings.isNullOrEmpty((schemaRegistryUsername))) {
producerConfig.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ public void run() {
ProducerRecord<String, SpecificRecordBase> getProducerRecord() {
return producerRecord;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ void toAvroObject() {
.correlationId("correlationId")
.serviceOwnerId("serviceOwnerId")
.serviceOwnerOrgno("serviceOwnerOrgno")
.serviceOwnerName("serviceOwnerName")
.serviceProviderId("serviceProviderId")
.serviceProviderOrgno("serviceProviderOrgno")
.serviceProviderName("serviceProviderName")
.extraData(Collections.singletonMap("key", "value"))
.eventCreated(Instant.now().minus(Duration.ofSeconds(60)))
.build();
Expand All @@ -142,9 +144,11 @@ void toAvroObject() {
assertEquals(record.getAuthEid(), avroRecord.getAuthEid());
assertEquals(record.getAuthMethod(), avroRecord.getAuthMethod());
assertEquals(record.getServiceOwnerOrgno(), avroRecord.getServiceOwnerOrgno());
assertEquals(record.getServiceOwnerName(), avroRecord.getServiceOwnerName());
assertEquals(record.getServiceOwnerId(), avroRecord.getServiceOwnerId());
assertEquals(record.getServiceProviderId(), avroRecord.getServiceProviderId());
assertEquals(record.getServiceProviderOrgno(), avroRecord.getServiceProviderOrgno());
assertEquals(record.getServiceProviderName(), avroRecord.getServiceProviderName());
assertEquals(record.getEventSubjectPid(), avroRecord.getEventSubjectPid());
assertEquals(record.getCorrelationId(), avroRecord.getCorrelationId());
assertEquals(record.getExtraData(), avroRecord.getExtraData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,6 @@ void queueStats() {
void metrics() {
assertNotNull(eventLogger.getMetrics(), "The eventLoggers metrics should be reachable and available.");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -218,34 +218,34 @@ void threadPoolSize() {
}

@Test
void threadPoolSizeDefault() {
void threadPoolQueueSize() {
EventLoggingConfig config = EventLoggingConfig.builder()
.applicationName("testApplicationName")
.environmentName("unit")
.bootstrapServers("abc")
.schemaRegistryUrl("abc")
.kafkaUsername("abc")
.featureEnabled(true)
.threadPoolQueueSize(200)
.build();
assertEquals(4, config.getThreadPoolSize(), "ThreadPoolSize default should be 4");
assertEquals(200, config.getThreadPoolQueueSize(), "ThreadPoolQueueSize should be equal to builder input");
}

@Test
void threadPoolQueueSize() {
void threadPoolQueueSizeDefault() {
EventLoggingConfig config = EventLoggingConfig.builder()
.applicationName("testApplicationName")
.environmentName("unit")
.bootstrapServers("abc")
.schemaRegistryUrl("abc")
.kafkaUsername("abc")
.featureEnabled(true)
.threadPoolQueueSize(200)
.build();
assertEquals(200, config.getThreadPoolQueueSize(), "ThreadPoolQueueSize should be equal to builder input");
assertEquals(30000, config.getThreadPoolQueueSize(), "ThreadPoolQueueSize default should be 100000");
}

@Test
void threadPoolQueueSizeDefault() {
void threadPoolSizeDefault() {
EventLoggingConfig config = EventLoggingConfig.builder()
.applicationName("testApplicationName")
.environmentName("unit")
Expand All @@ -254,7 +254,7 @@ void threadPoolQueueSizeDefault() {
.kafkaUsername("abc")
.featureEnabled(true)
.build();
assertEquals(30000, config.getThreadPoolQueueSize(), "ThreadPoolQueueSize default should be 100000");
assertEquals(4, config.getThreadPoolSize(), "ThreadPoolSize default should be 4");
}

@Test
Expand Down Expand Up @@ -326,4 +326,12 @@ void overrideWithOptionalConfig() {

assertEquals("32601", eventLoggingConfig.getProducerConfig().get("batch.size"));
}

@Test
void resolveSaslMechanism() {
String localUrl = "strimzi-kafka-kafka-bootstrap.event-statistikk.svc.cluster.local:9092";
String externalUrl = "kafka.systest.eid-event-stat.no:443";
assertEquals("SASL_PLAINTEXT", EventLoggingConfig.resolveSaslMechanism(localUrl, "SASL_SSL"));
assertEquals("SASL_SSL", EventLoggingConfig.resolveSaslMechanism(externalUrl, "SASL_SSL"));
}
}
32 changes: 18 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@
<java.version>1.8</java.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kafka.version>3.3.1</kafka.version>
<confluent.version>7.3.1</confluent.version>
<kafka.version>3.4.0</kafka.version>
<confluent.version>7.5.1</confluent.version>
<kafka.scala.version>2.13</kafka.scala.version>
<curator.version>5.4.0</curator.version>
<jackson.version>2.14.1</jackson.version>
<lombok.version>1.18.24</lombok.version>
<avro.version>1.11.1</avro.version>
<junit.version>5.9.1</junit.version>
<mockito.version>4.11.0</mockito.version>
<log4j2.version>2.19.0</log4j2.version>
<slf4j.version>2.0.6</slf4j.version>
<curator.version>5.5.0</curator.version>
<jackson.version>2.15.2</jackson.version>
<lombok.version>1.18.30</lombok.version>
<avro.version>1.11.3</avro.version>
<junit.version>5.10.0</junit.version>
<mockito.version>5.6.0</mockito.version>
<log4j2.version>2.20.0</log4j2.version>
<slf4j.version>2.0.9</slf4j.version>
<archunit.version>0.23.1</archunit.version>
<spring.boot.version>2.7.5</spring.boot.version>
<spring.boot.version>2.7.16</spring.boot.version>
<snappy.version>1.1.10.5</snappy.version> <!-- CVE-2023-34455 -->
</properties>

<dependencyManagement>
Expand All @@ -66,6 +67,7 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down Expand Up @@ -132,9 +134,11 @@
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down

0 comments on commit af568b4

Please sign in to comment.