11/*
2- * Copyright 2012-2019 the original author or authors.
2+ * Copyright 2012-2020 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -91,6 +91,8 @@ public class KafkaProperties {
9191
9292 private final Template template = new Template ();
9393
94+ private final Security security = new Security ();
95+
9496 public List <String > getBootstrapServers () {
9597 return this .bootstrapServers ;
9698 }
@@ -143,6 +145,10 @@ public Template getTemplate() {
143145 return this .template ;
144146 }
145147
148+ public Security getSecurity () {
149+ return this .security ;
150+ }
151+
146152 private Map <String , Object > buildCommonProperties () {
147153 Map <String , Object > properties = new HashMap <>();
148154 if (this .bootstrapServers != null ) {
@@ -152,6 +158,7 @@ private Map<String, Object> buildCommonProperties() {
152158 properties .put (CommonClientConfigs .CLIENT_ID_CONFIG , this .clientId );
153159 }
154160 properties .putAll (this .ssl .buildProperties ());
161+ properties .putAll (this .security .buildProperties ());
155162 if (!CollectionUtils .isEmpty (this .properties )) {
156163 properties .putAll (this .properties );
157164 }
@@ -217,6 +224,8 @@ public static class Consumer {
217224
218225 private final Ssl ssl = new Ssl ();
219226
227+ private final Security security = new Security ();
228+
220229 /**
221230 * Frequency with which the consumer offsets are auto-committed to Kafka if
222231 * 'enable.auto.commit' is set to true.
@@ -297,6 +306,10 @@ public Ssl getSsl() {
297306 return this .ssl ;
298307 }
299308
309+ public Security getSecurity () {
310+ return this .security ;
311+ }
312+
300313 public Duration getAutoCommitInterval () {
301314 return this .autoCommitInterval ;
302315 }
@@ -426,7 +439,7 @@ public Map<String, Object> buildProperties() {
426439 map .from (this ::getKeyDeserializer ).to (properties .in (ConsumerConfig .KEY_DESERIALIZER_CLASS_CONFIG ));
427440 map .from (this ::getValueDeserializer ).to (properties .in (ConsumerConfig .VALUE_DESERIALIZER_CLASS_CONFIG ));
428441 map .from (this ::getMaxPollRecords ).to (properties .in (ConsumerConfig .MAX_POLL_RECORDS_CONFIG ));
429- return properties .with (this .ssl , this .properties );
442+ return properties .with (this .ssl , this .security , this . properties );
430443 }
431444
432445 }
@@ -435,6 +448,8 @@ public static class Producer {
435448
436449 private final Ssl ssl = new Ssl ();
437450
451+ private final Security security = new Security ();
452+
438453 /**
439454 * Number of acknowledgments the producer requires the leader to have received
440455 * before considering a request complete.
@@ -498,6 +513,10 @@ public Ssl getSsl() {
498513 return this .ssl ;
499514 }
500515
516+ public Security getSecurity () {
517+ return this .security ;
518+ }
519+
501520 public String getAcks () {
502521 return this .acks ;
503522 }
@@ -595,7 +614,7 @@ public Map<String, Object> buildProperties() {
595614 map .from (this ::getKeySerializer ).to (properties .in (ProducerConfig .KEY_SERIALIZER_CLASS_CONFIG ));
596615 map .from (this ::getRetries ).to (properties .in (ProducerConfig .RETRIES_CONFIG ));
597616 map .from (this ::getValueSerializer ).to (properties .in (ProducerConfig .VALUE_SERIALIZER_CLASS_CONFIG ));
598- return properties .with (this .ssl , this .properties );
617+ return properties .with (this .ssl , this .security , this . properties );
599618 }
600619
601620 }
@@ -604,6 +623,8 @@ public static class Admin {
604623
605624 private final Ssl ssl = new Ssl ();
606625
626+ private final Security security = new Security ();
627+
607628 /**
608629 * ID to pass to the server when making requests. Used for server-side logging.
609630 */
@@ -623,6 +644,10 @@ public Ssl getSsl() {
623644 return this .ssl ;
624645 }
625646
647+ public Security getSecurity () {
648+ return this .security ;
649+ }
650+
626651 public String getClientId () {
627652 return this .clientId ;
628653 }
@@ -647,7 +672,7 @@ public Map<String, Object> buildProperties() {
647672 Properties properties = new Properties ();
648673 PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
649674 map .from (this ::getClientId ).to (properties .in (ProducerConfig .CLIENT_ID_CONFIG ));
650- return properties .with (this .ssl , this .properties );
675+ return properties .with (this .ssl , this .security , this . properties );
651676 }
652677
653678 }
@@ -659,6 +684,8 @@ public static class Streams {
659684
660685 private final Ssl ssl = new Ssl ();
661686
687+ private final Security security = new Security ();
688+
662689 /**
663690 * Kafka streams application.id property; default spring.application.name.
664691 */
@@ -705,6 +732,10 @@ public Ssl getSsl() {
705732 return this .ssl ;
706733 }
707734
735+ public Security getSecurity () {
736+ return this .security ;
737+ }
738+
708739 public String getApplicationId () {
709740 return this .applicationId ;
710741 }
@@ -775,7 +806,7 @@ public Map<String, Object> buildProperties() {
775806 map .from (this ::getClientId ).to (properties .in (CommonClientConfigs .CLIENT_ID_CONFIG ));
776807 map .from (this ::getReplicationFactor ).to (properties .in ("replication.factor" ));
777808 map .from (this ::getStateDir ).to (properties .in ("state.dir" ));
778- return properties .with (this .ssl , this .properties );
809+ return properties .with (this .ssl , this .security , this . properties );
779810 }
780811
781812 }
@@ -1167,15 +1198,40 @@ public void setOptions(Map<String, String> options) {
11671198
11681199 }
11691200
1201+ public static class Security {
1202+
1203+ /**
1204+ * Security protocol used to communicate with brokers.
1205+ */
1206+ private String protocol ;
1207+
1208+ public String getProtocol () {
1209+ return this .protocol ;
1210+ }
1211+
1212+ public void setProtocol (String protocol ) {
1213+ this .protocol = protocol ;
1214+ }
1215+
1216+ public Map <String , Object > buildProperties () {
1217+ Properties properties = new Properties ();
1218+ PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
1219+ map .from (this ::getProtocol ).to (properties .in (CommonClientConfigs .SECURITY_PROTOCOL_CONFIG ));
1220+ return properties ;
1221+ }
1222+
1223+ }
1224+
11701225 @ SuppressWarnings ("serial" )
11711226 private static class Properties extends HashMap <String , Object > {
11721227
11731228 <V > java .util .function .Consumer <V > in (String key ) {
11741229 return (value ) -> put (key , value );
11751230 }
11761231
1177- Properties with (Ssl ssl , Map <String , String > properties ) {
1232+ Properties with (Ssl ssl , Security security , Map <String , String > properties ) {
11781233 putAll (ssl .buildProperties ());
1234+ putAll (security .buildProperties ());
11791235 putAll (properties );
11801236 return this ;
11811237 }
0 commit comments