35
35
36
36
import org .springframework .boot .context .properties .ConfigurationProperties ;
37
37
import org .springframework .boot .context .properties .PropertyMapper ;
38
+ import org .springframework .boot .context .properties .source .MutuallyExclusiveConfigurationPropertiesException ;
38
39
import org .springframework .boot .convert .DurationUnit ;
39
40
import org .springframework .core .io .Resource ;
40
41
import org .springframework .kafka .listener .ContainerProperties .AckMode ;
@@ -1042,10 +1043,20 @@ public void setMissingTopicsFatal(boolean missingTopicsFatal) {
1042
1043
public static class Ssl {
1043
1044
1044
1045
/**
1045
- * Password of the private key in the key store file.
1046
+ * Password of the private key in either key store key or key store file.
1046
1047
*/
1047
1048
private String keyPassword ;
1048
1049
1050
+ /**
1051
+ * Certificate chain in PEM format with a list of X.509 certificates.
1052
+ */
1053
+ private String keyStoreCertificateChain ;
1054
+
1055
+ /**
1056
+ * Private key in PEM format with PKCS#8 keys.
1057
+ */
1058
+ private String keyStoreKey ;
1059
+
1049
1060
/**
1050
1061
* Location of the key store file.
1051
1062
*/
@@ -1061,6 +1072,11 @@ public static class Ssl {
1061
1072
*/
1062
1073
private String keyStoreType ;
1063
1074
1075
+ /**
1076
+ * Trusted certificates in PEM format with X.509 certificates.
1077
+ */
1078
+ private String trustStoreCertificates ;
1079
+
1064
1080
/**
1065
1081
* Location of the trust store file.
1066
1082
*/
@@ -1089,6 +1105,22 @@ public void setKeyPassword(String keyPassword) {
1089
1105
this .keyPassword = keyPassword ;
1090
1106
}
1091
1107
1108
+ public String getKeyStoreCertificateChain () {
1109
+ return this .keyStoreCertificateChain ;
1110
+ }
1111
+
1112
+ public void setKeyStoreCertificateChain (String keyStoreCertificateChain ) {
1113
+ this .keyStoreCertificateChain = keyStoreCertificateChain ;
1114
+ }
1115
+
1116
+ public String getKeyStoreKey () {
1117
+ return this .keyStoreKey ;
1118
+ }
1119
+
1120
+ public void setKeyStoreKey (String keyStoreKey ) {
1121
+ this .keyStoreKey = keyStoreKey ;
1122
+ }
1123
+
1092
1124
public Resource getKeyStoreLocation () {
1093
1125
return this .keyStoreLocation ;
1094
1126
}
@@ -1113,6 +1145,14 @@ public void setKeyStoreType(String keyStoreType) {
1113
1145
this .keyStoreType = keyStoreType ;
1114
1146
}
1115
1147
1148
+ public String getTrustStoreCertificates () {
1149
+ return this .trustStoreCertificates ;
1150
+ }
1151
+
1152
+ public void setTrustStoreCertificates (String trustStoreCertificates ) {
1153
+ this .trustStoreCertificates = trustStoreCertificates ;
1154
+ }
1155
+
1116
1156
public Resource getTrustStoreLocation () {
1117
1157
return this .trustStoreLocation ;
1118
1158
}
@@ -1146,13 +1186,25 @@ public void setProtocol(String protocol) {
1146
1186
}
1147
1187
1148
1188
public Map <String , Object > buildProperties () {
1189
+ MutuallyExclusiveConfigurationPropertiesException .throwIfMultipleNonNullValuesIn ((entries ) -> {
1190
+ entries .put ("spring.kafka.ssl.key-store-key" , this .getKeyStoreKey ());
1191
+ entries .put ("spring.kafka.ssl.key-store-location" , this .getKeyStoreLocation ());
1192
+ });
1193
+ MutuallyExclusiveConfigurationPropertiesException .throwIfMultipleNonNullValuesIn ((entries ) -> {
1194
+ entries .put ("spring.kafka.ssl.trust-store-certificates" , this .getTrustStoreCertificates ());
1195
+ entries .put ("spring.kafka.ssl.trust-store-location" , this .getTrustStoreLocation ());
1196
+ });
1149
1197
Properties properties = new Properties ();
1150
1198
PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
1151
1199
map .from (this ::getKeyPassword ).to (properties .in (SslConfigs .SSL_KEY_PASSWORD_CONFIG ));
1200
+ map .from (this ::getKeyStoreCertificateChain )
1201
+ .to (properties .in (SslConfigs .SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG ));
1202
+ map .from (this ::getKeyStoreKey ).to (properties .in (SslConfigs .SSL_KEYSTORE_KEY_CONFIG ));
1152
1203
map .from (this ::getKeyStoreLocation ).as (this ::resourceToPath )
1153
1204
.to (properties .in (SslConfigs .SSL_KEYSTORE_LOCATION_CONFIG ));
1154
1205
map .from (this ::getKeyStorePassword ).to (properties .in (SslConfigs .SSL_KEYSTORE_PASSWORD_CONFIG ));
1155
1206
map .from (this ::getKeyStoreType ).to (properties .in (SslConfigs .SSL_KEYSTORE_TYPE_CONFIG ));
1207
+ map .from (this ::getTrustStoreCertificates ).to (properties .in (SslConfigs .SSL_TRUSTSTORE_CERTIFICATES_CONFIG ));
1156
1208
map .from (this ::getTrustStoreLocation ).as (this ::resourceToPath )
1157
1209
.to (properties .in (SslConfigs .SSL_TRUSTSTORE_LOCATION_CONFIG ));
1158
1210
map .from (this ::getTrustStorePassword ).to (properties .in (SslConfigs .SSL_TRUSTSTORE_PASSWORD_CONFIG ));
0 commit comments