Skip to content

Commit 254809e

Browse files
committed
Using constants for default keystore type, file names, password
- in few tests changed to different to avoid confusion Signed-off-by: David Matějček <[email protected]>
1 parent 7b9f2d5 commit 254809e

File tree

31 files changed

+206
-198
lines changed

31 files changed

+206
-198
lines changed

appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/GlassFishTestEnvironment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
import org.glassfish.main.itest.tools.asadmin.StartServ;
5858
import org.glassfish.main.jdke.security.KeyTool;
5959

60+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
6061
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
62+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
6163
import static java.net.http.HttpResponse.BodyHandlers.ofString;
6264
import static org.glassfish.embeddable.GlassFishVariable.JAVA_HOME;
6365
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK;
@@ -176,7 +178,7 @@ public static Path getDomain1Directory() {
176178

177179

178180
public static KeyStore getDomain1KeyStore() {
179-
Path keystore = getDomain1Directory().resolve(Paths.get("config", "keystore.jks"));
181+
Path keystore = getDomain1Directory().resolve(Paths.get("config", KEYSTORE_FILENAME_DEFAULT));
180182
try {
181183
return new KeyTool(keystore.toFile(), KEYSTORE_PASSWORD_DEFAULT.toCharArray()).loadKeyStore();
182184
} catch (IOException e) {
@@ -186,7 +188,7 @@ public static KeyStore getDomain1KeyStore() {
186188

187189

188190
public static KeyStore getDomain1TrustStore() {
189-
Path cacerts = getDomain1Directory().resolve(Paths.get("config", "cacerts.jks"));
191+
Path cacerts = getDomain1Directory().resolve(Paths.get("config", TRUSTSTORE_FILENAME_DEFAULT));
190192
try {
191193
return new KeyTool(cacerts.toFile(), KEYSTORE_PASSWORD_DEFAULT.toCharArray()).loadKeyStore();
192194
} catch (IOException e) {

appserver/tests/application/src/test/java/org/glassfish/main/test/app/security/jmac/https/JmacHttpsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.junit.jupiter.api.io.TempDir;
5151

5252
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
53+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
5354
import static java.lang.System.Logger.Level.DEBUG;
5455
import static java.lang.System.Logger.Level.INFO;
5556
import static java.lang.System.Logger.Level.TRACE;
@@ -84,11 +85,11 @@ public class JmacHttpsTest {
8485

8586
@BeforeAll
8687
public static void prepareDeployment() throws Exception {
87-
myKeyStore = new File(tempDir, "httpstest.jks");
88+
myKeyStore = new File(tempDir, "httpstest.p12");
8889
myKeyStoreTool = new KeyTool(myKeyStore, MYKS_PASSWORD);
8990
myKeyStoreTool.generateKeyPair("httpstest", "CN=HTTPSTEST,OU=Eclipse GlassFish Tests", "RSA", 7);
9091

91-
File cacertsFile = getDomain1Directory().resolve(Paths.get("config", "cacerts.jks")).toFile();
92+
File cacertsFile = getDomain1Directory().resolve(Paths.get("config", TRUSTSTORE_FILENAME_DEFAULT)).toFile();
9293
myKeyStoreTool.copyCertificate("httpstest", cacertsFile, KEYSTORE_PASSWORD_DEFAULT.toCharArray());
9394

9495
// Default is false, required to set the client certificate to the context.

appserver/tests/embedded/maven-plugin/secureWebApp/src/test/java/org/glassfish/tests/embedded/securewebapp/SecureWebAppTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) {
6565

6666
@BeforeAll
6767
public static void createKeyStore() throws Exception {
68-
File keystore = JUnitSystem.detectBasedir().resolve(Path.of("target", "keystore.jks")).toFile();
68+
// The file is set also in system.properties file
69+
File keystore = JUnitSystem.detectBasedir().resolve(Path.of("target", "testkeystore.p12")).toFile();
6970
KeyTool keyTool = new KeyTool(keystore, KEYSTORE_PASSWORD_DEFAULT.toCharArray());
7071
keyTool.generateKeyPair("s1as", "CN=localhost", "RSA", 1);
7172
}

appserver/tests/embedded/maven-plugin/secureWebApp/src/test/resources/system.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
#
1717

1818
org.glassfish.embedded.greeting=Hi from BHAVANI
19-
javax.net.ssl.keyStore=${project.build.directory}/keystore.jks
20-
javax.net.ssl.trustStore=${project.build.directory}/truststore.jks
19+
javax.net.ssl.keyStore=${project.build.directory}/testkeystore.p12
20+
javax.net.ssl.trustStore=${project.build.directory}/testtruststore.p12

appserver/tests/embedded/web/web-api/src/test/java/org/glassfish/tests/embedded/web/EmbeddedAddHttpsListenerTest.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.BufferedReader;
2121
import java.io.File;
2222
import java.io.InputStreamReader;
23+
import java.net.URI;
2324
import java.net.URL;
2425
import java.security.SecureRandom;
2526
import java.security.cert.X509Certificate;
@@ -34,7 +35,6 @@
3435
import org.glassfish.embeddable.GlassFish;
3536
import org.glassfish.embeddable.GlassFishException;
3637
import org.glassfish.embeddable.GlassFishRuntime;
37-
import org.glassfish.embeddable.GlassFishVariable;
3838
import org.glassfish.embeddable.web.HttpsListener;
3939
import org.glassfish.embeddable.web.WebContainer;
4040
import org.glassfish.embeddable.web.config.SslConfig;
@@ -46,6 +46,7 @@
4646
import org.junit.jupiter.api.Test;
4747
import org.junit.jupiter.api.io.TempDir;
4848

49+
import static org.glassfish.embeddable.GlassFishVariable.KEYSTORE_FILE;
4950
import static org.glassfish.main.jdke.props.SystemProperties.setProperty;
5051

5152
/**
@@ -56,17 +57,17 @@
5657
public class EmbeddedAddHttpsListenerTest {
5758

5859
@TempDir
59-
static File tempDir;
60-
static GlassFish glassfish;
61-
static WebContainer embedded;
62-
static File root;
63-
static String contextRoot = "test";
60+
private static File tempDir;
61+
private static GlassFish glassfish;
62+
private static WebContainer embedded;
63+
private static File root;
64+
private static File keystore;
6465

6566
@BeforeAll
6667
public static void setupServer() throws Exception {
6768

68-
File keystore = new File(tempDir, "keystore.jks");
69-
setProperty(GlassFishVariable.KEYSTORE_FILE.getSystemPropertyName(), keystore.getAbsolutePath(), true);
69+
keystore = new File(tempDir, "test_keystore.p12");
70+
setProperty(KEYSTORE_FILE.getSystemPropertyName(), keystore.getAbsolutePath(), true);
7071
KeyTool keyTool = new KeyTool(keystore, "changeit".toCharArray());
7172
keyTool.generateKeyPair("s1as", "CN=localhost", "RSA", 1);
7273

@@ -87,7 +88,6 @@ public static void setupServer() throws Exception {
8788

8889
private void createHttpsListener(int port,
8990
String name,
90-
String keystore,
9191
String password,
9292
String certname) throws Exception {
9393

@@ -96,11 +96,8 @@ private void createHttpsListener(int port,
9696
listener.setId(name);
9797

9898
String keyStorePath = root.getAbsolutePath() + keystore;
99-
String trustStorePath = root.getAbsolutePath() + "/cacerts.jks";
100-
SslConfig sslConfig = new SslConfig(keyStorePath, trustStorePath);
99+
SslConfig sslConfig = new SslConfig(keyStorePath, null);
101100
sslConfig.setKeyPassword(password.toCharArray());
102-
String trustPassword = "changeit";
103-
sslConfig.setTrustPassword(trustPassword.toCharArray());
104101
if (certname != null) {
105102
sslConfig.setCertNickname(certname);
106103
}
@@ -110,26 +107,23 @@ private void createHttpsListener(int port,
110107
}
111108

112109
private void verify(int port) throws Exception {
113-
114-
URL servlet = new URL("https://localhost:"+port+"/classes/hello");
110+
URL servlet = new URI("https://localhost:" + port + "/classes/hello").toURL();
115111
HttpsURLConnection uc = (HttpsURLConnection) servlet.openConnection();
116-
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
117112
StringBuilder sb = new StringBuilder();
118-
String inputLine;
119-
while ((inputLine = in.readLine()) != null){
120-
sb.append(inputLine);
113+
try (BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()))) {
114+
String inputLine;
115+
while ((inputLine = in.readLine()) != null) {
116+
sb.append(inputLine);
117+
}
121118
}
122-
in.close();
123119
System.out.println(sb);
124120
Assertions.assertEquals("Hello World!", sb.toString());
125121
}
126122

127123
@Test
128124
public void test() throws Exception {
129125

130-
createHttpsListener(9191, "default-ssl-listener", "/keystore.jks", "changeit", "s1as");
131-
//createHttpsListener(9292, "ssl-listener0", "/keystore0", "password0", "keystore0");
132-
//createHttpsListener(9393, "ssl-listener1", "/keystore1", "password1", null);
126+
createHttpsListener(9191, "default-ssl-listener", "changeit", "s1as");
133127

134128
Deployer deployer = glassfish.getDeployer();
135129

appserver/web/web-core/src/main/java/org/apache/catalina/connector/CoyoteServerSocketFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.net.ServerSocket;
2424

2525
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
26+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_TYPE_DEFAULT;
2627

2728

2829
/**
@@ -43,7 +44,7 @@
4344
* <li><strong>keystorePass</strong> - Password for the Key Store file to be
4445
* loaded. ["changeit"]</li>
4546
* <li><strong>keystoreType</strong> - Type of the Key Store file to be
46-
* loaded. ["JKS"]</li>
47+
* loaded.</li>
4748
* <li><strong>protocol</strong> - SSL protocol to use. [TLS]</li>
4849
* </ul>
4950
*
@@ -61,7 +62,7 @@ public class CoyoteServerSocketFactory
6162
private String randomFile;
6263
private String rootFile;
6364
private String keystorePass = KEYSTORE_PASSWORD_DEFAULT;
64-
private String keystoreType = "JKS";
65+
private String keystoreType = KEYSTORE_TYPE_DEFAULT;
6566
private String protocol = "TLS";
6667
private String protocols;
6768
private String sslImplementation;

appserver/web/web-glue/src/main/java/com/sun/enterprise/web/connector/coyote/PECoyoteConnector.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@
6060
import org.glassfish.web.admin.monitor.RequestProbeProvider;
6161
import org.glassfish.web.util.IntrospectionUtils;
6262

63+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_TYPE_DEFAULT;
6364
import static org.glassfish.embeddable.GlassFishVariable.KEYSTORE_FILE;
6465
import static org.glassfish.embeddable.GlassFishVariable.KEYSTORE_TYPE;
6566
import static org.glassfish.embeddable.GlassFishVariable.TRUSTSTORE_FILE;
6667
import static org.glassfish.embeddable.GlassFishVariable.TRUSTSTORE_TYPE;
6768

6869
public class PECoyoteConnector extends Connector {
6970

70-
private static final String DEFAULT_KEYSTORE_TYPE = "JKS";
71-
private static final String DEFAULT_TRUSTSTORE_TYPE = "JKS";
72-
7371
private static final String DUMMY_CONNECTOR_LAUNCHER = DummyConnectorLauncher.class.getName();
7472

7573
protected static final Logger _logger = LogFacade.getLogger();
@@ -1334,14 +1332,14 @@ private void configureSSL(NetworkListener listener) {
13341332
*/
13351333
private void configureKeysAndCerts() {
13361334
String prop = System.getProperty(KEYSTORE_FILE.getSystemPropertyName());
1337-
String keyStoreType = System.getProperty(KEYSTORE_TYPE.getSystemPropertyName(), DEFAULT_KEYSTORE_TYPE);
1335+
String keyStoreType = System.getProperty(KEYSTORE_TYPE.getSystemPropertyName(), KEYSTORE_TYPE_DEFAULT);
13381336
if (prop != null) {
13391337
setKeystoreFile(prop);
13401338
setKeystoreType(keyStoreType);
13411339
}
13421340

13431341
prop = System.getProperty(TRUSTSTORE_FILE.getSystemPropertyName());
1344-
keyStoreType = System.getProperty(TRUSTSTORE_TYPE.getSystemPropertyName(), DEFAULT_TRUSTSTORE_TYPE);
1342+
keyStoreType = System.getProperty(TRUSTSTORE_TYPE.getSystemPropertyName(), KEYSTORE_TYPE_DEFAULT);
13451343
if (prop != null) {
13461344
setTruststore(prop);
13471345
setTruststoreType(keyStoreType);

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/KeystoreManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
import org.glassfish.main.jdke.security.KeyTool;
3434

35-
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.KEYSTORE_FILE;
36-
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.TRUSTSTORE_FILE;
35+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
36+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
3737

3838
/**
3939
* @author kebbs
@@ -102,8 +102,8 @@ protected void createKeyStore(File keyStore, RepositoryConfig config, String mas
102102

103103
protected void copyCertificatesToTrustStore(File configRoot, DomainConfig config, String masterPassword)
104104
throws DomainException {
105-
final File keyStore = new File(configRoot, KEYSTORE_FILE);
106-
final File trustStore = new File(configRoot, TRUSTSTORE_FILE);
105+
final File keyStore = new File(configRoot, KEYSTORE_FILENAME_DEFAULT);
106+
final File trustStore = new File(configRoot, TRUSTSTORE_FILENAME_DEFAULT);
107107
final KeyTool keyTool = new KeyTool(keyStore, masterPassword.toCharArray());
108108
try {
109109
keyTool.copyCertificate(CERTIFICATE_ALIAS, trustStore);

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/LocalServerCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static com.sun.enterprise.admin.cli.CLIConstants.DEFAULT_HOSTNAME;
4848
import static com.sun.enterprise.admin.cli.ProgramOptions.PasswordLocation.LOCAL_PASSWORD;
4949
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
50+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
5051
import static java.util.logging.Level.CONFIG;
5152
import static java.util.logging.Level.FINER;
5253

@@ -408,7 +409,7 @@ private File getJKS() {
408409
return null;
409410
}
410411

411-
File mp = new File(new File(serverDirs.getServerDir(), "config"), "cacerts.jks");
412+
File mp = new File(new File(serverDirs.getServerDir(), "config"), TRUSTSTORE_FILENAME_DEFAULT);
412413
if (!mp.canRead()) {
413414
return null;
414415
}

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/domain/DomainBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.logging.Logger;
5050

5151
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.DOMAIN_XML_FILE;
52+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
5253
import static java.text.MessageFormat.format;
5354
import static org.glassfish.embeddable.GlassFishVariable.INSTALL_ROOT;
5455

@@ -137,7 +138,7 @@ private void initialize() throws DomainException {
137138
_domainTempalte = new DomainTemplate(templateInfoHolder, stringSubstitutor, templateJarPath);
138139

139140
// Loads default self signed certificate.
140-
je = _templateJar.getJarEntry("config/" + DomainConstants.KEYSTORE_FILE);
141+
je = _templateJar.getJarEntry("config/" + KEYSTORE_FILENAME_DEFAULT);
141142
if (je != null) {
142143
_keystoreBytes = new byte[(int) je.getSize()];
143144
InputStream in = null;

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/domain/DomainConstants.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
23
* Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
@@ -13,10 +14,13 @@
1314
*
1415
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1516
*/
16-
1717
package com.sun.enterprise.admin.servermgmt.domain;
1818

19-
public class DomainConstants {
19+
public final class DomainConstants {
20+
21+
private DomainConstants() {
22+
// Prevent instantiation
23+
}
2024

2125
/** Filename contains encrypted admin credentials. */
2226
public static final String ADMIN_KEY_FILE = "admin-keyfile";
@@ -36,15 +40,9 @@ public class DomainConstants {
3640
/** Name of directory stores the domain information. */
3741
public static final String INFO_DIRECTORY = "init-info";
3842

39-
/** Filename contains the server certificates, including its private key. */
40-
public static final String KEYSTORE_FILE = "keystore.jks";
41-
4243
/** Master password file name stores the password for secure key store. */
4344
public static final String MASTERPASSWORD_FILE = "master-password";
4445

45-
/** Filename contains the trusted certificates, including public keys. */
46-
public static final String TRUSTSTORE_FILE = "cacerts.jks";
47-
4846
/** Filename contains most of the domain configuration. */
4947
public static final String DOMAIN_XML_FILE = "domain.xml";
5048
}

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/domain/DomainSecurity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828
import org.glassfish.security.common.FileRealmHelper;
2929

30-
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.KEYSTORE_FILE;
31-
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.TRUSTSTORE_FILE;
30+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
3231
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
32+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
3333

3434
public class DomainSecurity extends MasterPasswordFileManager {
3535

@@ -75,8 +75,8 @@ void createPasswordAliasKeystore(File pwFile, String password) throws Repository
7575
* @throws RepositoryException if any error occurs during keystore creation.
7676
*/
7777
void createSSLCertificateDatabase(File configDir, DomainConfig config, String masterPassword) throws RepositoryException {
78-
createKeyStore(new File(configDir, KEYSTORE_FILE), config, masterPassword);
79-
changeKeystorePassword(KEYSTORE_PASSWORD_DEFAULT, masterPassword, new File(configDir, TRUSTSTORE_FILE));
78+
createKeyStore(new File(configDir, KEYSTORE_FILENAME_DEFAULT), config, masterPassword);
79+
changeKeystorePassword(KEYSTORE_PASSWORD_DEFAULT, masterPassword, new File(configDir, TRUSTSTORE_FILENAME_DEFAULT));
8080
copyCertificatesToTrustStore(configDir, config, masterPassword);
8181
}
8282

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/pe/PEFileLayout.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.Locale;
3131
import java.util.Map;
3232

33+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
34+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
3335
import static java.text.MessageFormat.format;
3436

3537
public class PEFileLayout {
@@ -534,17 +536,12 @@ public File getWssServerConfig() {
534536
return new File(getConfigRoot(), WSSSERVERCONFIG);
535537
}
536538

537-
public static final String KEYSTORE = "keystore.jks";
538-
539539
public File getKeyStore() {
540-
return new File(getConfigRoot(), KEYSTORE);
540+
return new File(getConfigRoot(), KEYSTORE_FILENAME_DEFAULT);
541541
}
542542

543-
544-
public static final String TRUSTSTORE = "cacerts.jks";
545-
546543
public File getTrustStore() {
547-
return new File(getConfigRoot(), TRUSTSTORE);
544+
return new File(getConfigRoot(), TRUSTSTORE_FILENAME_DEFAULT);
548545
}
549546

550547
public static final String MASTERPASSWORD_FILE = "master-password";

0 commit comments

Comments
 (0)