Skip to content

Commit

Permalink
OWS-631: fix properties defined in jnlp
Browse files Browse the repository at this point in the history
  • Loading branch information
janakmulani committed Jun 7, 2024
1 parent 5d1ddc8 commit c482c85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/net/sourceforge/jnlp/JNLPFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected JNLPFile() {

final String httpAgent = getResources().getPropertiesMap().get(HTTP_AGENT);
// Do not set http.agent in stage 2 as it can be set from the vmarg to the jvm
if (! StringUtils.isBlank(httpAgent) && !"true".equalsIgnoreCase(System.getenv(ApplicationInstance.IGNORE_HTTP_AGENT_PROPERTY))) {
if (!StringUtils.isBlank(httpAgent) && !ApplicationInstance.getBlackListedJnlpProperties().contains(HTTP_AGENT)) {
System.setProperty(HTTP_AGENT, httpAgent);
if (!HttpURLConnection.userAgent.contains(httpAgent)) {
LOG.warn("Cannot set HTTP User-Agent as a connection has been opened before reading the JNLP file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.sourceforge.jnlp.runtime;

import net.adoptopenjdk.icedteaweb.JavaSystemPropertiesConstants;
import net.adoptopenjdk.icedteaweb.StringUtils;
import net.adoptopenjdk.icedteaweb.jnlp.element.resource.ExtensionDesc;
import net.adoptopenjdk.icedteaweb.jnlp.element.resource.PropertyDesc;
import net.adoptopenjdk.icedteaweb.jnlp.element.security.SecurityDesc;
Expand All @@ -39,7 +40,11 @@
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Represents a running instance of an application described in a
* JNLPFile. This class provides a way to track the application's
Expand All @@ -54,7 +59,16 @@ public class ApplicationInstance {

private static final String DEPLOYMENT_SYSPROP = "deployment.javaws";
private static final String DEPLOYMENT_SYSPROP_VALUE = "IcedTea-Web";
public static final String IGNORE_HTTP_AGENT_PROPERTY = "ignoreHttpAgentProperty";
public static final String BLACKLIST_FOR_JNLP_PROPERTIES = "blacklistForJnlpProperties";
public static final String BLACKLISTED_PROPERTIES_SEPARATOR = "=";

public static Set<String> getBlackListedJnlpProperties() {
final String blackListedProprtiesString = System.getenv(BLACKLIST_FOR_JNLP_PROPERTIES);
if (StringUtils.isBlank(blackListedProprtiesString)) {
return Collections.emptySet();
}
return new HashSet<>(Arrays.asList(blackListedProprtiesString.split(BLACKLISTED_PROPERTIES_SEPARATOR)));
}

// todo: should attempt to unload the environment variables
// installed by the application.
Expand Down Expand Up @@ -155,10 +169,9 @@ private void setSystemPropertiesFromJnlp() {
final AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { pd });

final PrivilegedAction<Object> setPropertiesAction = () -> {
final Set<String> blackListedJnlpProperties = getBlackListedJnlpProperties();
for (PropertyDesc propDesc : props) {
if (!propDesc.getKey().equals(JavaSystemPropertiesConstants.HTTP_AGENT)) {
setSystemProperty(propDesc);
} else if (!"true".equalsIgnoreCase(System.getenv(ApplicationInstance.IGNORE_HTTP_AGENT_PROPERTY))) {
if (!blackListedJnlpProperties.contains(propDesc.getKey())) {
setSystemProperty(propDesc);
}
}
Expand Down

0 comments on commit c482c85

Please sign in to comment.