Skip to content

Commit bb70f49

Browse files
committed
applying PR apache#4827 Co-authored-by: @sramazzina
1 parent 12367cc commit bb70f49

File tree

4 files changed

+146
-23
lines changed

4 files changed

+146
-23
lines changed

plugins/misc/mail/src/main/java/org/apache/hop/metadata/mail/MailServerConnection.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public class MailServerConnection extends HopMetadataBase implements IHopMetadat
5858

5959
@HopMetadataProperty private String proxyUsername;
6060

61+
@HopMetadataProperty private String trustedHosts;
62+
63+
@HopMetadataProperty private boolean checkServerIdentity;
64+
6165
public MailServerConnection() {
6266
super();
6367
}
@@ -98,6 +102,10 @@ public Session getSession(IVariables variables) {
98102
// javax.net.ssl.SSLException: Unsupported record version Unknown
99103
props.put("mail.smtps.quitwait", "false");
100104
}
105+
props.put("mail.smtp.ssl.checkServerIdentity", isCheckServerIdentity());
106+
if (!Utils.isEmpty(trustedHosts)) {
107+
props.put("mail.smtp.ssl.trust", variables.resolve(trustedHosts));
108+
}
101109
}
102110

103111
props.put(CONST_MAIL + protocol.toLowerCase() + ".host", variables.resolve(serverHost));

plugins/misc/mail/src/main/java/org/apache/hop/metadata/mail/MailServerConnectionEditor.java

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
import org.apache.hop.ui.core.metadata.MetadataEditor;
99
import org.apache.hop.ui.core.metadata.MetadataManager;
1010
import org.apache.hop.ui.core.widget.ComboVar;
11+
import org.apache.hop.ui.core.widget.LabelTextVar;
1112
import org.apache.hop.ui.core.widget.PasswordTextVar;
1213
import org.apache.hop.ui.core.widget.TextVar;
1314
import org.apache.hop.ui.hopgui.HopGui;
1415
import org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective;
1516
import org.eclipse.swt.SWT;
17+
import org.eclipse.swt.events.SelectionAdapter;
18+
import org.eclipse.swt.events.SelectionEvent;
1619
import org.eclipse.swt.layout.FormAttachment;
1720
import org.eclipse.swt.layout.FormData;
1821
import org.eclipse.swt.widgets.Button;
@@ -50,6 +53,12 @@ public class MailServerConnectionEditor extends MetadataEditor<MailServerConnect
5053

5154
private ComboVar wConnectionProtocol;
5255

56+
private Button wCheckServerIdentity;
57+
58+
private Label wlCheckServerIdentity;
59+
60+
private LabelTextVar wTrustedHosts;
61+
5362
public MailServerConnectionEditor(
5463
HopGui hopGui, MetadataManager<MailServerConnection> manager, MailServerConnection metadata) {
5564
super(hopGui, manager, metadata);
@@ -82,6 +91,28 @@ public void createControl(Composite composite) {
8291
wName.setLayoutData(fdName);
8392
Control lastControl = wName;
8493

94+
Label wlConnectionProtocol = new Label(composite, SWT.RIGHT);
95+
PropsUi.setLook(wlConnectionProtocol);
96+
wlConnectionProtocol.setText(
97+
BaseMessages.getString(PKG, "MailServerConnectionDialog.ConnectionProtocol"));
98+
FormData fdlConnectionProtocol = new FormData();
99+
fdlConnectionProtocol.top = new FormAttachment(lastControl, margin);
100+
fdlConnectionProtocol.left = new FormAttachment(0, 0);
101+
fdlConnectionProtocol.right = new FormAttachment(middle, -margin);
102+
wlConnectionProtocol.setLayoutData(fdlConnectionProtocol);
103+
wConnectionProtocol = new ComboVar(variables, composite, SWT.SINGLE | SWT.BORDER);
104+
PropsUi.setLook(wConnectionProtocol);
105+
FormData fdConnectionProtocol = new FormData();
106+
fdConnectionProtocol.top = new FormAttachment(lastControl, margin);
107+
fdConnectionProtocol.left = new FormAttachment(middle, 0);
108+
fdConnectionProtocol.right = new FormAttachment(100, 0);
109+
wConnectionProtocol.setLayoutData(fdConnectionProtocol);
110+
lastControl = wConnectionProtocol;
111+
112+
String[] protocols = new String[] {"SMTP", "IMAP", "POP3", "MBOX"};
113+
wConnectionProtocol.setItems(protocols);
114+
wConnectionProtocol.select(1);
115+
85116
Label wlServerHostLabel = new Label(composite, SWT.RIGHT);
86117
PropsUi.setLook(wlServerHostLabel);
87118
wlServerHostLabel.setText(BaseMessages.getString(PKG, "MailServerConnectionDialog.ServerHost"));
@@ -221,8 +252,48 @@ public void createControl(Composite composite) {
221252
fdSecureConnectionType.left = new FormAttachment(middle, 0);
222253
fdSecureConnectionType.right = new FormAttachment(100, 0);
223254
wSecureConnectionType.setLayoutData(fdSecureConnectionType);
255+
String[] secureConnectionType = new String[] {"SSL", "TLS", "TLS 1.2"};
224256
lastControl = wSecureConnectionType;
225257

258+
// Use check server identity
259+
wlCheckServerIdentity = new Label(composite, SWT.RIGHT);
260+
wlCheckServerIdentity.setText(
261+
BaseMessages.getString(PKG, "ActionMail.CheckServerIdentity.Label"));
262+
PropsUi.setLook(wlCheckServerIdentity);
263+
FormData fdlCheckServerIdentity = new FormData();
264+
fdlCheckServerIdentity.left = new FormAttachment(0, 0);
265+
fdlCheckServerIdentity.top = new FormAttachment(lastControl, 2 * margin);
266+
fdlCheckServerIdentity.right = new FormAttachment(middle, -margin);
267+
wlCheckServerIdentity.setLayoutData(fdlCheckServerIdentity);
268+
wCheckServerIdentity = new Button(composite, SWT.CHECK);
269+
PropsUi.setLook(wCheckServerIdentity);
270+
FormData fdCheckServerIdentity = new FormData();
271+
fdCheckServerIdentity.left = new FormAttachment(middle, margin);
272+
fdCheckServerIdentity.top = new FormAttachment(lastControl, 0, SWT.CENTER);
273+
fdCheckServerIdentity.right = new FormAttachment(100, 0);
274+
wCheckServerIdentity.setLayoutData(fdCheckServerIdentity);
275+
wCheckServerIdentity.addSelectionListener(
276+
new SelectionAdapter() {
277+
@Override
278+
public void widgetSelected(SelectionEvent e) {
279+
setChanged();
280+
}
281+
});
282+
283+
// Trusted Hosts line
284+
wTrustedHosts =
285+
new LabelTextVar(
286+
variables,
287+
composite,
288+
BaseMessages.getString(PKG, "ActionMail.TrustedHosts.Label"),
289+
BaseMessages.getString(PKG, "ActionMail.TrustedHosts.Tooltip"));
290+
// wTrustedHosts.addModifyListener(lsMod);
291+
FormData fdTrustedHosts = new FormData();
292+
fdTrustedHosts.left = new FormAttachment(0, 0);
293+
fdTrustedHosts.top = new FormAttachment(lastControl, 2 * margin);
294+
fdTrustedHosts.right = new FormAttachment(100, 0);
295+
wTrustedHosts.setLayoutData(fdTrustedHosts);
296+
226297
Label wlUseProxy = new Label(composite, SWT.RIGHT);
227298
PropsUi.setLook(wlUseProxy);
228299
wlUseProxy.setText(BaseMessages.getString(PKG, "MailServerConnectionDialog.UseProxy"));
@@ -276,28 +347,6 @@ public void createControl(Composite composite) {
276347
wProxyPassword.setLayoutData(fdProxyPassword);
277348
lastControl = wProxyPassword;
278349

279-
Label wlConnectionProtocol = new Label(composite, SWT.RIGHT);
280-
PropsUi.setLook(wlConnectionProtocol);
281-
wlConnectionProtocol.setText(
282-
BaseMessages.getString(PKG, "MailServerConnectionDialog.ConnectionProtocol"));
283-
FormData fdlConnectionProtocol = new FormData();
284-
fdlConnectionProtocol.top = new FormAttachment(lastControl, margin);
285-
fdlConnectionProtocol.left = new FormAttachment(0, 0);
286-
fdlConnectionProtocol.right = new FormAttachment(middle, -margin);
287-
wlConnectionProtocol.setLayoutData(fdlConnectionProtocol);
288-
wConnectionProtocol = new ComboVar(variables, composite, SWT.SINGLE | SWT.BORDER);
289-
PropsUi.setLook(wConnectionProtocol);
290-
FormData fdConnectionProtocol = new FormData();
291-
fdConnectionProtocol.top = new FormAttachment(lastControl, margin);
292-
fdConnectionProtocol.left = new FormAttachment(middle, 0);
293-
fdConnectionProtocol.right = new FormAttachment(100, 0);
294-
wConnectionProtocol.setLayoutData(fdConnectionProtocol);
295-
lastControl = wConnectionProtocol;
296-
297-
String[] protocols = new String[] {"SMTP", "IMAP", "POP3", "MBOX"};
298-
wConnectionProtocol.setItems(protocols);
299-
wConnectionProtocol.select(1);
300-
301350
setWidgetsContent();
302351

303352
resetChanged();
@@ -353,6 +402,8 @@ public void setWidgetsContent() {
353402
wUseSecureAuthentication.setSelection(metadata.isUseSecureAuthentication());
354403
wSecureConnectionType.setText(Const.NVL(metadata.getSecureConnectionType(), ""));
355404
wUseProxy.setSelection(metadata.isUseProxy());
405+
wTrustedHosts.setText(Const.NVL(metadata.getTrustedHosts(), ""));
406+
wCheckServerIdentity.setSelection(wCheckServerIdentity.getSelection());
356407
wProxyUsername.setText(Const.NVL(metadata.getProxyUsername(), ""));
357408
wConnectionProtocol.setText(Const.NVL(metadata.getProtocol(), ""));
358409
}
@@ -369,11 +420,13 @@ public void getWidgetsContent(MailServerConnection connection) {
369420
connection.setPassword(wServerPassword.getText());
370421
connection.setUseSecureAuthentication(wUseSecureAuthentication.getSelection());
371422
connection.setSecureConnectionType(wSecureConnectionType.getText());
423+
connection.setTrustedHosts(wTrustedHosts.getText());
424+
connection.setCheckServerIdentity(wCheckServerIdentity.getSelection());
372425
connection.setUseProxy(wUseProxy.getSelection());
373426
connection.setProxyUsername(wProxyUsername.getText());
374427
}
375428

376-
public void testConnection() {
429+
private void testConnection() {
377430
MailServerConnection connection = new MailServerConnection(getVariables());
378431
connection.setName(wName.getText());
379432
connection.setProtocol(wConnectionProtocol.getText());

plugins/misc/mail/src/main/java/org/apache/hop/workflow/actions/mail/ActionMail.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ public class ActionMail extends ActionBase implements Cloneable, IAction {
159159
@HopMetadataProperty(key = "use_Priority")
160160
private boolean usePriority;
161161

162+
@HopMetadataProperty(key = "trusted_hosts")
163+
private String trustedHosts;
164+
165+
@HopMetadataProperty(key = "check_server_identity")
166+
private boolean checkServerIdentity;
167+
162168
@HopMetadataProperty private String port;
163169

164170
@HopMetadataProperty private String priority;
@@ -249,6 +255,10 @@ public Result execute(Result result, int nr) {
249255
// javax.net.ssl.SSLException: Unsupported record version Unknown
250256
props.put("mail.smtps.quitwait", "false");
251257
}
258+
props.put("mail.smtp.ssl.checkServerIdentity", isCheckServerIdentity());
259+
if (!Utils.isEmpty(trustedHosts)) {
260+
props.put("mail.smtp.ssl.trust", resolve(trustedHosts));
261+
}
252262
}
253263

254264
props.put(CONST_MAIL + protocol + ".host", resolve(server));

plugins/misc/mail/src/main/java/org/apache/hop/workflow/actions/mail/ActionMailDialog.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ public class ActionMailDialog extends ActionDialog {
166166
private TextVar wContentID;
167167
private TableView wFields;
168168

169+
private Button wCheckServerIdentity;
170+
171+
private Label wlCheckServerIdentity;
172+
173+
private LabelTextVar wTrustedHosts;
174+
169175
private MetaSelectionLine wSelectionLine;
170176

171177
public ActionMailDialog(
@@ -661,6 +667,45 @@ public void widgetSelected(SelectionEvent e) {
661667
}
662668
});
663669

670+
// Use check server identity
671+
wlCheckServerIdentity = new Label(wAuthentificationGroup, SWT.RIGHT);
672+
wlCheckServerIdentity.setText(
673+
BaseMessages.getString(PKG, "ActionMail.CheckServerIdentity.Label"));
674+
PropsUi.setLook(wlCheckServerIdentity);
675+
FormData fdlCheckServerIdentity = new FormData();
676+
fdlCheckServerIdentity.left = new FormAttachment(0, 0);
677+
fdlCheckServerIdentity.top = new FormAttachment(wSecureConnectionType, 2 * margin);
678+
fdlCheckServerIdentity.right = new FormAttachment(middle, -margin);
679+
wlCheckServerIdentity.setLayoutData(fdlCheckServerIdentity);
680+
wCheckServerIdentity = new Button(wAuthentificationGroup, SWT.CHECK);
681+
PropsUi.setLook(wCheckServerIdentity);
682+
FormData fdCheckServerIdentity = new FormData();
683+
fdCheckServerIdentity.left = new FormAttachment(middle, margin);
684+
fdCheckServerIdentity.top = new FormAttachment(wlCheckServerIdentity, 0, SWT.CENTER);
685+
fdCheckServerIdentity.right = new FormAttachment(100, 0);
686+
wCheckServerIdentity.setLayoutData(fdCheckServerIdentity);
687+
wCheckServerIdentity.addSelectionListener(
688+
new SelectionAdapter() {
689+
@Override
690+
public void widgetSelected(SelectionEvent e) {
691+
action.setChanged();
692+
}
693+
});
694+
695+
// Trusted Hosts line
696+
wTrustedHosts =
697+
new LabelTextVar(
698+
variables,
699+
wAuthentificationGroup,
700+
BaseMessages.getString(PKG, "ActionMail.TrustedHosts.Label"),
701+
BaseMessages.getString(PKG, "ActionMail.TrustedHosts.Tooltip"));
702+
wTrustedHosts.addModifyListener(lsMod);
703+
FormData fdTrustedHosts = new FormData();
704+
fdTrustedHosts.left = new FormAttachment(0, 0);
705+
fdTrustedHosts.top = new FormAttachment(wlCheckServerIdentity, 2 * margin);
706+
fdTrustedHosts.right = new FormAttachment(100, 0);
707+
wTrustedHosts.setLayoutData(fdTrustedHosts);
708+
664709
FormData fdAuthentificationGroup = new FormData();
665710
fdAuthentificationGroup.left = new FormAttachment(0, margin);
666711
fdAuthentificationGroup.top = new FormAttachment(wServerGroup, margin);
@@ -1412,6 +1457,8 @@ private void setEnabledEncoding() {
14121457
}
14131458

14141459
protected void setSecureConnectiontype() {
1460+
wTrustedHosts.setEnabled(wUseSecAuth.getSelection());
1461+
wCheckServerIdentity.setEnabled(wUseSecAuth.getSelection());
14151462
wSecureConnectionType.setEnabled(wUseSecAuth.getSelection());
14161463
wlSecureConnectionType.setEnabled(wUseSecAuth.getSelection());
14171464
}
@@ -1472,6 +1519,8 @@ public void getData() {
14721519

14731520
wUseAuth.setSelection(action.isUsingAuthentication());
14741521
wUseSecAuth.setSelection(action.isUsingSecureAuthentication());
1522+
wCheckServerIdentity.setSelection(action.isCheckServerIdentity());
1523+
wTrustedHosts.setText(Const.nullToEmpty(action.getTrustedHosts()));
14751524
wAuthUser.setText(Const.nullToEmpty(action.getAuthenticationUser()));
14761525
wAuthPass.setText(Const.nullToEmpty(action.getAuthenticationPassword()));
14771526

@@ -1618,6 +1667,9 @@ private void ok() {
16181667
action.setUseHTML(wUseHTML.getSelection());
16191668
action.setUsePriority(wUsePriority.getSelection());
16201669

1670+
action.setTrustedHosts(wTrustedHosts.getText());
1671+
action.setCheckServerIdentity(wCheckServerIdentity.getSelection());
1672+
16211673
action.setEncoding(wEncoding.getText());
16221674
action.setPriority(wPriority.getText());
16231675

0 commit comments

Comments
 (0)