@@ -19,8 +19,10 @@ Reliable Event Logging Protocol (RELP) Logback plugin
1919
2020import java .io .IOException ;
2121import java .nio .charset .StandardCharsets ;
22+ import java .security .GeneralSecurityException ;
2223import java .util .UUID ;
2324import java .util .concurrent .TimeoutException ;
25+ import java .util .function .Supplier ;
2426
2527import ch .qos .logback .classic .spi .ILoggingEvent ;
2628import ch .qos .logback .core .encoder .LayoutWrappingEncoder ;
@@ -30,6 +32,10 @@ Reliable Event Logging Protocol (RELP) Logback plugin
3032import com .teragrep .rlp_01 .RelpBatch ;
3133import ch .qos .logback .core .AppenderBase ;
3234import com .teragrep .rlp_01 .RelpConnection ;
35+ import com .teragrep .rlp_01 .SSLContextFactory ;
36+
37+ import javax .net .ssl .SSLContext ;
38+ import javax .net .ssl .SSLEngine ;
3339
3440public class RlpLogbackAppender <E > extends AppenderBase <E > {
3541
@@ -59,6 +65,13 @@ public class RlpLogbackAppender<E> extends AppenderBase<E> {
5965 private long reconnectIfNoMessagesInterval = 150000 ;
6066 private long lastMessageSent = 0 ;
6167
68+ // tls
69+ private boolean useTLS = false ;
70+ private String keystorePath = "" ;
71+ private String keystorePassword = "" ;
72+ private String tlsProtocol = "" ;
73+
74+
6275 public void setEncoder (LayoutWrappingEncoder encoder ) {
6376 this .encoder = encoder ;
6477 }
@@ -121,6 +134,23 @@ public void setReconnectIfNoMessagesInterval(int interval) {
121134 this .reconnectIfNoMessagesInterval = interval ;
122135 }
123136
137+ // tls
138+ public void setUseTLS (boolean on ) {
139+ this .useTLS = on ;
140+ }
141+
142+ public void setKeystorePath (String keystorePath ) {
143+ this .keystorePath = keystorePath ;
144+ }
145+
146+ public void setKeystorePassword (String keystorePassword ) {
147+ this .keystorePassword = keystorePassword ;
148+ }
149+
150+ public void setTlsProtocol (String tlsProtocol ) {
151+ this .tlsProtocol = tlsProtocol ;
152+ }
153+
124154 private void connect () {
125155 if (System .getenv ("JLA01_DEBUG" ) != null ) {
126156 System .out .println ("RlpLogbackAppender.connect>" );
@@ -178,7 +208,29 @@ public void start() {
178208 return ;
179209
180210 // initialize events sender
181- this .sender = new RelpConnection ();
211+ if (useTLS ) {
212+ Supplier <SSLEngine > sslEngineSupplier = new Supplier <SSLEngine >() {
213+ private final SSLContext sslContext ;
214+ {
215+ try {
216+ sslContext = SSLContextFactory .authenticatedContext (keystorePath , keystorePassword , tlsProtocol );
217+ } catch (GeneralSecurityException | IOException e ) {
218+ throw new RuntimeException (e );
219+ }
220+ }
221+
222+ @ Override
223+ public SSLEngine get () {
224+ return sslContext .createSSLEngine ();
225+ }
226+ };
227+
228+ this .sender = new RelpConnection (sslEngineSupplier );
229+ }
230+ else {
231+ this .sender = new RelpConnection ();
232+ }
233+
182234
183235 this .sender .setConnectionTimeout (connectionTimeout );
184236 this .sender .setReadTimeout (this .readTimeout );
0 commit comments