Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove restricted params from urls #1083

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions service-base/src/main/java/org/oskari/util/LayerUrlHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.oskari.util;

import fi.nls.oskari.util.ConversionHelper;
import fi.nls.oskari.util.IOHelper;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class LayerUrlHelper {

private static final Set<String> RESTRICTED_PARAMS = ConversionHelper.asSet("request", "service", "version");

public static String getSanitizedUrl(String pUrl) {
String baseUrl = IOHelper.removeQueryString(pUrl);
Map<String, List<String>> params = IOHelper.parseQuerystring(pUrl);
String url = baseUrl;

for (String key : params.keySet()) {
if (!RESTRICTED_PARAMS.contains(key.toLowerCase())) {
// not the most efficient way, but just regenerating the url without restricted params
url = IOHelper.addUrlParam(url, key, params.get(key).stream().toArray(String[]::new));
}
}
return url;
}
}
15 changes: 15 additions & 0 deletions service-base/src/test/java/org/oskari/util/LayerUrlHelperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.oskari.util;

import org.junit.Test;

import static org.junit.Assert.*;

public class LayerUrlHelperTest {

@Test
public void getSanitizedUrl() {
assertEquals("https://jee.org/?apikey=woot&proxy=not", LayerUrlHelper.getSanitizedUrl("https://jee.org/?apikey=woot&request=GetWheel&proxy=not"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetWheel 🙊

// doesn't work:
// assertEquals("resources://jee.org/?apikey=woot&proxy=not", LayerUrlHelper.getSanitizedUrl("resources://jee.org/?apikey=woot&request=GetWheel&proxy=not"));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oskari.capabilities;

import fi.nls.oskari.domain.map.OskariLayer;
import org.oskari.util.LayerUrlHelper;

import java.util.Objects;

Expand All @@ -13,11 +14,12 @@ public class ServiceConnectInfo {
private String pass;

public ServiceConnectInfo(String url, String type, String version) {
this.url = url;
this.url = LayerUrlHelper.getSanitizedUrl(url);
this.type = type;
this.version = version;
}


public void setCredentials(String user, String pass) {
this.user = user;
this.pass = pass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oskari.maplayer.model;

import fi.nls.oskari.domain.map.style.VectorStyle;
import org.oskari.util.LayerUrlHelper;

import java.util.*;

Expand Down Expand Up @@ -83,7 +84,7 @@ public String getUrl() {
}

public void setUrl(String url) {
this.url = url;
this.url = LayerUrlHelper.getSanitizedUrl(url);
}

public String getUsername() {
Expand Down
Loading