Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reflection access to sun.security.util.HostnameChecker #165

Merged
merged 2 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added
### Fixed
- [[#1136] Allow reflection access to sun.security.util.HostnameChecker](https://github.com/ballerina-platform/ballerina-standard-library/issues/1136)

## [1.1.0-alpha8] - 2021-04-22

### Added
- [[#1248] Make possible to identify Compiler Plugin when email listener is given as a variable to the service](https://github.com/ballerina-platform/ballerina-standard-library/issues/1248)
- [[#1113] Add compiler extension for Email module](https://github.com/ballerina-platform/ballerina-standard-library/issues/1113)
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import javax.mail.Store;
import javax.mail.search.FlagTerm;

import static org.ballerinalang.stdlib.email.util.EmailConstants.HOSTNAME_CHECKER_CLASS;

/**
* Contains the functionality of email reading with POP and IMAP clients.
*
Expand All @@ -52,6 +54,20 @@ public class EmailAccessClient {

private EmailAccessClient() {}

static {
Class<?> hostNameCheckerClass = null;
try {
hostNameCheckerClass = Class.forName(HOSTNAME_CHECKER_CLASS);
} catch (ClassNotFoundException e) {
log.error("sun.security.util.HostnameChecker class was not found from EmailAccessClient.");
}
if (hostNameCheckerClass != null) {
String hostNameCheckerPackageName = hostNameCheckerClass.getPackageName();
Module emailAccessClientModule = EmailAccessClient.class.getModule();
hostNameCheckerClass.getModule().addOpens(hostNameCheckerPackageName, emailAccessClientModule);
}
}

/**
* Initializes the BObject object with the POP properties.
* @param clientEndpoint Represents the POP Client class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import javax.mail.Session;
import javax.mail.Transport;

import static org.ballerinalang.stdlib.email.util.EmailConstants.HOSTNAME_CHECKER_CLASS;

/**
* Contains functionality of SMTP Client.
*
Expand All @@ -47,6 +49,20 @@ public class SmtpClient {

private SmtpClient() {}

static {
Class<?> hostNameCheckerClass = null;
try {
hostNameCheckerClass = Class.forName(HOSTNAME_CHECKER_CLASS);
} catch (ClassNotFoundException e) {
log.error("sun.security.util.HostnameChecker class was not found from SmtpClient.");
}
if (hostNameCheckerClass != null) {
String hostNameCheckerPackageName = hostNameCheckerClass.getPackageName();
Module smtpClientModule = SmtpClient.class.getModule();
hostNameCheckerClass.getModule().addOpens(hostNameCheckerPackageName, smtpClientModule);
}
}

/**
* Initializes the BObject object with the SMTP Properties.
* @param clientEndpoint Represents the SMTP Client class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private EmailConstants() {}
MODULE_VERSION);
public static final String HTML_CONTENT_TYPE = "text/html";
public static final String DEFAULT_TRANSPORT_PROTOCOL = "TLS";
public static final String HOSTNAME_CHECKER_CLASS = "sun.security.util.HostnameChecker";
public static final String SSL_SOCKET_FACTORY_CLASS = "javax.net.ssl.SSLSocketFactory";
public static final BString ATTACHMENT_FILE_PATH = StringUtils.fromString("filePath");
public static final BString ATTACHMENT_CONTENT_TYPE = StringUtils.fromString("contentType");
Expand Down