From f690fbd72382aa29906472f45d77b5a92f0dd2dc Mon Sep 17 00:00:00 2001 From: janakmulani Date: Thu, 14 Dec 2023 19:23:24 +0530 Subject: [PATCH] Replace Set with UrlKey or List --- .../security/MissingALACAttributePanel.java | 6 +++--- .../dialogs/security/SecurityDialogs.java | 6 +++--- .../manifest/ManifestAttributesChecker.java | 20 ++++++++++--------- .../net/sourceforge/jnlp/util/UrlUtils.java | 3 ++- .../dialogs/security/SecurityDialogsTest.java | 16 +++++++-------- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/MissingALACAttributePanel.java b/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/MissingALACAttributePanel.java index 23c65380c..2aa79a18d 100644 --- a/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/MissingALACAttributePanel.java +++ b/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/MissingALACAttributePanel.java @@ -67,8 +67,8 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; /** * http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/manifest.html#app_library @@ -151,7 +151,7 @@ public void hyperlinkUpdate(HyperlinkEvent e) { } public static void main(String[] args) throws MalformedURLException { - Set s = new HashSet<>(); + List s = new ArrayList<>(); s.add(new URL("http:/blah.com/blah")); s.add(new URL("http:/blah.com/blah/blah")); MissingALACAttributePanel w = new MissingALACAttributePanel(null, "HelloWorld", "http://nbblah.url", UrlUtils.setOfUrlsToHtmlList(s)); diff --git a/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogs.java b/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogs.java index 59ce9fdcc..b3718f20a 100644 --- a/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogs.java +++ b/core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogs.java @@ -58,7 +58,7 @@ import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.Set; +import java.util.List; import java.util.concurrent.Semaphore; /** @@ -221,7 +221,7 @@ public static NamePassword showAuthenticationPrompt(String host, int port, Strin return (NamePassword) response; } - public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase, Set remoteUrls) { + public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase, List remoteUrls) { SecurityDialogMessage message = new SecurityDialogMessage(file); message.dialogType = DialogType.MISSING_ALACA; @@ -242,7 +242,7 @@ public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase, return selectedValue.toBoolean(); } - public static boolean showMatchingALACAttributePanel(JNLPFile file, URL documentBase, Set remoteUrls) { + public static boolean showMatchingALACAttributePanel(JNLPFile file, URL documentBase, List remoteUrls) { SecurityDialogMessage message = new SecurityDialogMessage(file); message.dialogType = DialogType.MATCHING_ALACA; diff --git a/core/src/main/java/net/adoptopenjdk/icedteaweb/manifest/ManifestAttributesChecker.java b/core/src/main/java/net/adoptopenjdk/icedteaweb/manifest/ManifestAttributesChecker.java index 0de455f46..66d068e97 100644 --- a/core/src/main/java/net/adoptopenjdk/icedteaweb/manifest/ManifestAttributesChecker.java +++ b/core/src/main/java/net/adoptopenjdk/icedteaweb/manifest/ManifestAttributesChecker.java @@ -332,12 +332,12 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx final URL codebase = file.getCodeBase(); //cases - final Map> usedUrls = new HashMap<>(); + final Map> usedUrls = new HashMap<>(); final URL sourceLocation = file.getSourceLocation(); final ResourcesDesc[] resourcesDescs = file.getResourcesDescs(); if ((sourceLocation != null) && !FILE_PROTOCOL.equals(sourceLocation.getProtocol())) { final URL urlWithoutFileName = UrlUtils.removeFileName(sourceLocation); - usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(sourceLocation); + usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(new UrlKey(sourceLocation)); } for (ResourcesDesc resourcesDesc : resourcesDescs) { ExtensionDesc[] ex = resourcesDesc.getExtensions(); @@ -345,7 +345,7 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx for (ExtensionDesc extensionDesc : ex) { if (extensionDesc != null) { final URL urlWithoutFileName = UrlUtils.removeFileName(extensionDesc.getLocation()); - usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(extensionDesc.getLocation()); + usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(new UrlKey(extensionDesc.getLocation())); } } } @@ -354,7 +354,7 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx for (JARDesc jarDesc : jars) { if (jarDesc != null) { final URL urlWithoutFileName = UrlUtils.removeFileName(jarDesc.getLocation()); - usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(jarDesc.getLocation()); + usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(new UrlKey(jarDesc.getLocation())); } } } @@ -366,7 +366,7 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx LOG.debug("The application is not using any url resources, skipping Application-Library-Allowable-Codebase Attribute check."); return; } - final Set notOkUrls = new HashSet<>(); + final Set notOkUrls = new HashSet<>(); final boolean skipResourcesFromFileSystem = Boolean.parseBoolean(JNLPRuntime.getConfiguration().getProperty(ConfigurationConstants.KEY_ASSUME_FILE_STEM_IN_CODEBASE)); for (UrlKey urlKey : usedUrls.keySet()) { final URL u = urlKey.getUrl(); @@ -375,7 +375,7 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx } else if (skipResourcesFromFileSystem && FILE_PROTOCOL.equals(u.getProtocol())) { LOG.debug("OK - '{}' is from file system", u); } else { - notOkUrls.add(u); + notOkUrls.add(urlKey); LOG.warn("Warning! '{}' is NOT from codebase '{}'.", u, codebase); } } @@ -393,9 +393,11 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx att = null; } - final Set notOkResources = notOkUrls.stream() - .flatMap(notOk -> usedUrls.get(new UrlKey(notOk)).stream()) - .collect(Collectors.toSet()); + final List notOkResources = notOkUrls.stream() + .flatMap(notOk -> usedUrls.get(notOk).stream()) + .collect(Collectors.toSet()).stream() + .map(UrlKey::getUrl) + .collect(Collectors.toList()); notOkResources.forEach(url -> LOG.warn("The resource '{}' is not from codebase '{}'", url, codebase)); diff --git a/core/src/main/java/net/sourceforge/jnlp/util/UrlUtils.java b/core/src/main/java/net/sourceforge/jnlp/util/UrlUtils.java index f899f855f..3c85e47da 100644 --- a/core/src/main/java/net/sourceforge/jnlp/util/UrlUtils.java +++ b/core/src/main/java/net/sourceforge/jnlp/util/UrlUtils.java @@ -60,6 +60,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.List; import java.util.Objects; import static java.nio.charset.StandardCharsets.UTF_8; @@ -226,7 +227,7 @@ public static URL removeFileName(final URL src) { * @param remoteUrls list of urls * @return String containing html item list of those urls */ - public static String setOfUrlsToHtmlList(final Collection remoteUrls) { + public static String setOfUrlsToHtmlList(final List remoteUrls) { return setOfUrlsToHtmlList(remoteUrls, 4); } diff --git a/core/src/test/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogsTest.java b/core/src/test/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogsTest.java index d72e491a7..57298be1b 100644 --- a/core/src/test/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogsTest.java +++ b/core/src/test/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogsTest.java @@ -66,7 +66,7 @@ import java.lang.reflect.Field; import java.net.MalformedURLException; import java.net.URL; -import java.util.HashSet; +import java.util.ArrayList; @Ignore public class SecurityDialogsTest extends NoStdOutErrTest { @@ -312,9 +312,9 @@ private void testAllDialogs(ExpectedResults r) throws MalformedURLException { //Assert.assertEquals(r.ea, r5); NamePassword r6 = SecurityDialogs.showAuthenticationPrompt(null, 123456, null, null); Assert.assertEquals(r.np, r6); - boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new HashSet()); + boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>()); Assert.assertEquals(r.b, r7); - boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet()); + boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>()); Assert.assertEquals(r.b, r8); boolean r9 = SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF()); Assert.assertEquals(r.b, r9); @@ -336,9 +336,9 @@ private void testAllDialogsNullResults() throws MalformedURLException { //Assert.assertEquals(r.ea, r5); NamePassword r6 = SecurityDialogs.showAuthenticationPrompt(null, 123456, null, null); Assert.assertEquals(null, r6); - boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new HashSet()); + boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>()); Assert.assertEquals(false, r7); - boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet()); + boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>()); Assert.assertEquals(false, r8); boolean r9 = SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF()); Assert.assertEquals(false, r9); @@ -441,7 +441,7 @@ private void countNPES(int allowedRuns) throws MalformedURLException { } try { metcounter++; - SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet()); + SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>()); } catch (NullPointerException ex) { npecounter++; } @@ -628,9 +628,9 @@ public void testUnsignedDialogsNotHeadlessPrompt() throws Exception { + ".* \\Q" + urlstr + "\\E "; private void runRememeberableClasses(ExpectedResults r) throws MalformedURLException { - boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new HashSet()); + boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>()); Assert.assertEquals(r.b, r7); - boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet()); + boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>()); Assert.assertEquals(r.b, r8); boolean r9 = testUnsignedBehaviour(); Assert.assertEquals(r.b, r9);