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 | |
public class SmtpsConnector extends SmtpConnector implements TlsIndirectTrustStore, TlsIndirectKeyStore |
24 | |
{ |
25 | |
|
26 | |
public static final String SMTPS = "smtps"; |
27 | 0 | public static final String DEFAULT_SOCKET_FACTORY = SmtpsSocketFactory.class.getName(); |
28 | |
|
29 | 0 | private String socketFactory = DEFAULT_SOCKET_FACTORY; |
30 | 0 | private String socketFactoryFallback = "false"; |
31 | 0 | private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE); |
32 | |
|
33 | |
public static final int DEFAULT_SMTPS_PORT = 465; |
34 | |
|
35 | |
|
36 | |
public SmtpsConnector(MuleContext context) |
37 | |
{ |
38 | 0 | super(DEFAULT_SMTPS_PORT, context); |
39 | 0 | } |
40 | |
|
41 | |
public String getProtocol() |
42 | |
{ |
43 | 0 | return "smtps"; |
44 | |
} |
45 | |
|
46 | |
public String getBaseProtocol() |
47 | |
{ |
48 | 0 | return "smtp"; |
49 | |
} |
50 | |
|
51 | |
protected void doInitialise() throws InitialisationException |
52 | |
{ |
53 | |
try |
54 | |
{ |
55 | 0 | tls.initialise(true, null); |
56 | |
} |
57 | 0 | catch (CreateException e) |
58 | |
{ |
59 | 0 | throw new InitialisationException(e, this); |
60 | 0 | } |
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(SmtpsSocketFactory.MULE_SMTPS_NAMESPACE).writeToProperties(global, tls); |
73 | 0 | } |
74 | |
|
75 | |
public String getSocketFactory() |
76 | |
{ |
77 | 0 | return socketFactory; |
78 | |
} |
79 | |
|
80 | |
public void setSocketFactory(String sslSocketFactory) |
81 | |
{ |
82 | 0 | this.socketFactory = sslSocketFactory; |
83 | 0 | } |
84 | |
|
85 | |
public String getSocketFactoryFallback() |
86 | |
{ |
87 | 0 | return socketFactoryFallback; |
88 | |
} |
89 | |
|
90 | |
public void setSocketFactoryFallback(String socketFactoryFallback) |
91 | |
{ |
92 | 0 | this.socketFactoryFallback = socketFactoryFallback; |
93 | 0 | } |
94 | |
|
95 | |
public String getTrustStore() |
96 | |
{ |
97 | 0 | return tls.getTrustStore(); |
98 | |
} |
99 | |
|
100 | |
public String getTrustStorePassword() |
101 | |
{ |
102 | 0 | return tls.getTrustStorePassword(); |
103 | |
} |
104 | |
|
105 | |
public void setTrustStore(String trustStore) throws IOException |
106 | |
{ |
107 | 0 | tls.setTrustStore(trustStore); |
108 | 0 | } |
109 | |
|
110 | |
public void setTrustStorePassword(String trustStorePassword) |
111 | |
{ |
112 | 0 | tls.setTrustStorePassword(trustStorePassword); |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
public String getClientKeyStore() |
119 | |
{ |
120 | 0 | return this.tls.getClientKeyStore(); |
121 | |
} |
122 | |
|
123 | |
public String getClientKeyStorePassword() |
124 | |
{ |
125 | 0 | return this.tls.getClientKeyStorePassword(); |
126 | |
} |
127 | |
|
128 | |
public String getClientKeyStoreType() |
129 | |
{ |
130 | 0 | return this.tls.getClientKeyStoreType(); |
131 | |
} |
132 | |
|
133 | |
public void setClientKeyStore(String name) throws IOException |
134 | |
{ |
135 | 0 | this.tls.setClientKeyStore(name); |
136 | 0 | } |
137 | |
|
138 | |
public void setClientKeyStorePassword(String clientKeyStorePassword) |
139 | |
{ |
140 | 0 | this.tls.setClientKeyStorePassword(clientKeyStorePassword); |
141 | 0 | } |
142 | |
|
143 | |
public void setClientKeyStoreType(String clientKeyStoreType) |
144 | |
{ |
145 | 0 | this.tls.setClientKeyStoreType(clientKeyStoreType); |
146 | 0 | } |
147 | |
|
148 | |
} |