Class KafkaSecurityConfiguration
java.lang.Object
com.reallifedeveloper.common.infrastructure.messaging.KafkaSecurityConfiguration
Utility class used to set the security-related Kafka configuration properties when creating consumers and producers.
In particular, it allows reading the truststore from a classpath resource using a classpath:
prefix.
- Author:
- RealLifeDeveloper
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The configuration property to use to set the JAAS config.static final String
The configuration property to use to set the SASL mechanism, e.g.,PLAIN
.static final String
The configuration property to use to set security protocol, e.g.,SASL_SSL
.static final String
The configuration property to use to set the location of the truststore, supportsclasspath
prefixes.static final String
The configuration property to use to set the password of the truststore. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
SECURITY_PROTOCOL_CONFIGURATION_KEY
The configuration property to use to set security protocol, e.g.,SASL_SSL
.- See Also:
-
SSL_TRUSTSTORE_LOCATION_CONFIGURATION_KEY
The configuration property to use to set the location of the truststore, supportsclasspath
prefixes.- See Also:
-
SSL_TRUSTSTORE_PASSWORD_CONFIGURATION_KEY
The configuration property to use to set the password of the truststore.- See Also:
-
SASL_MECHNISM_CONFIGURATION_KEY
The configuration property to use to set the SASL mechanism, e.g.,PLAIN
.- See Also:
-
SASL_JAAS_CONFIG_CONFIGURATION_KEY
The configuration property to use to set the JAAS config.- See Also:
-
-
Constructor Details
-
KafkaSecurityConfiguration
public KafkaSecurityConfiguration()
-
-
Method Details
-
applySecurityConfiguration
public static void applySecurityConfiguration(String configurationKey, String configurationValue, Map<String, Object> configurationProperties) throws IOExceptionSets the value of a configuration property.A value can be set only once for a particular property; trying to reset a value causes an exception to be thrown.
There is special handling of the "ssl.truststore.location" configuration property, with support for reading a trust store from the classpath if the configuration value starts with
classpath:
.In the case that the "ssl.truststore.location" value starts with
classpath:
, the trust store is read as a resource using the current thread's context classloader. The store is copied to a temporary file, and the path of the file is used as the value to set.- Parameters:
configurationKey
- the configuration key to applyconfigurationValue
- the configuration valueconfigurationProperties
- the currently set configuration properties- Throws:
IllegalStateException
- if trying to reset a valueIOException
- if reading the trust store from classpath fails
-