1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.email; |
12 | |
|
13 | |
import org.mule.api.lifecycle.CreateException; |
14 | |
import org.mule.api.lifecycle.InitialisationException; |
15 | |
import org.mule.api.security.TlsIndirectKeyStore; |
16 | |
import org.mule.api.security.TlsIndirectTrustStore; |
17 | |
import org.mule.api.security.tls.TlsConfiguration; |
18 | |
import org.mule.api.security.tls.TlsPropertiesMapper; |
19 | |
|
20 | |
import java.io.IOException; |
21 | |
import java.util.Properties; |
22 | |
|
23 | |
import javax.mail.URLName; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public abstract class AbstractTlsRetrieveMailConnector |
30 | |
extends AbstractRetrieveMailConnector implements TlsIndirectTrustStore, TlsIndirectKeyStore |
31 | |
{ |
32 | |
|
33 | |
private String namespace; |
34 | |
private String socketFactory; |
35 | 56 | private String socketFactoryFallback = "false"; |
36 | 56 | private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE); |
37 | |
|
38 | |
protected AbstractTlsRetrieveMailConnector(int defaultPort, String namespace, Class defaultSocketFactory) |
39 | |
{ |
40 | 56 | super(defaultPort); |
41 | 56 | this.namespace = namespace; |
42 | 56 | socketFactory = defaultSocketFactory.getName(); |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 56 | } |
48 | |
|
49 | |
protected void doInitialise() throws InitialisationException |
50 | |
{ |
51 | |
try |
52 | |
{ |
53 | 56 | tls.initialise(true, null); |
54 | |
} |
55 | 0 | catch (CreateException e) |
56 | |
{ |
57 | 0 | throw new InitialisationException(e, this); |
58 | 56 | } |
59 | 56 | super.doInitialise(); |
60 | 56 | } |
61 | |
|
62 | |
|
63 | |
protected void extendPropertiesForSession(Properties global, Properties local, URLName url) |
64 | |
{ |
65 | 8 | super.extendPropertiesForSession(global, local, url); |
66 | |
|
67 | 8 | local.setProperty("mail." + getProtocol() + ".ssl", "true"); |
68 | 8 | local.setProperty("mail." + getProtocol() + ".socketFactory.class", getSocketFactory()); |
69 | 8 | local.setProperty("mail." + getProtocol() + ".socketFactory.fallback", getSocketFactoryFallback()); |
70 | |
|
71 | 8 | new TlsPropertiesMapper(namespace).writeToProperties(global, tls); |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | 8 | } |
78 | |
|
79 | |
public String getSocketFactory() |
80 | |
{ |
81 | 8 | return socketFactory; |
82 | |
} |
83 | |
|
84 | |
public void setSocketFactory(String sslSocketFactory) |
85 | |
{ |
86 | 0 | this.socketFactory = sslSocketFactory; |
87 | 0 | } |
88 | |
|
89 | |
public String getSocketFactoryFallback() |
90 | |
{ |
91 | 8 | return socketFactoryFallback; |
92 | |
} |
93 | |
|
94 | |
public void setSocketFactoryFallback(String socketFactoryFallback) |
95 | |
{ |
96 | 0 | this.socketFactoryFallback = socketFactoryFallback; |
97 | 0 | } |
98 | |
|
99 | |
public String getTrustStore() |
100 | |
{ |
101 | 4 | return tls.getTrustStore(); |
102 | |
} |
103 | |
|
104 | |
public String getTrustStorePassword() |
105 | |
{ |
106 | 4 | return tls.getTrustStorePassword(); |
107 | |
} |
108 | |
|
109 | |
public void setTrustStore(String trustStore) throws IOException |
110 | |
{ |
111 | 56 | tls.setTrustStore(trustStore); |
112 | 56 | } |
113 | |
|
114 | |
public void setTrustStorePassword(String trustStorePassword) |
115 | |
{ |
116 | 56 | tls.setTrustStorePassword(trustStorePassword); |
117 | 56 | } |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public String getClientKeyStore() |
123 | |
{ |
124 | 4 | return this.tls.getClientKeyStore(); |
125 | |
} |
126 | |
|
127 | |
public String getClientKeyStorePassword() |
128 | |
{ |
129 | 4 | return this.tls.getClientKeyStorePassword(); |
130 | |
} |
131 | |
|
132 | |
public String getClientKeyStoreType() |
133 | |
{ |
134 | 0 | return this.tls.getClientKeyStoreType(); |
135 | |
} |
136 | |
|
137 | |
public void setClientKeyStore(String name) throws IOException |
138 | |
{ |
139 | 16 | this.tls.setClientKeyStore(name); |
140 | 16 | } |
141 | |
|
142 | |
public void setClientKeyStorePassword(String clientKeyStorePassword) |
143 | |
{ |
144 | 16 | this.tls.setClientKeyStorePassword(clientKeyStorePassword); |
145 | 16 | } |
146 | |
|
147 | |
public void setClientKeyStoreType(String clientKeyStoreType) |
148 | |
{ |
149 | 0 | this.tls.setClientKeyStoreType(clientKeyStoreType); |
150 | 0 | } |
151 | |
|
152 | |
} |