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