Skip to content

Commit

Permalink
7384: Add option to enable STARTTLS encryption for mail server in com…
Browse files Browse the repository at this point in the history
…munication preference

Reviewed-by: hirt
  • Loading branch information
Suchita Chaturvedi committed Oct 4, 2021
1 parent 90165cf commit b447fd4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -60,6 +60,7 @@ public class Messages extends NLS {
public static String CommunicationPage_CAPTION_MAIL_SERVER_USER;
public static String CommunicationPage_CAPTION_RETAINED_EVENT_VALUES;
public static String CommunicationPage_CAPTION_SECURE_MAIL_SERVER;
public static String CommunicationPage_CAPTION_SECURE_MAIL_SERVER_STARTTLS;
public static String CommunicationPage_DESCRIPTION;
public static String CommunicationPage_UPDATE_INTERVAL_THREAD_STACK0;
public static String ConsoleEditorInput_FAILED_TO_OPEN_EDITOR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -122,6 +122,11 @@ public void createFieldEditors() {
Messages.CommunicationPage_CAPTION_SECURE_MAIL_SERVER, getFieldEditorParent());
addField(mailServerSecure);

BooleanFieldEditor mailServerStarttls = new BooleanFieldEditor(
PreferencesKeys.PROPERTY_MAIL_SERVER_STARTTLS_ENCRYPTION,
Messages.CommunicationPage_CAPTION_SECURE_MAIL_SERVER_STARTTLS, getFieldEditorParent());
addField(mailServerStarttls);

createCredentialFields();
loadCredentials();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
Expand Down Expand Up @@ -80,6 +80,7 @@ CommunicationPage_CAPTION_MAIL_SERVER_USER=Mail server user:
CommunicationPage_CAPTION_MAIL_SERVER_PASSWORD=Mail server password:
CommunicationPage_CAPTION_RETAINED_EVENT_VALUES=Retained event values
CommunicationPage_CAPTION_SECURE_MAIL_SERVER=Secure mail server (SSL)
CommunicationPage_CAPTION_SECURE_MAIL_SERVER_STARTTLS=Enable STARTTLS Encryption
GeneralPage_DESCRIPTION=General settings for the JMX Console.\n\n
GeneralPage_SHOW_WARNING_BEFORE_UPDATING_HEAP_HISTOGRAM=Show warning before updating heap histogram
GeneralPage_LIST_AGGREGATE_SIZE=Show tree nodes in groups of:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -53,6 +53,8 @@ public void initializeDefaultPreferences() {
preferences.put(PreferencesKeys.PROPERTY_MAIL_SERVER, PreferencesKeys.DEFAULT_MAIL_SERVER);
preferences.putInt(PreferencesKeys.PROPERTY_MAIL_SERVER_PORT, PreferencesKeys.DEFAULT_MAIL_SERVER_PORT);
preferences.putBoolean(PreferencesKeys.PROPERTY_MAIL_SERVER_SECURE, PreferencesKeys.DEFAULT_MAIL_SERVER_SECURE);
preferences.putBoolean(PreferencesKeys.PROPERTY_MAIL_SERVER_STARTTLS_ENCRYPTION,
PreferencesKeys.DEFAULT_MAIL_SERVER_STARTTLS_ENCRYPTION);
preferences.put(PreferencesKeys.PROPERTY_MAIL_SERVER_CREDENTIALS,
PreferencesKeys.DEFAULT_MAIL_SERVER_CREDENTIALS);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -51,10 +51,12 @@ public class PreferencesKeys {
public static final String PROPERTY_MAIL_SERVER = "rjmx.smtp.server"; //$NON-NLS-1$
public static final String PROPERTY_MAIL_SERVER_PORT = "rjmx.smtp.server.port"; //$NON-NLS-1$
public static final String PROPERTY_MAIL_SERVER_SECURE = "rjmx.smtp.server.secure"; //$NON-NLS-1$
public static final String PROPERTY_MAIL_SERVER_STARTTLS_ENCRYPTION = "rjmx.smtp.server.starttls.encryption"; //$NON-NLS-1$
public static final String PROPERTY_MAIL_SERVER_CREDENTIALS = "rjmx.smtp.server.credentials"; //$NON-NLS-1$
public static final String DEFAULT_MAIL_SERVER = "mail.example.org"; //$NON-NLS-1$
public static final int DEFAULT_MAIL_SERVER_PORT = 25;
public static final boolean DEFAULT_MAIL_SERVER_SECURE = false;
public static final boolean DEFAULT_MAIL_SERVER_STARTTLS_ENCRYPTION = false;
public static final String DEFAULT_MAIL_SERVER_USER = ""; //$NON-NLS-1$
public static final String DEFAULT_MAIL_SERVER_PASSWORD = ""; //$NON-NLS-1$
public static final String DEFAULT_MAIL_SERVER_CREDENTIALS = ""; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -95,6 +95,7 @@ public void handleNotificationEvent(TriggerEvent e) throws MessagingException {
*/
public void sendEMail(String subject, String content) throws MessagingException {
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", getSmtpSTARTTLS());
Session session = Session.getInstance(props, null);
UserPassword credentials = getSmtpCredentials();
URLName urlName = createURLName(credentials);
Expand Down Expand Up @@ -183,6 +184,12 @@ private Boolean getSmtpSSL() {
PreferencesKeys.DEFAULT_MAIL_SERVER_SECURE);
}

private Boolean getSmtpSTARTTLS() {
return RJMXPlugin.getDefault().getRJMXPreferences().getBoolean(
PreferencesKeys.PROPERTY_MAIL_SERVER_STARTTLS_ENCRYPTION,
PreferencesKeys.DEFAULT_MAIL_SERVER_STARTTLS_ENCRYPTION);
}

/**
* Gets the cc.
*
Expand Down

0 comments on commit b447fd4

Please sign in to comment.