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