Skip to content

Commit

Permalink
Replace Set<URL> with UrlKey or List
Browse files Browse the repository at this point in the history
  • Loading branch information
janakmulani committed Dec 14, 2023
1 parent 71cb061 commit f690fbd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,7 +151,7 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
}

public static void main(String[] args) throws MalformedURLException {
Set<URL> s = new HashSet<>();
List<URL> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<URL> remoteUrls) {
public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase, List<URL> remoteUrls) {

SecurityDialogMessage message = new SecurityDialogMessage(file);
message.dialogType = DialogType.MISSING_ALACA;
Expand All @@ -242,7 +242,7 @@ public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase,
return selectedValue.toBoolean();
}

public static boolean showMatchingALACAttributePanel(JNLPFile file, URL documentBase, Set<URL> remoteUrls) {
public static boolean showMatchingALACAttributePanel(JNLPFile file, URL documentBase, List<URL> remoteUrls) {

SecurityDialogMessage message = new SecurityDialogMessage(file);
message.dialogType = DialogType.MATCHING_ALACA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,20 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx
final URL codebase = file.getCodeBase();

//cases
final Map<UrlKey, Set<URL>> usedUrls = new HashMap<>();
final Map<UrlKey, Set<UrlKey>> 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();
if (ex != null) {
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()));
}
}
}
Expand All @@ -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()));
}
}
}
Expand All @@ -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<URL> notOkUrls = new HashSet<>();
final Set<UrlKey> 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();
Expand All @@ -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);
}
}
Expand All @@ -393,9 +393,11 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx
att = null;
}

final Set<URL> notOkResources = notOkUrls.stream()
.flatMap(notOk -> usedUrls.get(new UrlKey(notOk)).stream())
.collect(Collectors.toSet());
final List<URL> 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));

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/net/sourceforge/jnlp/util/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<URL> remoteUrls) {
public static String setOfUrlsToHtmlList(final List<URL> remoteUrls) {
return setOfUrlsToHtmlList(remoteUrls, 4);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<URL>());
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>());
Assert.assertEquals(r.b, r7);
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
Assert.assertEquals(r.b, r8);
boolean r9 = SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF());
Assert.assertEquals(r.b, r9);
Expand All @@ -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<URL>());
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>());
Assert.assertEquals(false, r7);
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
Assert.assertEquals(false, r8);
boolean r9 = SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF());
Assert.assertEquals(false, r9);
Expand Down Expand Up @@ -441,7 +441,7 @@ private void countNPES(int allowedRuns) throws MalformedURLException {
}
try {
metcounter++;
SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
} catch (NullPointerException ex) {
npecounter++;
}
Expand Down Expand Up @@ -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<URL>());
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>());
Assert.assertEquals(r.b, r7);
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
Assert.assertEquals(r.b, r8);
boolean r9 = testUnsignedBehaviour();
Assert.assertEquals(r.b, r9);
Expand Down

0 comments on commit f690fbd

Please sign in to comment.