Skip to content

Commit 83dc08b

Browse files
afsahsyedaGMishx
authored andcommitted
feat(ImportCDX): remove VCS URL redirection logic
Signed-off-by: afsahsyeda <[email protected]>
1 parent 3fff93d commit 83dc08b

File tree

5 files changed

+2
-102
lines changed

5 files changed

+2
-102
lines changed

backend/common/src/main/java/org/eclipse/sw360/common/utils/RepositoryURL.java

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,27 @@
1010

1111
package org.eclipse.sw360.common.utils;
1212

13-
import java.io.IOException;
1413
import java.net.*;
1514
import java.util.*;
1615
import java.util.stream.Collectors;
1716

1817
import org.apache.logging.log4j.LogManager;
1918
import org.apache.logging.log4j.Logger;
2019
import org.eclipse.sw360.datahandler.common.CommonUtils;
21-
import org.eclipse.sw360.datahandler.common.SW360Constants;
2220
import org.eclipse.sw360.datahandler.common.SW360Utils;
2321

2422
import static org.eclipse.sw360.datahandler.common.SW360ConfigKeys.VCS_HOSTS;
25-
import static org.eclipse.sw360.datahandler.common.SW360ConfigKeys.VCS_REDIRECTION_LIMIT;
26-
import static org.eclipse.sw360.datahandler.common.SW360ConfigKeys.VCS_REDIRECTION_TIMEOUT_LIMIT;
2723

2824
public class RepositoryURL {
29-
private String url;
3025
private static final Logger log = LogManager.getLogger(RepositoryURL.class);
3126
private static final String SCHEMA_PATTERN = ".+://(\\w*(?:[\\-@.\\\\s,_:/][/(.\\-)A-Za-z0-9]+)*)";
3227
private static final String VCS_HOSTS_STRING = SW360Utils.readConfig(VCS_HOSTS,"");
3328
private static final Map<String, String> KNOWN_VCS_HOSTS = parseVCSHosts(VCS_HOSTS_STRING);
34-
private Set<String> redirectedUrls = new HashSet<>();
35-
private static int redirectionTimeout = Integer.parseInt(SW360Utils.readConfig(VCS_REDIRECTION_TIMEOUT_LIMIT, SW360Constants.VCS_REDIRECTION_TIMEOUT_LIMIT));
36-
private static int redirectionLimit = Integer.parseInt(SW360Utils.readConfig(VCS_REDIRECTION_LIMIT, SW360Constants.VCS_REDIRECTION_LIMIT));
37-
38-
public RepositoryURL(){}
39-
40-
public RepositoryURL(String url) {
41-
if (url == null || url.isEmpty()) {
42-
throw new IllegalArgumentException("URL cannot be null or empty");
43-
}
44-
this.url = processURL(url);
45-
}
4629

4730
public String processURL(String url) {
48-
String sanitized = sanitizeVCS(url);
49-
return handleURLRedirection(sanitized);
31+
return sanitizeVCS(url);
5032
}
5133

52-
5334
private static String formatVCSUrl(String host, String[] urlParts) {
5435
String formatString = KNOWN_VCS_HOSTS.get(host);
5536

@@ -111,74 +92,6 @@ public static String getComponentNameFromVCS(String vcsUrl, boolean isGetVendora
11192
return isGetVendorandName ? String.join("/", pathParts) : pathParts[pathParts.length - 1];
11293
}
11394

114-
public String handleURLRedirection(String urlString) {
115-
URL url;
116-
HttpURLConnection connection = null;
117-
try {
118-
url = new URI(urlString).toURL();
119-
} catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) {
120-
log.error("Invalid URL format: {}", e.getMessage());
121-
return urlString;
122-
}
123-
124-
int redirectCount = 0;
125-
126-
while (redirectCount < redirectionLimit) {
127-
try {
128-
connection = openConnection(url);
129-
int status = connection.getResponseCode();
130-
131-
if (status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_MOVED_TEMP || status == 308) {
132-
String newUrl = connection.getHeaderField("Location");
133-
connection.disconnect();
134-
135-
// Resolve relative URLs
136-
url = url.toURI().resolve(newUrl).toURL();
137-
138-
if (!"https".equalsIgnoreCase(url.getProtocol())) {
139-
log.error("Insecure redirection to non-HTTPS URL: {}", url);
140-
return urlString;
141-
}
142-
143-
redirectCount++;
144-
redirectedUrls.add(urlString);
145-
} else {
146-
connection.disconnect();
147-
break;
148-
}
149-
} catch (IOException | URISyntaxException | IllegalArgumentException e) {
150-
log.error("Error during redirection handling: {}", e.getMessage());
151-
return urlString;
152-
}
153-
finally {
154-
if (connection != null) {
155-
connection.disconnect();
156-
}
157-
}
158-
159-
}
160-
161-
if (redirectCount == 0 || redirectCount >= redirectionLimit) {
162-
if (redirectCount >= redirectionLimit) {
163-
log.error("Exceeded maximum redirect limit. Returning original URL.");
164-
}
165-
return urlString;
166-
}
167-
return sanitizeVCS(url.toString());
168-
}
169-
170-
private static HttpURLConnection openConnection(URL url) throws IOException{
171-
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
172-
connection.setInstanceFollowRedirects(false);
173-
connection.setConnectTimeout(redirectionTimeout);
174-
connection.setReadTimeout(redirectionTimeout);
175-
return connection;
176-
}
177-
178-
public Set<String> getRedirectedUrls(){
179-
return redirectedUrls;
180-
}
181-
18295
private static Map<String, String> parseVCSHosts(String propertyValue) {
18396
if (propertyValue == null || propertyValue.isEmpty()) {
18497
log.error("VCS_HOSTS property is empty");

backend/common/src/main/java/org/eclipse/sw360/cyclonedx/CycloneDxBOMImporter.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public class CycloneDxBOMImporter {
108108
private static final String INVALID_PACKAGE = "invalidPkg";
109109
private static final String PROJECT_ID = "projectId";
110110
private static final String PROJECT_NAME = "projectName";
111-
private static final String REDIRECTED_VCS = "redirectedVCS";
112111
public static final String INVALID_VCS_COMPONENT = "invalidVcsComponent";
113112
private static final Predicate<ExternalReference.Type> typeFilter = Type.VCS::equals;
114113

@@ -299,8 +298,6 @@ public RequestSummary importFromBOM(InputStream inputStream, AttachmentContent a
299298
// all components does not have VCS, so return & show appropriate error in UI
300299
messageMap.put(INVALID_COMPONENT, String.join(JOINER, componentsWithoutVcs));
301300
messageMap.put(INVALID_PACKAGE, String.join(JOINER, invalidPackages));
302-
messageMap.put(REDIRECTED_VCS, String.join(JOINER, repositoryURL.getRedirectedUrls()));
303-
messageMap.put(DUPLICATE_PACKAGE, String.join(JOINER, duplicatePackages));
304301
messageMap.put(SW360Constants.MESSAGE,
305302
String.format("VCS information is missing for <b>%s</b> / <b>%s</b> Components!",
306303
componentsCount - vcsCount, componentsCount));
@@ -811,7 +808,6 @@ private Map<String, String> importAllComponentsAsPackages(Map<String, List<org.c
811808
messageMap.put(DUPLICATE_RELEASE, String.join(JOINER, duplicateReleases));
812809
messageMap.put(DUPLICATE_PACKAGE, String.join(JOINER, duplicatePackages));
813810
messageMap.put(INVALID_RELEASE, String.join(JOINER, invalidReleases));
814-
messageMap.put(REDIRECTED_VCS, String.join(JOINER, repositoryURL.getRedirectedUrls()));
815811
messageMap.put(NON_PKG_MANAGED_COMP_WITHOUT_VCS, String.join(JOINER, nonPkgManagedCompWithoutVCS));
816812
messageMap.put(INVALID_PACKAGE, String.join(JOINER, invalidPackages));
817813
messageMap.put(INVALID_VCS_COMPONENT, String.join(JOINER, invalidVcsComponents));

backend/common/src/main/java/org/eclipse/sw360/datahandler/db/SW360ConfigsDatabaseHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ private void loadToConfigsInMemForSw360(ConfigContainer configContainer) {
8888
.put(RELEASE_FRIENDLY_URL, getOrDefault(configContainer, RELEASE_FRIENDLY_URL, "http://localhost:3000/components/releases/detail/releaseId"))
8989
.put(COMBINED_CLI_PARSER_EXTERNAL_ID_CORRELATION_KEY, getOrDefault(configContainer, COMBINED_CLI_PARSER_EXTERNAL_ID_CORRELATION_KEY, ""))
9090
.put(VCS_HOSTS, getOrDefault(configContainer, VCS_HOSTS, ""))
91-
.put(VCS_REDIRECTION_LIMIT, getOrDefault(configContainer, VCS_REDIRECTION_LIMIT, String.valueOf(SW360Constants.VCS_REDIRECTION_LIMIT)))
92-
.put(VCS_REDIRECTION_TIMEOUT_LIMIT, getOrDefault(configContainer, VCS_REDIRECTION_TIMEOUT_LIMIT, String.valueOf(SW360Constants.VCS_REDIRECTION_TIMEOUT_LIMIT)))
9391
.put(NON_PKG_MANAGED_COMPS_PROP, getOrDefault(configContainer, NON_PKG_MANAGED_COMPS_PROP, ""))
9492
.build();
9593
putInMemory(ConfigFor.SW360_CONFIGURATION, configMap);
@@ -206,9 +204,7 @@ private boolean isConfigValid(String configKey, String configValue) {
206204
-> configValue != null;
207205

208206
// validate int value
209-
case ATTACHMENT_DELETE_NO_OF_DAYS,
210-
VCS_REDIRECTION_LIMIT,
211-
VCS_REDIRECTION_TIMEOUT_LIMIT
207+
case ATTACHMENT_DELETE_NO_OF_DAYS
212208
-> isIntegerValue(configValue);
213209

214210
// validate string in enum

libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360ConfigKeys.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public class SW360ConfigKeys {
6565

6666
//Properties used by the RepositoryURL class to handle VCS from SBOM
6767
public static final String VCS_HOSTS = "vcs.hosts";
68-
public static final String VCS_REDIRECTION_LIMIT = "vcs.redirection.limit";
69-
public static final String VCS_REDIRECTION_TIMEOUT_LIMIT = "vcs.redirection.timeout.limit";
7068
public static final String NON_PKG_MANAGED_COMPS_PROP = "non.pkg.managed.comps.prop";
7169

7270
// Properties purely used by UI

libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Constants.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ public class SW360Constants {
120120
public static final String SRC_ATTACHMENT_DOWNLOAD_LOCATION;
121121
public static final String PREFERRED_CLEARING_DATE_LIMIT;
122122

123-
public static final String VCS_REDIRECTION_LIMIT = "5";
124-
public static final String VCS_REDIRECTION_TIMEOUT_LIMIT = "5000";
125-
126123
public static final String COMPONENTS = "components";
127124
public static final String PROJECTS = "projects";
128125
public static final String LICENSES = "licenses";

0 commit comments

Comments
 (0)