1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.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 public class SSLSocketReceiver extends SocketReceiver implements SSLComponent {
30
31 private SSLConfiguration ssl;
32 private SocketFactory socketFactory;
33
34
35
36
37
38
39
40 @Override
41 protected SocketFactory getSocketFactory() {
42 return socketFactory;
43 }
44
45
46
47
48 @Override
49 protected boolean shouldStart() {
50 try {
51 SSLContext sslContext = getSsl().createContext(this);
52 SSLParametersConfiguration parameters = getSsl().getParameters();
53 parameters.setContext(getContext());
54 socketFactory = new ConfigurableSSLSocketFactory(parameters, sslContext.getSocketFactory());
55 return super.shouldStart();
56 } catch (Exception ex) {
57 addError(ex.getMessage(), ex);
58 return false;
59 }
60 }
61
62
63
64
65
66
67
68 public SSLConfiguration getSsl() {
69 if (ssl == null) {
70 ssl = new SSLConfiguration();
71 }
72 return ssl;
73 }
74
75
76
77
78
79
80 public void setSsl(SSLConfiguration ssl) {
81 this.ssl = ssl;
82 }
83
84 }