Merge branch 'master' into feature_enable_push_in_deployment_view

Conflicts:
	hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetDeletedEvent.java
	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleMetadatadetailslayout.java
	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java
	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java
	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java


Signed-off-by: Gaurav <gaurav.sahay@in.bosch.com>
This commit is contained in:
Gaurav
2016-08-10 11:44:23 +02:00
136 changed files with 1129 additions and 1105 deletions

0
3rd-dependencies/listDeps.sh Normal file → Executable file
View File

View File

@@ -118,6 +118,16 @@ public class DeviceSimulatorUpdater {
}
private static final class DeviceSimulatorUpdateThread implements Runnable {
/**
*
*/
private static final String BUT_GOT_LOG_MESSAGE = " but got: ";
/**
*
*/
private static final String DOWNLOAD_LOG_MESSAGE = "Download ";
private static final int MINIMUM_TOKENLENGTH_FOR_HINT = 6;
private static final Random rndSleep = new SecureRandom();
@@ -187,7 +197,7 @@ public class DeviceSimulatorUpdater {
return result;
}
private boolean isErrorResponse(final UpdateStatus status) {
private static boolean isErrorResponse(final UpdateStatus status) {
if (status == null) {
return false;
}
@@ -212,60 +222,73 @@ public class DeviceSimulatorUpdater {
LOGGER.debug("Downloading {} with token {}, expected sha1 hash {} and size {}", url,
hideTokenDetails(targetToken), sha1Hash, size);
long overallread = 0;
try {
final CloseableHttpClient httpclient = createHttpClientThatAcceptsAllServerCerts();
final HttpGet request = new HttpGet(url);
request.addHeader(HttpHeaders.AUTHORIZATION, "TargetToken " + targetToken);
final String sha1HashResult;
try (final CloseableHttpResponse response = httpclient.execute(request)) {
if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
final String message = wrongStatusCode(url, response);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
if (response.getEntity().getContentLength() != size) {
final String message = wrongContentLength(url, size, response);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
// Exception squid:S2070 - not used for hashing sensitive
// data
@SuppressWarnings("squid:S2070")
final MessageDigest md = MessageDigest.getInstance("SHA-1");
try (final BufferedOutputStream bdos = new BufferedOutputStream(
new DigestOutputStream(ByteStreams.nullOutputStream(), md))) {
try (BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
overallread = ByteStreams.copy(bis, bdos);
}
}
if (overallread != size) {
final String message = incompleteRead(url, size, overallread);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
sha1HashResult = BaseEncoding.base16().lowerCase().encode(md.digest());
}
if (!sha1Hash.equalsIgnoreCase(sha1HashResult)) {
final String message = wrongHash(url, sha1Hash, overallread, sha1HashResult);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
return readAndCheckDownloadUrl(url, targetToken, sha1Hash, size);
} catch (IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
LOGGER.error("Failed to download" + url, e);
return new UpdateStatus(ResponseStatus.ERROR, "Failed to download " + url + ": " + e.getMessage());
}
}
private static UpdateStatus readAndCheckDownloadUrl(final String url, final String targetToken,
final String sha1Hash, final long size)
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
long overallread;
final CloseableHttpClient httpclient = createHttpClientThatAcceptsAllServerCerts();
final HttpGet request = new HttpGet(url);
request.addHeader(HttpHeaders.AUTHORIZATION, "TargetToken " + targetToken);
final String sha1HashResult;
try (final CloseableHttpResponse response = httpclient.execute(request)) {
if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
final String message = wrongStatusCode(url, response);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
if (response.getEntity().getContentLength() != size) {
final String message = wrongContentLength(url, size, response);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
// Exception squid:S2070 - not used for hashing sensitive
// data
@SuppressWarnings("squid:S2070")
final MessageDigest md = MessageDigest.getInstance("SHA-1");
overallread = getOverallRead(response, md);
if (overallread != size) {
final String message = incompleteRead(url, size, overallread);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
sha1HashResult = BaseEncoding.base16().lowerCase().encode(md.digest());
}
if (!sha1Hash.equalsIgnoreCase(sha1HashResult)) {
final String message = wrongHash(url, sha1Hash, overallread, sha1HashResult);
return new UpdateStatus(ResponseStatus.ERROR, message);
}
final String message = "Downloaded " + url + " (" + overallread + " bytes)";
LOGGER.debug(message);
return new UpdateStatus(ResponseStatus.SUCCESSFUL, message);
}
private static long getOverallRead(final CloseableHttpResponse response, final MessageDigest md)
throws IOException {
long overallread;
try (final BufferedOutputStream bdos = new BufferedOutputStream(
new DigestOutputStream(ByteStreams.nullOutputStream(), md))) {
try (BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
overallread = ByteStreams.copy(bis, bdos);
}
}
return overallread;
}
private static String hideTokenDetails(final String targetToken) {
if (targetToken == null) {
return "<NULL!>";
@@ -285,29 +308,30 @@ public class DeviceSimulatorUpdater {
private static String wrongHash(final String url, final String sha1Hash, final long overallread,
final String sha1HashResult) {
final String message = "Download " + url + " failed with SHA1 hash missmatch (Expected: " + sha1Hash
+ " but got: " + sha1HashResult + ") (" + overallread + " bytes)";
final String message = DOWNLOAD_LOG_MESSAGE + url + " failed with SHA1 hash missmatch (Expected: "
+ sha1Hash + BUT_GOT_LOG_MESSAGE + sha1HashResult + ") (" + overallread + " bytes)";
LOGGER.error(message);
return message;
}
private static String incompleteRead(final String url, final long size, final long overallread) {
final String message = "Download " + url + " is incomplete (Expected: " + size + " but got: " + overallread
+ ")";
final String message = DOWNLOAD_LOG_MESSAGE + url + " is incomplete (Expected: " + size
+ BUT_GOT_LOG_MESSAGE + overallread + ")";
LOGGER.error(message);
return message;
}
private static String wrongContentLength(final String url, final long size,
final CloseableHttpResponse response) {
final String message = "Download " + url + " has wrong content length (Expected: " + size + " but got: "
+ response.getEntity().getContentLength() + ")";
final String message = DOWNLOAD_LOG_MESSAGE + url + " has wrong content length (Expected: " + size
+ BUT_GOT_LOG_MESSAGE + response.getEntity().getContentLength() + ")";
LOGGER.error(message);
return message;
}
private static String wrongStatusCode(final String url, final CloseableHttpResponse response) {
final String message = "Download " + url + " failed (" + response.getStatusLine().getStatusCode() + ")";
final String message = DOWNLOAD_LOG_MESSAGE + url + " failed (" + response.getStatusLine().getStatusCode()
+ ")";
LOGGER.error(message);
return message;
}
@@ -339,4 +363,5 @@ public class DeviceSimulatorUpdater {
*/
void updateFinished(AbstractSimulatedDevice device, final Long actionId);
}
}

View File

@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.simulator.amqp;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import org.slf4j.Logger;
@@ -58,7 +59,7 @@ public abstract class SenderService extends MessageService {
}
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
final String correlationId = UUID.randomUUID().toString();
message.getMessageProperties().setCorrelationId(correlationId.getBytes());
message.getMessageProperties().setCorrelationId(correlationId.getBytes(StandardCharsets.UTF_8));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Sending message {} to exchange {} with correlationId {}", message, address, correlationId);

View File

@@ -67,8 +67,6 @@ public class SpReceiverService extends ReceiverService {
* the incoming message
* @param type
* the action type
* @param contentType
* the content type in message header
* @param thingId
* the thing id in message header
*/
@@ -82,14 +80,11 @@ public class SpReceiverService extends ReceiverService {
private void delegateMessage(final Message message, final String type, final String thingId) {
final MessageType messageType = MessageType.valueOf(type);
switch (messageType) {
case EVENT:
if (MessageType.EVENT.equals(messageType)) {
handleEventMessage(message, thingId);
break;
default:
LOGGER.info("No valid message type property.");
break;
return;
}
LOGGER.info("No valid message type property.");
}
private void handleEventMessage(final Message message, final String thingId) {

View File

@@ -33,9 +33,10 @@ import com.vaadin.ui.Window;
* Popup dialog window for setting the values of generating the simulated
* devices, e.g. the amount.
*
* @author Michael Hirsch
*
*/
// Vaadin Inheritance
@SuppressWarnings("squid:MaximumInheritanceDepth")
public class GenerateDialog extends Window {
private static final long serialVersionUID = 1L;
@@ -49,8 +50,8 @@ public class GenerateDialog extends Window {
private final TextField pollDelayTextField;
private final TextField pollUrlTextField;
private final TextField gatewayTokenTextField;
private final OptionGroup protocolGroup;
private final Button buttonOk;
private OptionGroup protocolGroup;
private Button buttonOk;
/**
* Creates a new pop window for setting the configuration of simulating
@@ -87,8 +88,8 @@ public class GenerateDialog extends Window {
gatewayTokenTextField.setColumns(50);
gatewayTokenTextField.setVisible(false);
protocolGroup = createProtocolGroup();
buttonOk = createOkButton(callback);
createProtocolGroup();
createOkButton(callback);
namePrefixTextField.addValueChangeListener(event -> checkValid());
amountTextField.addValueChangeListener(event -> checkValid());
@@ -181,9 +182,9 @@ public class GenerateDialog extends Window {
final URL basePollURL, final String gatewayToken, final Protocol protocol);
}
private OptionGroup createProtocolGroup() {
private void createProtocolGroup() {
final OptionGroup protocolGroup = new OptionGroup("Simulated Device Protocol");
this.protocolGroup = new OptionGroup("Simulated Device Protocol");
protocolGroup.addItem(Protocol.DMF_AMQP);
protocolGroup.addItem(Protocol.DDI_HTTP);
protocolGroup.setItemCaption(Protocol.DMF_AMQP, "Device Management Federation API (AMQP push)");
@@ -195,12 +196,11 @@ public class GenerateDialog extends Window {
pollUrlTextField.setVisible(directDeviceOptionSelected);
gatewayTokenTextField.setVisible(directDeviceOptionSelected);
});
return protocolGroup;
}
private Button createOkButton(final GenerateDialogCallback callback) {
private void createOkButton(final GenerateDialogCallback callback) {
final Button buttonOk = new Button("generate");
this.buttonOk = new Button("generate");
buttonOk.setImmediate(true);
buttonOk.setIcon(FontAwesome.GEARS);
buttonOk.addClickListener(event -> {
@@ -210,14 +210,11 @@ public class GenerateDialog extends Window {
Integer.valueOf(pollDelayTextField.getValue().replace(".", "")),
new URL(pollUrlTextField.getValue()), gatewayTokenTextField.getValue(),
(Protocol) protocolGroup.getValue());
} catch (final NumberFormatException e) {
LOGGER.info(e.getMessage(), e);
} catch (final MalformedURLException e) {
} catch (final NumberFormatException | MalformedURLException e) {
LOGGER.info(e.getMessage(), e);
}
GenerateDialog.this.close();
});
return buttonOk;
}
private TextField createRequiredTextfield(final String caption, final String value, final Resource icon,
@@ -226,7 +223,7 @@ public class GenerateDialog extends Window {
return addTextFieldValues(textField, icon, validator);
}
private TextField createRequiredTextfield(final String caption, final Property dataSource, final Resource icon,
private TextField createRequiredTextfield(final String caption, final Property<?> dataSource, final Resource icon,
final Validator validator) {
final TextField textField = new TextField(caption, dataSource);
return addTextFieldValues(textField, icon, validator);

View File

@@ -57,6 +57,11 @@ import com.vaadin.ui.renderers.ProgressBarRenderer;
@SuppressWarnings("squid:MaximumInheritanceDepth")
public class SimulatorView extends VerticalLayout implements View {
/**
*
*/
private static final String HTML_SPAN = ";</span>";
private static final String NEXT_POLL_COUNTER_SEC_COL = "nextPollCounterSec";
private static final String RESPONSE_STATUS_COL = "updateStatus";
@@ -266,89 +271,90 @@ public class SimulatorView extends VerticalLayout implements View {
}));
}
private Converter<String, Protocol> createProtocolConverter() {
return new Converter<String, Protocol>() {
private static final long serialVersionUID = 1L;
@Override
public Protocol convertToModel(final String value, final Class<? extends Protocol> targetType,
final Locale locale) {
return null;
}
@Override
public String convertToPresentation(final Protocol value, final Class<? extends String> targetType,
final Locale locale) {
switch (value) {
case DDI_HTTP:
return "DDI API (http)";
case DMF_AMQP:
return "DMF API (amqp)";
default:
return "unknown";
}
}
@Override
public Class<Protocol> getModelType() {
return Protocol.class;
}
@Override
public Class<String> getPresentationType() {
return String.class;
}
};
private ProtocolConverter createProtocolConverter() {
return new ProtocolConverter();
}
private Converter<String, Status> createStatusConverter() {
return new Converter<String, Status>() {
private static final long serialVersionUID = 1L;
private StatusConverter createStatusConverter() {
return new StatusConverter();
}
@Override
public Status convertToModel(final String value, final Class<? extends Status> targetType,
final Locale locale) {
return null;
}
public static final class ProtocolConverter implements Converter<String, Protocol> {
private static final long serialVersionUID = 1L;
@Override
public String convertToPresentation(final Status value, final Class<? extends String> targetType,
final Locale locale) {
switch (value) {
case UNKNWON:
return "<span class=\"v-icon grayicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"gray\";\">&#x"
+ Integer.toHexString(FontAwesome.QUESTION_CIRCLE.getCodepoint()) + ";</span>";
case PEDNING:
return "<span class=\"v-icon yellowicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"yellow\";\">&#x" + Integer.toHexString(FontAwesome.REFRESH.getCodepoint())
+ ";</span>";
case FINISH:
return "<span class=\"v-icon greenicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"green\";\">&#x"
+ Integer.toHexString(FontAwesome.CHECK_CIRCLE.getCodepoint()) + ";</span>";
case ERROR:
return "<span class=\"v-icon redicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"red\";\">&#x"
+ Integer.toHexString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()) + ";</span>";
default:
throw new IllegalStateException("unknown value");
}
}
@Override
public Protocol convertToModel(final String value, final Class<? extends Protocol> targetType,
final Locale locale) {
return null;
}
@Override
public Class<Status> getModelType() {
return Status.class;
@Override
public String convertToPresentation(final Protocol value, final Class<? extends String> targetType,
final Locale locale) {
switch (value) {
case DDI_HTTP:
return "DDI API (http)";
case DMF_AMQP:
return "DMF API (amqp)";
default:
return "unknown";
}
}
@Override
public Class<String> getPresentationType() {
return String.class;
@Override
public Class<Protocol> getModelType() {
return Protocol.class;
}
@Override
public Class<String> getPresentationType() {
return String.class;
}
}
private static final class StatusConverter implements Converter<String, Status> {
private static final long serialVersionUID = 1L;
@Override
public Status convertToModel(final String value, final Class<? extends Status> targetType,
final Locale locale) {
return null;
}
@Override
public String convertToPresentation(final Status value, final Class<? extends String> targetType,
final Locale locale) {
switch (value) {
case UNKNWON:
return "<span class=\"v-icon grayicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"gray\";\">&#x" + Integer.toHexString(FontAwesome.QUESTION_CIRCLE.getCodepoint())
+ HTML_SPAN;
case PEDNING:
return "<span class=\"v-icon yellowicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"yellow\";\">&#x" + Integer.toHexString(FontAwesome.REFRESH.getCodepoint())
+ HTML_SPAN;
case FINISH:
return "<span class=\"v-icon greenicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"green\";\">&#x" + Integer.toHexString(FontAwesome.CHECK_CIRCLE.getCodepoint())
+ HTML_SPAN;
case ERROR:
return "<span class=\"v-icon redicon\" style=\"font-family: " + FontAwesome.FONT_FAMILY
+ ";\"color\":\"red\";\">&#x"
+ Integer.toHexString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()) + HTML_SPAN;
default:
throw new IllegalStateException("unknown value");
}
};
}
@Override
public Class<Status> getModelType() {
return Status.class;
}
@Override
public Class<String> getPresentationType() {
return String.class;
}
}
}

View File

@@ -12,9 +12,11 @@ import java.io.File;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import org.apache.commons.io.IOUtils;
/**
*
*
* Look for a free port.
*/
public class FreePortFileWriter {
@@ -24,7 +26,9 @@ public class FreePortFileWriter {
/**
* @param from
* port range from (start point)
* @param to
* port range to (end point)
*/
public FreePortFileWriter(final int from, final int to, final String filePortPath) {
this.from = from;
@@ -46,29 +50,28 @@ public class FreePortFileWriter {
}
boolean isFree(final int port) {
ServerSocket sock = null;
try {
final File portFile = new File(filePortPath + File.separator + port + ".port");
portFile.getParentFile().mkdirs();
if (portFile.exists()) {
return false;
} else {
boolean isFree = false;
final ServerSocket sock = new ServerSocket();
sock.setReuseAddress(true);
sock.bind(new InetSocketAddress(port));
if (portFile.createNewFile()) {
portFile.deleteOnExit();
isFree = true;
}
sock.close();
// is free:
return isFree;
// We rely on an exception thrown to determine availability or
// not availability.
}
} catch (final Exception e) {
// not free.
boolean isFree = false;
sock = new ServerSocket();
sock.setReuseAddress(true);
sock.bind(new InetSocketAddress(port));
if (portFile.createNewFile()) {
portFile.deleteOnExit();
isFree = true;
}
return isFree;
// We rely on an exception thrown to determine availability or
// not availability and don't want to log the exception.
} catch (@SuppressWarnings({ "squid:S2221", "squid:S1166" }) final Exception e) {
return false;
} finally {
IOUtils.closeQuietly(sock);
}
}

View File

@@ -23,7 +23,7 @@ import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
/**
*
* Auto configuration for the event bus.
*
*/
@Configuration

View File

@@ -21,7 +21,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
/**
*
*
* Auto config fot the exception handler.
*/
@Configuration
@EnableAsync

View File

@@ -120,6 +120,8 @@ public class SecurityManagedConfiguration {
*/
@Bean
@ConditionalOnMissingBean
// Exception squid:S00112 - Is aspectJ proxy
@SuppressWarnings({ "squid:S00112" })
public UserAuthenticationFilter userAuthenticationFilter() throws Exception {
return new UserAuthenticationFilterBasicAuth(configuration.getAuthenticationManager());
}

View File

@@ -56,6 +56,10 @@ public class RedisConfiguration {
return new TenantAwareCacheManager(directCacheManager(), tenantAware);
}
/**
*
* @return bean for the direct cache manager.
*/
@Bean(name = "directCacheManager")
public CacheManager directCacheManager() {
return new RedisCacheManager(redisTemplate());

View File

@@ -28,7 +28,7 @@ import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
/**
*
* The distributor for events.
*
*/
@EventSubscriber
@@ -100,11 +100,11 @@ public class EventDistributor {
return topics;
}
private void logDistributingEvent(final Event event, final String channel) {
private static void logDistributingEvent(final Event event, final String channel) {
LOGGER.trace("distributing event {} from node {} to topic {}", event, NODE_ID, channel);
}
private void logNotDistributingEvent(final Event event, final String channel) {
private static void logNotDistributingEvent(final Event event, final String channel) {
LOGGER.debug("no redis template configured, event {} will not be distributed to channel {} from node {}", event,
channel, NODE_ID);
}

View File

@@ -16,9 +16,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*/
@ConfigurationProperties("hawkbit.artifact.url")
public class ArtifactUrlHandlerProperties {
private static final String DEFAULT_IP_LOCALHOST = "127.0.0.1";
private static final String DEFAULT_PORT = "8080";
private static final String LOCALHOST = "localhost";
private final Http http = new Http();
private final Https https = new Https();
@@ -55,227 +52,45 @@ public class ArtifactUrlHandlerProperties {
}
}
/**
* Interface for declaring common properties through all supported protocols
* pattern.
*/
public interface ProtocolProperties {
/**
* @return the hostname value to resolve in the pattern.
*/
String getHostname();
/**
* @return the IP address value to resolve in the pattern.
*/
String getIp();
/**
* @return the port value to resolve in the pattern.
*/
String getPort();
/**
* @return the pattern to build the URL.
*/
String getPattern();
/**
* @return <code>true</code> if the {@link ProtocolProperties} is
* enabled.
*/
boolean isEnabled();
}
/**
* Object to hold the properties for the HTTP protocol.
*/
public static class Http implements ProtocolProperties {
private String hostname = LOCALHOST;
private String ip = DEFAULT_IP_LOCALHOST;
private String port = DEFAULT_PORT;
/**
* An ant-URL pattern with placeholder to build the URL on. The URL can
* have specific artifact placeholder.
*/
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
public static class Http extends DefaultProtocolProperties {
/**
* Enables HTTP URI generation in DDI and DMF.
* Constructor.
*/
private boolean enabled = true;
@Override
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
@Override
public String getHostname() {
return hostname;
}
public void setHostname(final String hostname) {
this.hostname = hostname;
}
@Override
public String getIp() {
return ip;
}
public void setIp(final String ip) {
this.ip = ip;
}
@Override
public String getPattern() {
return pattern;
}
public void setPattern(final String urlPattern) {
this.pattern = urlPattern;
}
@Override
public String getPort() {
return port;
}
public void setPort(final String port) {
this.port = port;
public Http() {
setPattern(
"{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
}
}
/**
* Object to hold the properties for the HTTP protocol.
*/
public static class Https implements ProtocolProperties {
private String hostname = LOCALHOST;
private String ip = DEFAULT_IP_LOCALHOST;
private String port = DEFAULT_PORT;
/**
* An ant-URL pattern with placeholder to build the URL on. The URL can
* have specific artifact placeholder.
*/
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
public static class Https extends DefaultProtocolProperties {
/**
* Enables HTTPS URI generation in DDI and DMF.
* Constructor.
*/
private boolean enabled = true;
@Override
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
@Override
public String getHostname() {
return hostname;
}
public void setHostname(final String hostname) {
this.hostname = hostname;
}
@Override
public String getIp() {
return ip;
}
public void setIp(final String ip) {
this.ip = ip;
}
@Override
public String getPattern() {
return pattern;
}
public void setPattern(final String urlPattern) {
this.pattern = urlPattern;
}
@Override
public String getPort() {
return port;
}
public void setPort(final String port) {
this.port = port;
public Https() {
setPattern(
"{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
}
}
/**
* Object to hold the properties for the HTTP protocol.
*/
public static class Coap implements ProtocolProperties {
private String hostname = LOCALHOST;
private String ip = DEFAULT_IP_LOCALHOST;
private String port = "5683";
/**
* An ant-URL pattern with placeholder to build the URL on. The URL can
* have specific artifact placeholder.
*/
private String pattern = "{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}";
public static class Coap extends DefaultProtocolProperties {
/**
* Enables CoAP URI generation in DMF.
* Constructor.
*/
private boolean enabled = true;
@Override
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
@Override
public String getHostname() {
return hostname;
}
public void setHostname(final String hostname) {
this.hostname = hostname;
}
@Override
public String getIp() {
return ip;
}
public void setIp(final String ip) {
this.ip = ip;
}
@Override
public String getPattern() {
return pattern;
}
public void setPattern(final String urlPattern) {
this.pattern = urlPattern;
}
@Override
public String getPort() {
return port;
}
public void setPort(final String port) {
this.port = port;
public Coap() {
setPattern("{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}");
setPort("5683");
}
}

View File

@@ -0,0 +1,79 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.api;
/**
* Object to hold the properties for the base protocols.
*/
public class DefaultProtocolProperties implements ProtocolProperties {
// The IP address is not hardcoded. It's the default value, if the IP
// address is not configured.
@SuppressWarnings("squid:S1313")
private static final String DEFAULT_IP_LOCALHOST = "127.0.0.1";
private static final String LOCALHOST = "localhost";
private String hostname = LOCALHOST;
private String ip = DEFAULT_IP_LOCALHOST;
private String port = "";
/**
* An ant-URL pattern with placeholder to build the URL on. The URL can have
* specific artifact placeholder.
*/
private String pattern;
/**
* Enables protocol.
*/
private boolean enabled = true;
@Override
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
@Override
public String getHostname() {
return hostname;
}
public void setHostname(final String hostname) {
this.hostname = hostname;
}
@Override
public String getIp() {
return ip;
}
public void setIp(final String ip) {
this.ip = ip;
}
@Override
public String getPattern() {
return pattern;
}
public void setPattern(final String urlPattern) {
this.pattern = urlPattern;
}
@Override
public String getPort() {
return port;
}
public void setPort(final String port) {
this.port = port;
}
}

View File

@@ -13,7 +13,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties.ProtocolProperties;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.api;
/**
* Interface for declaring common properties through all supported protocols
* pattern.
*/
public interface ProtocolProperties {
/**
* @return the hostname value to resolve in the pattern.
*/
String getHostname();
/**
* @return the IP address value to resolve in the pattern.
*/
String getIp();
/**
* @return the port value to resolve in the pattern.
*/
String getPort();
/**
* @return the pattern to build the URL.
*/
String getPattern();
/**
* @return <code>true</code> if the {@link ProtocolProperties} is enabled.
*/
boolean isEnabled();
}

View File

@@ -13,7 +13,7 @@ import org.springframework.cache.CacheManager;
/**
*
*
* A cache interface which handles multi tenancy.
*/
public interface TenancyCacheManager extends CacheManager {

View File

@@ -67,7 +67,7 @@ public class TenantAwareCacheManager implements TenancyCacheManager {
public Collection<String> getCacheNames() {
String currentTenant = tenantAware.getCurrentTenant();
if (currentTenant == null) {
return null;
return Collections.emptyList();
}
currentTenant = currentTenant.toUpperCase();

View File

@@ -17,7 +17,7 @@ import java.net.URI;
*
*
*/
public class CancelTargetAssignmentEvent extends AbstractEvent {
public class CancelTargetAssignmentEvent extends DefaultEvent {
private final String controllerId;
private final Long actionId;

View File

@@ -12,11 +12,10 @@ package org.eclipse.hawkbit.eventbus.event;
* Abstract event definition class which holds the necessary revsion and tenant
* information which every event needs.
*
* @author Michael Hirsch
* @see AbstractDistributedEvent for events which should be distributed to other
* cluster nodes
*/
public class AbstractEvent implements Event {
public class DefaultEvent implements Event {
private final long revision;
private final String tenant;
@@ -27,7 +26,7 @@ public class AbstractEvent implements Event {
* @param tenant
* the tenant of the event
*/
protected AbstractEvent(final long revision, final String tenant) {
protected DefaultEvent(final long revision, final String tenant) {
this.revision = revision;
this.tenant = tenant;
}

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.eventbus.event;
/**
* The event when a target is deleted.
*/
public class TargetDeletedEvent extends AbstractDistributedEvent {
private static final long serialVersionUID = 1L;
private final long targetId;
/**
* @param tenant
* the tenant for this event
* @param targetId
* the ID of the target which has been deleted
*/
public TargetDeletedEvent(final String tenant, final long targetId) {
super(-1, tenant);
this.targetId = targetId;
}
/**
* @return the targetId
*/
public long getTargetId() {
return targetId;
}
}

View File

@@ -15,8 +15,7 @@ package org.eclipse.hawkbit.exception;
* Generic Custom Exception to wrap the Runtime and checked exception
*
*/
public abstract class SpServerRtException extends RuntimeException {
public abstract class AbstractServerRtException extends RuntimeException {
private static final long serialVersionUID = 1L;
@@ -28,7 +27,7 @@ public abstract class SpServerRtException extends RuntimeException {
* @param error
* detail
*/
public SpServerRtException(final SpServerError error) {
public AbstractServerRtException(final SpServerError error) {
super(error.getMessage());
this.error = error;
}
@@ -41,7 +40,7 @@ public abstract class SpServerRtException extends RuntimeException {
* @param error
* detail
*/
public SpServerRtException(final String message, final SpServerError error) {
public AbstractServerRtException(final String message, final SpServerError error) {
super(message);
this.error = error;
}
@@ -56,7 +55,7 @@ public abstract class SpServerRtException extends RuntimeException {
* @param cause
* of the exception
*/
public SpServerRtException(final String message, final SpServerError error, final Throwable cause) {
public AbstractServerRtException(final String message, final SpServerError error, final Throwable cause) {
super(message, cause);
this.error = error;
}
@@ -69,7 +68,7 @@ public abstract class SpServerRtException extends RuntimeException {
* @param cause
* of the exception
*/
public SpServerRtException(final SpServerError error, final Throwable cause) {
public AbstractServerRtException(final SpServerError error, final Throwable cause) {
super(error.getMessage(), cause);
this.error = error;
}

View File

@@ -16,7 +16,7 @@ package org.eclipse.hawkbit.exception;
*
*
*/
public class GenericSpServerException extends SpServerRtException {
public class GenericSpServerException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_GENERIC_ERROR;

View File

@@ -11,11 +11,8 @@ package org.eclipse.hawkbit.repository;
/**
* Sort fields for {@link ActionRest}.
*
*
*
*
*/
public enum ActionFields implements FieldNameProvider,FieldValueConverter<ActionFields> {
public enum ActionFields implements FieldNameProvider, FieldValueConverter<ActionFields> {
/**
* The status field.
@@ -42,13 +39,10 @@ public enum ActionFields implements FieldNameProvider,FieldValueConverter<Action
@Override
public Object convertValue(final ActionFields e, final String value) {
switch (e) {
case STATUS:
if (STATUS.equals(e)) {
return convertStatusValue(value);
default:
return value;
}
return value;
}
private static Object convertStatusValue(final String value) {
@@ -64,11 +58,9 @@ public enum ActionFields implements FieldNameProvider,FieldValueConverter<Action
@Override
public String[] possibleValues(final ActionFields e) {
switch (e) {
case STATUS:
if (STATUS.equals(e)) {
return new String[] { ACTIVE, INACTIVE };
default:
return new String[0];
}
return new String[0];
}
}

View File

@@ -22,7 +22,7 @@ public interface FieldNameProvider {
/**
* Separator for the sub attributes
*/
public static final String SUB_ATTRIBUTE_SEPERATOR = ".";
String SUB_ATTRIBUTE_SEPERATOR = ".";
/**
* @return the string representation of the underlying persistence field
@@ -30,13 +30,24 @@ public interface FieldNameProvider {
*/
String getFieldName();
/**
* Contains the sub entity the given field.
*
* @param propertyField
* the given field
* @return <true> contains <false> contains not
*/
default boolean containsSubEntityAttribute(final String propertyField) {
return FieldNameProvider.containsSubEntityAttribute(propertyField, getSubEntityAttributes());
};
}
/**
*
* @return all sub entities attributes.
*/
default List<String> getSubEntityAttributes() {
return Collections.emptyList();
};
}
/**
* the database column for the key
@@ -59,11 +70,11 @@ public interface FieldNameProvider {
/**
* Is the entity field a {@link Map}.
*
* @return
* @return <true> is a map <false> is not a map
*/
default boolean isMap() {
return getKeyFieldName() != null;
};
}
/**
* Check if a sub attribute exists.

View File

@@ -27,7 +27,7 @@ public final class DurationHelper {
* the defined min/max range.
*
*/
public static class DurationRangeValidator {
public static final class DurationRangeValidator {
final Duration min;
final Duration max;

View File

@@ -9,14 +9,14 @@
package org.eclipse.hawkbit.tenancy.configuration;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* The {@link #InvalidTenantConfigurationKeyException} is thrown when an invalid
* configuration key is used.
*
*/
public class InvalidTenantConfigurationKeyException extends SpServerRtException {
public class InvalidTenantConfigurationKeyException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_CONFIGURATION_KEY_INVALID;

View File

@@ -22,7 +22,7 @@ public interface TenantConfigurationValidator {
* @throws TenantConfigurationValidatorException
* is thrown, when parameter is invalid.
*/
default void validate(final Object tenantConfigurationValue) throws TenantConfigurationValidatorException {
default void validate(final Object tenantConfigurationValue) {
if (tenantConfigurationValue != null
&& validateToClass().isAssignableFrom(tenantConfigurationValue.getClass())) {
return;

View File

@@ -9,14 +9,14 @@
package org.eclipse.hawkbit.tenancy.configuration.validator;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception which is thrown, when the validation of the configuration value has
* not been successful.
*
*/
public class TenantConfigurationValidatorException extends SpServerRtException {
public class TenantConfigurationValidatorException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_CONFIGURATION_VALUE_INVALID;

View File

@@ -27,6 +27,7 @@ public class DdiArtifactHash {
* Default constructor.
*/
public DdiArtifactHash() {
// needed for json create
}
/**

View File

@@ -29,7 +29,7 @@ public class DdiChunk {
private List<DdiArtifact> artifacts;
public DdiChunk() {
// needed for json create
}
/**

View File

@@ -34,8 +34,11 @@ public class DdiConfig {
this.polling = polling;
}
/**
* Constructor.
*/
public DdiConfig() {
// needed for json create.
}
public DdiPolling getPolling() {

View File

@@ -37,7 +37,7 @@ public class DdiControllerBase extends ResourceSupport {
}
public DdiControllerBase() {
// needed for json create
}
public DdiConfig getConfig() {

View File

@@ -23,8 +23,11 @@ public class DdiDeployment {
private List<DdiChunk> chunks;
/**
* Constructor.
*/
public DdiDeployment() {
// needed for json create.
}
/**

View File

@@ -21,10 +21,10 @@ public class DdiDeploymentBase extends ResourceSupport {
@JsonProperty("id")
@NotNull
private String deplyomentId;
private final String deplyomentId;
@NotNull
private DdiDeployment deployment;
private final DdiDeployment deployment;
/**
* Constructor.
@@ -35,14 +35,10 @@ public class DdiDeploymentBase extends ResourceSupport {
* details.
*/
public DdiDeploymentBase(final String id, final DdiDeployment deployment) {
deplyomentId = id;
this.deplyomentId = id;
this.deployment = deployment;
}
public DdiDeploymentBase() {
}
public DdiDeployment getDeployment() {
return deployment;
}

View File

@@ -30,11 +30,15 @@ public class DdiPolling {
* between polls
*/
public DdiPolling(final String sleep) {
super();
this.sleep = sleep;
}
/**
* Constructor.
*
*/
public DdiPolling() {
// needed for json create
}
public String getSleep() {

View File

@@ -60,8 +60,8 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Deployment Action Resource")
public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoDB {
private static final String HTTP_LOCALHOST = "http://localhost:8080/";
private static final String HTTPS_LOCALHOST = "https://localhost:8080/";
private static final String HTTP_LOCALHOST = "http://localhost/";
private static final String HTTPS_LOCALHOST = "https://localhost/";
@Test()
@Description("Ensures that artifacts are not found, when softare module does not exists.")

View File

@@ -36,7 +36,7 @@ import org.springframework.stereotype.Component;
/**
*
*
* A controller which handles the amqp authentfication.
*/
@Component
public class AmqpControllerAuthentfication {

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.amqp;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@@ -137,6 +138,13 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
return onMessage(message, type, tenant, getRabbitTemplate().getConnectionFactory().getVirtualHost());
}
/**
* Executed on a authentication request.
*
* @param message
* the amqp message
* @return the rpc message back to supplier.
*/
@RabbitListener(queues = "${hawkbit.dmf.rabbitmq.authenticationReceiverQueue}", containerFactory = "listenerContainerFactory")
public Message onAuthenticationRequest(final Message message) {
checkContentTypeJson(message);
@@ -152,6 +160,19 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
}
}
/**
* * Executed if a amqp message arrives.
*
* @param message
* the message
* @param type
* the type
* @param tenant
* the tenant
* @param virtualHost
* the virtual host
* @return the rpc message back to supplier.
*/
public Message onMessage(final Message message, final String type, final String tenant, final String virtualHost) {
checkContentTypeJson(message);
final SecurityContext oldContext = SecurityContextHolder.getContext();
@@ -417,7 +438,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
}
private static String convertCorrelationId(final Message message) {
return new String(message.getMessageProperties().getCorrelationId());
return new String(message.getMessageProperties().getCorrelationId(), StandardCharsets.UTF_8);
}
private Action getUpdateActionStatus(final ActionStatus actionStatus) {

View File

@@ -39,16 +39,6 @@ public class BaseAmqpService {
this.rabbitTemplate = rabbitTemplate;
}
/**
* Clean message properties before sending a message.
*
* @param message
* the message to cleaned up
*/
protected void cleanMessageHeaderProperties(final Message message) {
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
}
/**
* Is needed to convert a incoming message to is originally object type.
*
@@ -68,7 +58,7 @@ public class BaseAmqpService {
return (T) rabbitTemplate.getMessageConverter().fromMessage(message);
}
private boolean isMessageBodyEmpty(final Message message) {
private static boolean isMessageBodyEmpty(final Message message) {
return message == null || message.getBody() == null || message.getBody().length == 0;
}
@@ -98,8 +88,7 @@ public class BaseAmqpService {
return rabbitTemplate.getMessageConverter();
}
protected final String getStringHeaderKey(final Message message, final String key,
final String errorMessageIfNull) {
protected String getStringHeaderKey(final Message message, final String key, final String errorMessageIfNull) {
final Map<String, Object> header = message.getMessageProperties().getHeaders();
final Object value = header.get(key);
if (value == null) {
@@ -117,4 +106,15 @@ public class BaseAmqpService {
protected RabbitTemplate getRabbitTemplate() {
return rabbitTemplate;
}
/**
* Clean message properties before sending a message.
*
* @param message
* the message to cleaned up
*/
protected void cleanMessageHeaderProperties(final Message message) {
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
}
}

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.amqp;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import org.eclipse.hawkbit.util.IpUtil;
@@ -46,7 +47,7 @@ public class DefaultAmqpSenderService implements AmqpSenderService {
final String correlationId = UUID.randomUUID().toString();
final String exchange = extractExchange(replyTo);
message.getMessageProperties().setCorrelationId(correlationId.getBytes());
message.getMessageProperties().setCorrelationId(correlationId.getBytes(StandardCharsets.UTF_8));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Sending message {} to exchange {} with correlationId {}", message, exchange, correlationId);

View File

@@ -114,7 +114,7 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication manager without principal")
public void testAuthenticationeBadCredantialsWithoutPricipal() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345"));
FileResource.createFileResourceBySha1("12345"));
try {
authenticationManager.doAuthenticate(securityToken);
fail("BadCredentialsException was excepeted since principal was missing");
@@ -128,7 +128,7 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication manager without wrong credential")
public void testAuthenticationBadCredantialsWithWrongCredential() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345"));
FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE);
@@ -146,7 +146,7 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication successfull")
public void testSuccessfullAuthentication() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345"));
FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE);
@@ -161,7 +161,7 @@ public class AmqpControllerAuthenticationTest {
final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345"));
FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties);
@@ -179,7 +179,7 @@ public class AmqpControllerAuthenticationTest {
public void testAuthenticationMessageBadCredantialsWithWrongCredential() {
final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345"));
FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE);
@@ -201,7 +201,7 @@ public class AmqpControllerAuthenticationTest {
public void testSuccessfullMessageAuthentication() {
final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345"));
FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE);

View File

@@ -279,7 +279,8 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is denied for an artifact which does not exists")
public void authenticationRequestDeniedForArtifactWhichDoesNotExists() {
final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345"));
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123",
FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties);
@@ -297,7 +298,8 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is denied for an artifact which is not assigned to the requested target")
public void authenticationRequestDeniedForArtifactWhichIsNotAssignedToTarget() {
final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345"));
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123",
FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties);
@@ -320,7 +322,8 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is allowed for an artifact which exists and assigned to the requested target")
public void authenticationRequestAllowedForArtifactWhichExistsAndAssignedToTarget() throws MalformedURLException {
final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345"));
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123",
FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties);

View File

@@ -35,8 +35,8 @@ import ru.yandex.qatools.allure.annotations.Stories;
org.eclipse.hawkbit.RepositoryApplicationConfiguration.class })
public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTestWithMongoDB {
private static final String HTTPS_LOCALHOST = "https://localhost:8080/";
private static final String HTTP_LOCALHOST = "http://localhost:8080/";
private static final String HTTPS_LOCALHOST = "https://localhost/";
private static final String HTTP_LOCALHOST = "http://localhost/";
@Autowired
private ArtifactUrlHandler urlHandlerProperties;

View File

@@ -135,7 +135,7 @@ public class TenantSecurityToken {
* the SHA1 key of the file to obtain
* @return the {@link FileResource} with SHA1 key set
*/
public static FileResource sha1(final String sha1) {
public static FileResource createFileResourceBySha1(final String sha1) {
final FileResource resource = new FileResource();
resource.sha1 = sha1;
return resource;
@@ -148,7 +148,7 @@ public class TenantSecurityToken {
* the filename of the file to obtain
* @return the {@link FileResource} with filename set
*/
public static FileResource filename(final String filename) {
public static FileResource createFileResourceByFilename(final String filename) {
final FileResource resource = new FileResource();
resource.filename = filename;
return resource;

View File

@@ -47,7 +47,7 @@ import com.google.common.collect.UnmodifiableIterator;
*/
public abstract class AbstractHttpControllerAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractHttpControllerAuthenticationFilter.class);
private static final Logger LOG = LoggerFactory.getLogger(AbstractHttpControllerAuthenticationFilter.class);
private static final String TENANT_PLACE_HOLDER = "tenant";
private static final String CONTROLLER_ID_PLACE_HOLDER = "controllerId";
@@ -73,10 +73,12 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
/**
* Constructor for sub-classes.
*
* @param systemManagement
* the system management service
* @param tenantConfigurationManagement
* the tenant configuration service
* @param tenantAware
* the tenant aware service
* @param systemSecurityContext
* the system secruity context
*/
public AbstractHttpControllerAuthenticationFilter(final TenantConfigurationManagement tenantConfigurationManagement,
final TenantAware tenantAware, final SystemSecurityContext systemSecurityContext) {
@@ -136,28 +138,28 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
final String requestURI = request.getRequestURI();
if (pathExtractor.match(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI)) {
LOGGER.debug("retrieving principal from URI request {}", requestURI);
LOG.debug("retrieving principal from URI request {}", requestURI);
final Map<String, String> extractUriTemplateVariables = pathExtractor
.extractUriTemplateVariables(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI);
final String controllerId = extractUriTemplateVariables.get(CONTROLLER_ID_PLACE_HOLDER);
final String tenant = extractUriTemplateVariables.get(TENANT_PLACE_HOLDER);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Parsed tenant {} and controllerId {} from path request {}", tenant, controllerId,
if (LOG.isTraceEnabled()) {
LOG.trace("Parsed tenant {} and controllerId {} from path request {}", tenant, controllerId,
requestURI);
}
return createTenantSecruityTokenVariables(request, tenant, controllerId);
} else if (pathExtractor.match(request.getContextPath() + CONTROLLER_DL_REQUEST_ANT_PATTERN, requestURI)) {
LOGGER.debug("retrieving path variables from URI request {}", requestURI);
LOG.debug("retrieving path variables from URI request {}", requestURI);
final Map<String, String> extractUriTemplateVariables = pathExtractor.extractUriTemplateVariables(
request.getContextPath() + CONTROLLER_DL_REQUEST_ANT_PATTERN, requestURI);
final String tenant = extractUriTemplateVariables.get(TENANT_PLACE_HOLDER);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Parsed tenant {} from path request {}", tenant, requestURI);
if (LOG.isTraceEnabled()) {
LOG.trace("Parsed tenant {} from path request {}", tenant, requestURI);
}
return createTenantSecruityTokenVariables(request, tenant, "anonymous");
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("request {} does not match the path pattern {}, request gets ignored", requestURI,
if (LOG.isTraceEnabled()) {
LOG.trace("request {} does not match the path pattern {}, request gets ignored", requestURI,
CONTROLLER_REQUEST_ANT_PATTERN);
}
return null;
@@ -166,7 +168,8 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
private TenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request,
final String tenant, final String controllerId) {
final TenantSecurityToken secruityToken = new TenantSecurityToken(tenant, controllerId, FileResource.sha1(""));
final TenantSecurityToken secruityToken = new TenantSecurityToken(tenant, controllerId,
FileResource.createFileResourceBySha1(""));
final UnmodifiableIterator<String> forEnumeration = Iterators.forEnumeration(request.getHeaderNames());
forEnumeration.forEachRemaining(header -> secruityToken.getHeaders().put(header, request.getHeader(header)));
return secruityToken;

View File

@@ -22,15 +22,11 @@ import org.springframework.util.AntPathMatcher;
* An {@link AuthenticationDetailsSource} implementation which retrieves the
* tenant from a request pattern {@link #TENANT_AWARE_CONTROLLER_PATTERN} and
* stores the retrieved tenant in the {@link TenantAwareAuthenticationDetails}.
*
*
*/
public class ControllerTenantAwareAuthenticationDetailsSource
implements AuthenticationDetailsSource<HttpServletRequest, TenantAwareAuthenticationDetails> {
/**
*
*/
private static final String TENANT_AWARE_CONTROLLER_PATTERN = "/{tenant}/controller/**";
private static final Logger LOGGER = LoggerFactory
.getLogger(ControllerTenantAwareAuthenticationDetailsSource.class);
@@ -38,19 +34,12 @@ public class ControllerTenantAwareAuthenticationDetailsSource
private final AntPathMatcher pathExtractor;
/**
*
*/
* Constructor.
*/
public ControllerTenantAwareAuthenticationDetailsSource() {
pathExtractor = new AntPathMatcher();
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.authentication.AuthenticationDetailsSource#
* buildDetails(java. lang.Object)
*/
@Override
public TenantAwareAuthenticationDetails buildDetails(final HttpServletRequest request) {
return new TenantAwareWebAuthenticationDetails(getTenantFromRequestUri(request), request.getRemoteAddr(), true);

View File

@@ -28,7 +28,7 @@ import org.springframework.security.web.authentication.preauth.AbstractPreAuthen
public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter {
public static final String REQUEST_ID_REGEX_PATTERN = ".*\\/downloadId\\/.*";
private static final Logger LOGGER = LoggerFactory.getLogger(HttpDownloadAuthenticationFilter.class);
private static final Logger LOG = LoggerFactory.getLogger(HttpDownloadAuthenticationFilter.class);
private final Pattern pattern;
private final Cache cache;
@@ -50,7 +50,7 @@ public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedPr
if (!matcher.matches()) {
return null;
}
LOGGER.debug("retrieving id from URI request {}", requestURI);
LOG.debug("retrieving id from URI request {}", requestURI);
final String[] groups = requestURI.split("\\/");
final String id = groups[groups.length - 1];
if (id == null) {

View File

@@ -27,6 +27,7 @@ public class MgmtArtifactHash {
* Default constructor.
*/
public MgmtArtifactHash() {
// used for jackson to instantiate
}
/**

View File

@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
*
*/
@RequestMapping(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
@FunctionalInterface
public interface MgmtDownloadArtifactRestApi {
/**

View File

@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
*
*/
@RequestMapping(MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE)
@FunctionalInterface
public interface MgmtDownloadRestApi {
/**

View File

@@ -15,6 +15,7 @@ import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.cache.CacheConstants;
import org.eclipse.hawkbit.cache.DownloadArtifactCache;
import org.eclipse.hawkbit.cache.DownloadType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadRestApi;
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
import org.slf4j.Logger;
@@ -73,14 +74,11 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
final DownloadArtifactCache artifactCache = (DownloadArtifactCache) cacheWrapper.get();
DbArtifact artifact = null;
switch (artifactCache.getDownloadType()) {
case BY_SHA1:
artifact = artifactRepository.getArtifactBySha1(artifactCache.getId());
break;
default:
if (DownloadType.BY_SHA1.equals(artifactCache.getDownloadType())) {
artifact = artifactRepository.getArtifactBySha1(artifactCache.getId());
} else {
LOGGER.warn("Download Type {} not supported", artifactCache.getDownloadType());
break;
}
if (artifact == null) {

View File

@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
* A mapper which maps repository model to RESTful model representation and
* back.
*/
public class MgmtSystemMapper {
public final class MgmtSystemMapper {
private MgmtSystemMapper() {
// Utility class
@@ -51,6 +51,8 @@ public class MgmtSystemMapper {
* maps a TenantConfigurationValue from the repository model to a
* MgmtSystemTenantConfigurationValue, the RESTful model.
*
* @param key
* the key
* @param repoConfValue
* configuration value as repository model
* @return configuration value as RESTful model

View File

@@ -44,9 +44,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
*/
public interface DistributionSetManagement {
// TODO rename/document the whole with details thing (document what the
// details are and maybe find a better name, e.g. with dependencies?)
/**
* Assigns {@link SoftwareModule} to existing {@link DistributionSet}.
*
@@ -330,7 +327,6 @@ public interface DistributionSetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<DistributionSet> findDistributionSetsAll(Collection<Long> dist);
// TODO discuss: use enum instead of the true,false,null switch ?
/**
* finds all {@link DistributionSet}s.
*

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.eventbus.event;
import org.eclipse.hawkbit.eventbus.event.AbstractEvent;
import org.eclipse.hawkbit.eventbus.event.DefaultEvent;
/**
* Event declaration for the UI to notify the UI that a rollout has been
@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.eventbus.event.AbstractEvent;
* @author Michael Hirsch
*
*/
public class RolloutChangeEvent extends AbstractEvent {
public class RolloutChangeEvent extends DefaultEvent {
private final Long rolloutId;

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.eventbus.event;
import org.eclipse.hawkbit.eventbus.event.AbstractEvent;
import org.eclipse.hawkbit.eventbus.event.DefaultEvent;
/**
* Event declaration for the UI to notify the UI that a rollout has been
@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.eventbus.event.AbstractEvent;
* @author Michael Hirsch
*
*/
public class RolloutGroupChangeEvent extends AbstractEvent {
public class RolloutGroupChangeEvent extends DefaultEvent {
private final Long rolloutId;
private final Long rolloutGroupId;

View File

@@ -11,14 +11,14 @@ package org.eclipse.hawkbit.repository.eventbus.event;
import java.net.URI;
import java.util.Collection;
import org.eclipse.hawkbit.eventbus.event.AbstractEvent;
import org.eclipse.hawkbit.eventbus.event.DefaultEvent;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
/**
* Event that gets sent when a distribution set gets assigned to a target.
*
*/
public class TargetAssignDistributionSetEvent extends AbstractEvent {
public class TargetAssignDistributionSetEvent extends DefaultEvent {
private final Collection<SoftwareModule> softwareModules;
private final String controllerId;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if artifact deletion failed.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public final class ArtifactDeleteFailedException extends SpServerRtException {
public final class ArtifactDeleteFailedException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,14 +9,14 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
*
*
*
*/
public final class ArtifactUploadFailedException extends SpServerRtException {
public final class ArtifactUploadFailedException extends AbstractServerRtException {
/**
*

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if cancelation of actions is performened where the action is not
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public final class CancelActionNotAllowedException extends SpServerRtException {
public final class CancelActionNotAllowedException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* {@link ConcurrentModificationException} is thrown when a given entity in's
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class ConcurrentModificationException extends SpServerRtException {
public class ConcurrentModificationException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_CONCURRENT_MODIFICATION;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if DS creation failed.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public final class DistributionSetCreationFailedMissingMandatoryModuleException extends SpServerRtException {
public final class DistributionSetCreationFailedMissingMandatoryModuleException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -21,7 +21,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType;
*
*
*/
public class DistributionSetTypeUndefinedException extends SpServerRtException {
public class DistributionSetTypeUndefinedException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* the {@link EntityAlreadyExistsException} is thrown when a entity is tried to
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class EntityAlreadyExistsException extends SpServerRtException {
public class EntityAlreadyExistsException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_ALRREADY_EXISTS;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* The {@link EntityLockedException} is thrown when an entity has been locked by
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class EntityLockedException extends SpServerRtException {
public class EntityLockedException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_ENTITY_LOCKED;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* the {@link EntityNotFoundException} is thrown when a entity is tried find but
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class EntityNotFoundException extends SpServerRtException {
public class EntityNotFoundException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_NOT_EXISTS;

View File

@@ -9,13 +9,13 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* the {@link EntityReadOnlyException} is thrown when a entity is in read only
* mode and a user tries to change it.
*/
public class EntityReadOnlyException extends SpServerRtException {
public class EntityReadOnlyException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_READ_ONLY;

View File

@@ -9,14 +9,14 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown when force quitting an actions is not allowed. e.g. the action is not
* active or it is not canceled before.
*
*/
public final class ForceQuitActionNotAllowedException extends SpServerRtException {
public final class ForceQuitActionNotAllowedException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,14 +9,14 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
*
*
*
*/
public final class GridFSDBFileNotFoundException extends SpServerRtException {
public final class GridFSDBFileNotFoundException extends AbstractServerRtException {
/**
*

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if a distribution set is assigned to a a target that is incomplete
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public final class IncompleteDistributionSetException extends SpServerRtException {
public final class IncompleteDistributionSetException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception which is thrown in case the current security context object does
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class InsufficientPermissionException extends SpServerRtException {
public class InsufficientPermissionException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if MD5 checksum check fails.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class InvalidMD5HashException extends SpServerRtException {
public class InvalidMD5HashException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if SHA1 checksum check fails.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class InvalidSHA1HashException extends SpServerRtException {
public class InvalidSHA1HashException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,12 +9,12 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception which is thrown when trying to set an invalid target address.
*/
public class InvalidTargetAddressException extends SpServerRtException {
public class InvalidTargetAddressException extends AbstractServerRtException {
/**
*

View File

@@ -9,13 +9,13 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if a multi part exception occurred.
*
*/
public final class MultiPartFileUploadException extends SpServerRtException {
public final class MultiPartFileUploadException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception used by the REST API in case of RSQL search filter query.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class RSQLParameterSyntaxException extends SpServerRtException {
public class RSQLParameterSyntaxException extends AbstractServerRtException {
/**
*

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception used by the REST API in case of invalid field name in the rsql
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class RSQLParameterUnsupportedFieldException extends SpServerRtException {
public class RSQLParameterUnsupportedFieldException extends AbstractServerRtException {
/**
*

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* the {@link RolloutIllegalStateException} is thrown when a rollout is changing
@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
* rollout, or trying to resume a already finished rollout.
*
*/
public class RolloutIllegalStateException extends SpServerRtException {
public class RolloutIllegalStateException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_ROLLOUT_ILLEGAL_STATE;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* the {@link TenantNotExistException} is thrown when e.g. a controller tries to
@@ -20,7 +20,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class TenantNotExistException extends SpServerRtException {
public class TenantNotExistException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_TENANT_NOT_EXISTS;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if too many status entries have been inserted.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public final class ToManyAttributeEntriesException extends SpServerRtException {
public final class ToManyAttributeEntriesException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if too many status entries have been inserted.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public final class ToManyStatusEntriesException extends SpServerRtException {
public final class ToManyStatusEntriesException extends AbstractServerRtException {
/**
*
*/

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
*
*
*/
public class UnsupportedSoftwareModuleForThisDistributionSetException extends SpServerRtException {
public class UnsupportedSoftwareModuleForThisDistributionSetException extends AbstractServerRtException {
/**
*
*/

View File

@@ -27,43 +27,84 @@ import org.eclipse.hawkbit.repository.model.EntityInterceptor;
*/
public class EntityInterceptorListener {
/**
* Callback for lifecyle event <i>pre persist</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PrePersist
protected void prePersist(final Object entity) {
public void prePersist(final Object entity) {
notifyAll(interceptor -> interceptor.prePersist(entity));
}
/**
* Callback for lifecyle event <i>post persist</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PostPersist
protected void postPersist(final Object entity) {
public void postPersist(final Object entity) {
notifyAll(interceptor -> interceptor.postPersist(entity));
}
/**
* Callback for lifecyle event <i>post remove</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PostRemove
protected void postRemove(final Object entity) {
public void postRemove(final Object entity) {
notifyAll(interceptor -> interceptor.postRemove(entity));
}
/**
* Callback for lifecyle event <i>pre remove</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PreRemove
protected void preRemove(final Object entity) {
public void preRemove(final Object entity) {
notifyAll(interceptor -> interceptor.preRemove(entity));
}
/**
* Callback for lifecyle event <i>post load</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PostLoad
protected void postLoad(final Object entity) {
public void postLoad(final Object entity) {
notifyAll(interceptor -> interceptor.postLoad(entity));
}
/**
* Callback for lifecyle event <i>pre update</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PreUpdate
protected void preUpdate(final Object entity) {
public void preUpdate(final Object entity) {
notifyAll(interceptor -> interceptor.preUpdate(entity));
}
/**
* Callback for lifecyle event <i>post update</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PostUpdate
protected void postUpdate(final Object entity) {
public void postUpdate(final Object entity) {
notifyAll(interceptor -> interceptor.postUpdate(entity));
}
private void notifyAll(final Consumer<? super EntityInterceptor> action) {
private static void notifyAll(final Consumer<? super EntityInterceptor> action) {
EntityInterceptorHolder.getInstance().getEntityInterceptors().forEach(action);
}
}

View File

@@ -17,7 +17,7 @@ import org.hamcrest.Matchers;
/**
* Matcher for {@link BaseEntity}.
*/
public class BaseEntityMatcher {
public final class BaseEntityMatcher {
private BaseEntityMatcher() {
}

View File

@@ -226,7 +226,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
createTestdatabaseAndStart();
}
private static void createTestdatabaseAndStart() {
private static synchronized void createTestdatabaseAndStart() {
if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
tesdatabase = new CIMySqlTestDatabase();
tesdatabase.before();

View File

@@ -14,7 +14,7 @@ import java.net.ServerSocket;
/**
*
*
* Look for a free port.
*/
public class FreePortFileWriter {
@@ -24,7 +24,9 @@ public class FreePortFileWriter {
/**
* @param from
* port range from (start point)
* @param to
* port range to (end point)
*/
public FreePortFileWriter(final int from, final int to, final String filePortPath) {
this.from = from;
@@ -51,25 +53,21 @@ public class FreePortFileWriter {
portFile.getParentFile().mkdirs();
if (portFile.exists()) {
return false;
} else {
boolean isFree = false;
final ServerSocket sock = new ServerSocket();
sock.setReuseAddress(true);
sock.bind(new InetSocketAddress(port));
if (portFile.createNewFile()) {
portFile.deleteOnExit();
isFree = true;
}
sock.close();
// is free:
return isFree;
// We rely on an exception thrown to determine availability or
// not availability.
}
} catch (final Exception e) {
// not free.
boolean isFree = false;
final ServerSocket sock = new ServerSocket();
sock.setReuseAddress(true);
sock.bind(new InetSocketAddress(port));
if (portFile.createNewFile()) {
portFile.deleteOnExit();
isFree = true;
}
sock.close();
return isFree;
// We rely on an exception thrown to determine availability or
// not availability and don't want to log the exception.
} catch (@SuppressWarnings({ "squid:S2221", "squid:S1166" }) final Exception e) {
return false;
}
}
}

View File

@@ -13,11 +13,14 @@ import java.util.List;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
public class JpaTestRepositoryManagement implements TestRepositoryManagement {
private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class);
@Autowired
private TenantAwareCacheManager cacheManager;
@@ -28,6 +31,7 @@ public class JpaTestRepositoryManagement implements TestRepositoryManagement {
private SystemManagement systemManagement;
@Override
@Transactional
public void clearTestRepository() {
deleteAllRepos();
cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear());
@@ -43,7 +47,7 @@ public class JpaTestRepositoryManagement implements TestRepositoryManagement {
return null;
});
} catch (final Exception e) {
e.printStackTrace();
LOGGER.error("Error hile delete tenant", e);
}
});
}

View File

@@ -10,10 +10,10 @@ package org.eclipse.hawkbit.repository.test.util;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
@@ -191,16 +191,17 @@ public class TestdataFactory {
public DistributionSet createDistributionSet(final String prefix, final String version,
final boolean isRequiredMigrationStep) {
final SoftwareModule appMod = softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule(
findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE), prefix + SM_TYPE_APP,
version + "." + new Random().nextInt(100), LOREM.words(20), prefix + " vendor Limited, California"));
final SoftwareModule appMod = softwareManagement.createSoftwareModule(
entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE),
prefix + SM_TYPE_APP, version + "." + new SecureRandom().nextInt(100), LOREM.words(20),
prefix + " vendor Limited, California"));
final SoftwareModule runtimeMod = softwareManagement
.createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_RT),
prefix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20),
prefix + "app runtime", version + "." + new SecureRandom().nextInt(100), LOREM.words(20),
prefix + " vendor GmbH, Stuttgart, Germany"));
final SoftwareModule osMod = softwareManagement
.createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_OS),
prefix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20),
prefix + " Firmware", version + "." + new SecureRandom().nextInt(100), LOREM.words(20),
prefix + " vendor Limited Inc, California"));
return distributionSetManagement

View File

@@ -16,7 +16,6 @@ import java.util.List;
import java.util.concurrent.Callable;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder;
import org.junit.rules.TestRule;
@@ -29,16 +28,12 @@ import org.springframework.security.core.context.SecurityContextHolder;
public class WithSpringAuthorityRule implements TestRule {
/*
* (non-Javadoc)
*
* @see org.junit.rules.TestRule#apply(org.junit.runners.model.Statement,
* org.junit.runner.Description)
*/
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
// throwable comes from jnuit evaluate signature
@SuppressWarnings("squid:S00112")
public void evaluate() throws Throwable {
final SecurityContext oldContext = before(description);
try {
@@ -50,7 +45,7 @@ public class WithSpringAuthorityRule implements TestRule {
};
}
private SecurityContext before(final Description description) throws Throwable {
private SecurityContext before(final Description description) {
final SecurityContext oldContext = SecurityContextHolder.getContext();
WithUser annotation = description.getAnnotation(WithUser.class);
if (annotation == null) {
@@ -64,19 +59,14 @@ public class WithSpringAuthorityRule implements TestRule {
}
return oldContext;
}
/**
* @param annotation
*/
private void setSecurityContext(final WithUser annotation) {
SecurityContextHolder.setContext(new SecurityContext() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void setAuthentication(final Authentication authentication) {
// nothing todo
}
@Override
@@ -114,7 +104,8 @@ public class WithSpringAuthorityRule implements TestRule {
if (addPermission) {
allPermissions.add(permissionName);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
// don't want to log this exceptions.
} catch (@SuppressWarnings("squid:S1166") IllegalArgumentException | IllegalAccessException e) {
// nope
}
}
@@ -130,18 +121,17 @@ public class WithSpringAuthorityRule implements TestRule {
private void after(final SecurityContext oldContext) {
SecurityContextHolder.setContext(oldContext);
}
/**
* Clears the current security context.
*/
public void clear()
{
public void clear() {
SecurityContextHolder.clearContext();
}
/**
* @param callable
* @return
* @return the callable result
* @throws Exception
*/
public <T> T runAsPrivileged(final Callable<T> callable) throws Exception {
@@ -149,10 +139,10 @@ public class WithSpringAuthorityRule implements TestRule {
}
/**
*
*
* @param withUser
* @param callable
* @return
* @return callable result
* @throws Exception
*/
public <T> T runAs(final WithUser withUser, final Callable<T> callable) throws Exception {
@@ -167,15 +157,13 @@ public class WithSpringAuthorityRule implements TestRule {
after(oldContext);
}
}
private void createTenant(final String tenantId) throws Exception {
private void createTenant(final String tenantId) {
final SecurityContext oldContext = SecurityContextHolder.getContext();
setSecurityContext(privilegedUser());
try
{
try {
SystemManagementHolder.getInstance().getSystemManagement().getTenantMetadata(tenantId);
}finally
{
} finally {
after(oldContext);
}
}
@@ -183,7 +171,7 @@ public class WithSpringAuthorityRule implements TestRule {
public static WithUser withUser(final String principal, final String... authorities) {
return withUserAndTenant(principal, "default", true, true, authorities);
}
public static WithUser withUser(final String principal, final boolean allSpPermision, final String... authorities) {
return withUserAndTenant(principal, "default", true, allSpPermision, authorities);
}
@@ -198,6 +186,15 @@ public class WithSpringAuthorityRule implements TestRule {
public static WithUser withUserAndTenant(final String principal, final String tenant,
final boolean autoCreateTenant, final boolean allSpPermission, final String... authorities) {
return createWithUser(principal, tenant, autoCreateTenant, allSpPermission, authorities);
}
private static WithUser privilegedUser() {
return createWithUser("bumlux", "default", true, true, new String[] { "ROLE_CONTROLLER", "ROLE_SYSTEM_CODE" });
}
private static WithUser createWithUser(final String principal, final String tenant, final boolean autoCreateTenant,
final boolean allSpPermission, final String... authorities) {
return new WithUser() {
@Override
@@ -227,7 +224,7 @@ public class WithSpringAuthorityRule implements TestRule {
@Override
public String[] removeFromAllPermission() {
return null;
return new String[0];
}
@Override
@@ -235,65 +232,10 @@ public class WithSpringAuthorityRule implements TestRule {
return tenant;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.WithUser#autoCreateTenant()
*/
@Override
public boolean autoCreateTenant() {
return autoCreateTenant;
}
};
}
private static WithUser privilegedUser() {
return new WithUser() {
@Override
public Class<? extends Annotation> annotationType() {
return WithUser.class;
}
@Override
public String principal() {
return "bumlux";
}
@Override
public String credentials() {
return null;
}
@Override
public String[] authorities() {
return new String[] { "ROLE_CONTROLLER", "ROLE_SYSTEM_CODE" };
}
@Override
public boolean allSpPermissions() {
return true;
}
@Override
public String[] removeFromAllPermission() {
return null;
}
@Override
public String tenantId() {
return "default";
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.WithUser#autoCreateTenant()
*/
@Override
public boolean autoCreateTenant() {
return true;
}
};
}
}

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.rest.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception which is thrown in case an request body is not well formaned and
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class MessageNotReadableException extends SpServerRtException {
public class MessageNotReadableException extends AbstractServerRtException {
/**
*

View File

@@ -16,7 +16,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.repository.exception.MultiPartFileUploadException;
import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
import org.slf4j.Logger;
@@ -75,7 +75,7 @@ public class ResponseExceptionHandler {
}
/**
* method for handling exception of type SpServerRtException. Called by the
* method for handling exception of type AbstractServerRtException. Called by the
* Spring-Framework for exception handling.
*
* @param request
@@ -86,14 +86,14 @@ public class ResponseExceptionHandler {
* @return the entity to be responded containing the exception information
* as entity.
*/
@ExceptionHandler(SpServerRtException.class)
@ExceptionHandler(AbstractServerRtException.class)
public ResponseEntity<ExceptionInfo> handleSpServerRtExceptions(final HttpServletRequest request,
final Exception ex) {
logRequest(request, ex);
final ExceptionInfo response = createExceptionInfo(ex);
final HttpStatus responseStatus;
if (ex instanceof SpServerRtException) {
responseStatus = getStatusOrDefault(((SpServerRtException) ex).getError());
if (ex instanceof AbstractServerRtException) {
responseStatus = getStatusOrDefault(((AbstractServerRtException) ex).getError());
} else {
responseStatus = DEFAULT_RESPONSE_STATUS;
}
@@ -152,8 +152,8 @@ public class ResponseExceptionHandler {
final ExceptionInfo response = new ExceptionInfo();
response.setMessage(ex.getMessage());
response.setExceptionClass(ex.getClass().getName());
if (ex instanceof SpServerRtException) {
response.setErrorCode(((SpServerRtException) ex).getError().getKey());
if (ex instanceof AbstractServerRtException) {
response.setErrorCode(((AbstractServerRtException) ex).getError().getKey());
}
return response;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.rest.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception used by the REST API in case of invalid sort parameter syntax.
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class SortParameterSyntaxErrorException extends SpServerRtException {
public class SortParameterSyntaxErrorException extends AbstractServerRtException {
/**
*

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.rest.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception used by the REST API in case of invalid sort parameter direction
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class SortParameterUnsupportedDirectionException extends SpServerRtException {
public class SortParameterUnsupportedDirectionException extends AbstractServerRtException {
/**
*

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.rest.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Exception used by the REST API in case of invalid field name in the sort
@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.exception.SpServerRtException;
*
*
*/
public class SortParameterUnsupportedFieldException extends SpServerRtException {
public class SortParameterUnsupportedFieldException extends AbstractServerRtException {
/**
*

View File

@@ -69,13 +69,10 @@ public class ByteRange {
return total;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() { // NOSONAR - as this is generated
// NOSONAR - as this is generated
@SuppressWarnings("squid:S864")
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (end ^ end >>> 32);
@@ -85,11 +82,6 @@ public class ByteRange {
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated
if (this == obj) {

View File

@@ -9,12 +9,12 @@
package org.eclipse.hawkbit.rest.util;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
/**
* Thrown if artifact content streaming to client failed.
*/
public final class FileSteamingFailedException extends SpServerRtException {
public final class FileSteamingFailedException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;

View File

@@ -185,18 +185,22 @@ public final class SpPermission {
field.setAccessible(true);
try {
final String role = (String) field.get(null);
if (!(exclusionRoles.contains(role))) {
allPermissions.add(role);
}
addIfNotExcluded(exclusionRoles, allPermissions, role);
} catch (final IllegalAccessException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
return allPermissions;
}
private static void addIfNotExcluded(final Collection<String> exclusionRoles, final List<String> allPermissions,
final String role) {
if (!(exclusionRoles.contains(role))) {
allPermissions.add(role);
}
}
/**
* Contains all the spring security evaluation expressions for the
* {@link PreAuthorize} annotation for method security.

View File

@@ -51,7 +51,9 @@ public interface UserAuthenticationFilter {
* @throws ServletException
* servlet exception
*/
// this declaration of multiple checked exception is necessary so it's
// aligned with the servlet API.
@SuppressWarnings("squid:S1160")
void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException;

View File

@@ -28,11 +28,6 @@ import org.springframework.security.core.context.SecurityContextImpl;
*/
public class SecurityContextTenantAware implements TenantAware {
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.tenancy.TenantAware#getCurrentTenantId()
*/
@Override
public String getCurrentTenant() {
final SecurityContext context = SecurityContextHolder.getContext();
@@ -56,7 +51,7 @@ public class SecurityContextTenantAware implements TenantAware {
}
}
private SecurityContext buildSecurityContext(final String tenant) {
private static SecurityContext buildSecurityContext(final String tenant) {
final SecurityContextImpl securityContext = new SecurityContextImpl();
securityContext.setAuthentication(
new AuthenticationDelegate(SecurityContextHolder.getContext().getAuthentication(), tenant));
@@ -68,7 +63,7 @@ public class SecurityContextTenantAware implements TenantAware {
* {@link Authentication} object except setting the details specifically for
* a specific tenant.
*/
private class AuthenticationDelegate implements Authentication {
private static final class AuthenticationDelegate implements Authentication {
private static final long serialVersionUID = 1L;
private final Authentication delegate;

View File

@@ -29,12 +29,12 @@ import org.springframework.stereotype.Service;
import com.google.common.base.Throwables;
/**
*
* A Service which provide to run system code.
*/
@Service
public class SystemSecurityContext {
private static final Logger logger = LoggerFactory.getLogger(SystemSecurityContext.class);
private static final Logger LOG = LoggerFactory.getLogger(SystemSecurityContext.class);
private final TenantAware tenantAware;
@@ -96,19 +96,21 @@ public class SystemSecurityContext {
public <T> T runAsSystemAsTenant(final Callable<T> callable, final String tenant) {
final SecurityContext oldContext = SecurityContextHolder.getContext();
try {
logger.debug("entering system code execution");
LOG.debug("entering system code execution");
return tenantAware.runAsTenant(tenant, () -> {
try {
setSystemContext(SecurityContextHolder.getContext());
return callable.call();
} catch (final Exception e) {
// The callable API throws a Exception and not a specific
// one
} catch (@SuppressWarnings("squid:S2221") final Exception e) {
throw Throwables.propagate(e);
}
});
} finally {
SecurityContextHolder.setContext(oldContext);
logger.debug("leaving system code execution");
LOG.debug("leaving system code execution");
}
}
@@ -134,7 +136,7 @@ public class SystemSecurityContext {
* {@link SpringEvalExpressions#SYSTEM_ROLE} which is allowed to execute all
* secured methods.
*/
public static class SystemCodeAuthentication implements Authentication {
public static final class SystemCodeAuthentication implements Authentication {
private static final long serialVersionUID = 1L;
private static final List<SimpleGrantedAuthority> AUTHORITIES = Collections

Some files were not shown because too many files have changed in this diff Show More