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