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

[CDAP-16181] Adding sessionTimeout and sessionCacheSize #83

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
50 changes: 48 additions & 2 deletions src/main/java/io/cdap/http/SSLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ public class SSLConfig {
private final String certificatePassword;
private final File trustKeyStore;
private final String trustKeyStorePassword;
private final long sessionTimeoutInSeconds;
private final long sessionCacheSize;

private SSLConfig(File keyStore, String keyStorePassword,
String certificatePassword, File trustKeyStore, String trustKeyStorePassword) {
String certificatePassword, File trustKeyStore, String trustKeyStorePassword,
long sessionCacheSize, long sessionTimeoutInSeconds) {
this.keyStore = keyStore;
this.keyStorePassword = keyStorePassword;
this.certificatePassword = certificatePassword;
this.trustKeyStore = trustKeyStore;
this.trustKeyStorePassword = trustKeyStorePassword;
this.sessionCacheSize = sessionCacheSize;
this.sessionTimeoutInSeconds = sessionTimeoutInSeconds;
}

/**
Expand Down Expand Up @@ -72,6 +77,20 @@ public String getTrustKeyStorePassword() {
return trustKeyStorePassword;
}

/**
* @return size of cache used for storing SSL session objects.
*/
public long getSessionCacheSize() {
return sessionCacheSize;
}

/**
* @return timeout for the cached SSL session objects, in seconds.
*/
public long getSessionTimeoutInSeconds() {
return sessionTimeoutInSeconds;
}

/**
* Creates a builder for the SSLConfig.
*
Expand All @@ -92,10 +111,14 @@ public static class Builder {
private String certificatePassword;
private File trustKeyStore;
private String trustKeyStorePassword;
private long sessionTimeoutInSeconds;
private long sessionCacheSize;

private Builder(File keyStore, String keyStorePassword) {
this.keyStore = keyStore;
this.keyStorePassword = keyStorePassword;
this.sessionCacheSize = 10000L;
this.sessionTimeoutInSeconds = 60L;
}

/**
Expand All @@ -120,6 +143,28 @@ public Builder setTrustKeyStore(File trustKeyStore) {
return this;
}

/**
* Set the SSL session object timeout in seconds.
*
* @param sessionTimeoutInSeconds time in seconds.
* @return an instance of {@code Builder}.
*/
public Builder setSessionTimeoutInSecond(long sessionTimeoutInSeconds) {
this.sessionTimeoutInSeconds = sessionTimeoutInSeconds;
return this;
}

/**
* Set the SSL session object cache.
*
* @param sessionCacheSize size of SSL session object to be cached.
* @return an instance of {@code Builder}.
*/
public Builder setSessionCacheSize(long sessionCacheSize) {
this.sessionCacheSize = sessionCacheSize;
return this;
}

/**
* Set trust KeyStore password.
*
Expand All @@ -144,7 +189,8 @@ public SSLConfig build() {
if (keyStorePassword == null) {
throw new IllegalArgumentException("KeyStore Password Not Configured");
}
return new SSLConfig(keyStore, keyStorePassword, certificatePassword, trustKeyStore, trustKeyStorePassword);
return new SSLConfig(keyStore, keyStorePassword, certificatePassword, trustKeyStore, trustKeyStorePassword,
sessionCacheSize, sessionTimeoutInSeconds);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misalignment

}
}
}
3 changes: 2 additions & 1 deletion src/main/java/io/cdap/http/SSLHandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public SSLHandlerFactory(SSLConfig sslConfig) {
tmf.init(tks);
builder.trustManager(tmf);
}

builder.sessionTimeout(sslConfig.getSessionTimeoutInSeconds());
builder.sessionCacheSize(sslConfig.getSessionCacheSize());
this.sslContext = builder.build();
} catch (Exception e) {
throw new IllegalArgumentException("Failed to initialize the server-side SSLContext", e);
Expand Down