Skip to content

Commit 124227e

Browse files
authored
Merge pull request #25566 from dmatej/loginconfig
The java.security.auth.login.config system property must be an URL
2 parents 00b7246 + 106ddc9 commit 124227e

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/CLIBootstrap.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.File;
2121
import java.io.IOException;
2222
import java.io.PrintStream;
23+
import java.net.MalformedURLException;
24+
import java.net.URL;
2325
import java.nio.file.Path;
2426
import java.util.ArrayList;
2527
import java.util.List;
@@ -292,7 +294,7 @@ private void addProperties(final StringBuilder command) {
292294
command.append(' ').append("-D").append(INSTALL_ROOT.getSystemPropertyName()).append('=').append(quote(gfInfo.home().getAbsolutePath()));
293295
command.append(' ').append("-Dorg.glassfish.gmbal.no.multipleUpperBoundsException=true");
294296
command.append(' ').append(SECURITY_POLICY_PROPERTY_EXPR).append(quote(gfInfo.securityPolicy().getAbsolutePath()));
295-
command.append(' ').append(SECURITY_AUTH_LOGIN_CONFIG_PROPERTY_EXPR).append(quote(gfInfo.loginConfig().getAbsolutePath()));
297+
command.append(' ').append(SECURITY_AUTH_LOGIN_CONFIG_PROPERTY_EXPR).append(quote(gfInfo.loginConfig().toExternalForm()));
296298
}
297299

298300
/**
@@ -910,8 +912,12 @@ File securityPolicy() {
910912
return new File(libAppclient, "client.policy");
911913
}
912914

913-
File loginConfig() {
914-
return new File(libAppclient, "appclientlogin.conf");
915+
URL loginConfig() {
916+
try {
917+
return new File(libAppclient, "appclientlogin.conf").toURI().toURL();
918+
} catch (MalformedURLException e) {
919+
throw new IllegalStateException("Could not create URL for appclientlogin.conf", e);
920+
}
915921
}
916922
}
917923

appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
2+
* Copyright (c) 2024, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -27,7 +27,7 @@
2727
import java.io.File;
2828
import java.io.IOException;
2929
import java.net.Authenticator;
30-
import java.net.URI;
30+
import java.nio.file.Path;
3131
import java.util.List;
3232
import java.util.Properties;
3333
import java.util.logging.Logger;
@@ -87,28 +87,21 @@ void init(final TargetServer[] targetServers, final List<MessageSecurityConfig>
8787
}
8888

8989
private void initLoginConfig() throws IOException {
90-
/*
91-
* During Java Web Start launches, the appclientlogin.conf content is passed as a property. Store that content (if
92-
* present) into a local temporary file and use that during this app client launch.
93-
*/
90+
91+
// During Java Web Start launches, the appclientlogin.conf content is passed as a property.
92+
// Store that content (if present) into a local temporary file and use that during this app client launch.
9493
final String appclientloginConfContent = System.getProperty("appclient.login.conf.content");
95-
URI configURI;
94+
final File configFile;
9695
if (appclientloginConfContent == null) {
97-
configURI = new File(System.getProperty(INSTALL_ROOT.getSystemPropertyName())).toURI()
98-
.resolve("lib/appclient/appclientlogin.conf");
96+
configFile = new File(System.getProperty(INSTALL_ROOT.getSystemPropertyName())).toPath()
97+
.resolve(Path.of("lib", "appclient", "appclientlogin.conf")).toFile();
9998
} else {
100-
configURI = writeTextToTempFile(appclientloginConfContent, "appclientlogin", ".conf", false).toURI();
99+
configFile = writeTextToTempFile(appclientloginConfContent, "appclientlogin", ".conf", false);
101100
}
102101

103-
final File configFile = new File(configURI);
104-
105-
/*
106-
* Ugly, but necessary. The Java com.sun.security.auth.login.ConfigFile class expects the
107-
* java.security.auth.login.config property value to be a URL, but one with NO encoding. That is, if the path to the
108-
* config file contains a blank then ConfigFile class expects the URL to contain a blank, not %20 for example. So, we
109-
* need to use the deprecated File.toURL() method to create such a URL.
110-
*/
111-
System.setProperty("java.security.auth.login.config", configFile.toURI().toURL().toString());
102+
// The Java com.sun.security.auth.login.ConfigFile class expects the
103+
// java.security.auth.login.config property value to be a URL
104+
System.setProperty("java.security.auth.login.config", configFile.toURI().toURL().toExternalForm());
112105
}
113106

114107
/**

nucleus/security/core/src/main/java/com/sun/enterprise/security/SecurityLifecycle.java

Lines changed: 2 additions & 1 deletion
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) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
@@ -91,7 +92,7 @@ public SecurityLifecycle() {
9192
if (Util.isEmbeddedServer()) {
9293
// If the user-defined login.conf/server.policy are set as system properties, then they are given priority
9394
if (System.getProperty(SYS_PROP_LOGIN_CONF) == null) {
94-
System.setProperty(SYS_PROP_LOGIN_CONF, writeConfigFileToTempDir("login.conf").getAbsolutePath());
95+
System.setProperty(SYS_PROP_LOGIN_CONF, writeConfigFileToTempDir("login.conf").toURI().toURL().toExternalForm());
9596
}
9697
if (System.getProperty(SYS_PROP_JAVA_SEC_POLICY) == null) {
9798
System.setProperty(SYS_PROP_JAVA_SEC_POLICY, writeConfigFileToTempDir("server.policy").getAbsolutePath());

0 commit comments

Comments
 (0)