1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.net;
15
16 import javax.net.SocketFactory;
17 import javax.net.ssl.SSLContext;
18
19 import ch.qos.logback.core.net.ssl.ConfigurableSSLSocketFactory;
20 import ch.qos.logback.core.net.ssl.SSLComponent;
21 import ch.qos.logback.core.net.ssl.SSLConfiguration;
22 import ch.qos.logback.core.net.ssl.SSLParametersConfiguration;
23
24
25
26
27
28
29
30 public abstract class AbstractSSLSocketAppender<E> extends AbstractSocketAppender<E> implements SSLComponent {
31
32 private SSLConfiguration ssl;
33 private SocketFactory socketFactory;
34
35
36
37
38 protected AbstractSSLSocketAppender() {
39 }
40
41
42
43
44
45
46
47 @Override
48 protected SocketFactory getSocketFactory() {
49 return socketFactory;
50 }
51
52
53
54
55 @Override
56 public void start() {
57 try {
58 SSLContext sslContext = getSsl().createContext(this);
59 SSLParametersConfiguration parameters = getSsl().getParameters();
60 parameters.setContext(getContext());
61 socketFactory = new ConfigurableSSLSocketFactory(parameters, sslContext.getSocketFactory());
62 super.start();
63 } catch (Exception ex) {
64 addError(ex.getMessage(), ex);
65 }
66 }
67
68
69
70
71
72
73
74 public SSLConfiguration getSsl() {
75 if (ssl == null) {
76 ssl = new SSLConfiguration();
77 }
78 return ssl;
79 }
80
81
82
83
84
85
86 public void setSsl(SSLConfiguration ssl) {
87 this.ssl = ssl;
88 }
89
90 }