Remove download by downloadId functionality (#1820)
This functionallity seems to get via AMQP (after some authentication) a private (wihtout need of authentication) url to an artifact assigned to the controller. By default, DDI or DMF shall provide proper urls (for direct download) to devices and if they have to be without authentication this shall be solved in different ways - for instance separate download server providing dedicated private / signed urls. This functinallity is not a real hawkBit part but more like something intended to solve some edge cases. Since it is complicated, heeds support, doesn't solve wide spread use cases, and could be achieved with other means - better to be removed. Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -22,9 +22,7 @@ import jakarta.servlet.ServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.security.DmfTenantSecurityToken.FileResource;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.hawkbit.util.UrlUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -159,8 +157,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
|
||||
|
||||
private DmfTenantSecurityToken createTenantSecurityTokenVariables(final HttpServletRequest request,
|
||||
final String tenant, final String controllerId) {
|
||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(tenant, null, controllerId, null,
|
||||
FileResource.createFileResourceBySha1(""));
|
||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(tenant, null, controllerId, null);
|
||||
|
||||
Collections.list(request.getHeaderNames())
|
||||
.forEach(header -> securityToken.putHeader(header, request.getHeader(header)));
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.security;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.cache.DownloadIdCache;
|
||||
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
|
||||
|
||||
/**
|
||||
* Extracts download or upload id from the request URI security token and set
|
||||
* the security context.
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter {
|
||||
|
||||
public static final String REQUEST_ID_REGEX_PATTERN = ".*\\/downloadId\\/.*";
|
||||
|
||||
private final Pattern pattern;
|
||||
private final DownloadIdCache downloadIdCache;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param downloadIdCache
|
||||
* the cache
|
||||
*/
|
||||
public HttpDownloadAuthenticationFilter(final DownloadIdCache downloadIdCache) {
|
||||
this.downloadIdCache = downloadIdCache;
|
||||
this.pattern = Pattern.compile(REQUEST_ID_REGEX_PATTERN);
|
||||
|
||||
}
|
||||
|
||||
private Object getDownloadByUri(final String requestURI) {
|
||||
final Matcher matcher = pattern.matcher(requestURI);
|
||||
if (!matcher.matches()) {
|
||||
return null;
|
||||
}
|
||||
log.debug("retrieving id from URI request {}", requestURI);
|
||||
final String[] groups = requestURI.split("\\/");
|
||||
final String id = groups[groups.length - 1];
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
return downloadIdCache.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getPreAuthenticatedPrincipal(final HttpServletRequest request) {
|
||||
return getDownloadByUri(request.getRequestURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getPreAuthenticatedCredentials(final HttpServletRequest request) {
|
||||
return getDownloadByUri(request.getRequestURI());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user