Rename DMF model classes to avoid name clashes with the repository.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
kaizimmerm
2017-05-16 16:57:07 +02:00
parent cacb32da1a
commit 806491d9b5
33 changed files with 271 additions and 274 deletions

View File

@@ -31,8 +31,8 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContextBuilder; import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.eclipse.hawkbit.dmf.json.model.Artifact; import org.eclipse.hawkbit.dmf.json.model.DmfArtifact;
import org.eclipse.hawkbit.dmf.json.model.SoftwareModule; import org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule;
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol; import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
import org.eclipse.hawkbit.simulator.UpdateStatus.ResponseStatus; import org.eclipse.hawkbit.simulator.UpdateStatus.ResponseStatus;
import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.eclipse.hawkbit.simulator.amqp.SpSenderService;
@@ -94,7 +94,7 @@ public class DeviceSimulatorUpdater {
* process has been finished * process has been finished
*/ */
public void startUpdate(final String tenant, final String id, final long actionId, final String swVersion, public void startUpdate(final String tenant, final String id, final long actionId, final String swVersion,
final List<SoftwareModule> modules, final String targetSecurityToken, final UpdaterCallback callback) { final List<DmfSoftwareModule> modules, final String targetSecurityToken, final UpdaterCallback callback) {
AbstractSimulatedDevice device = repository.get(tenant, id); AbstractSimulatedDevice device = repository.get(tenant, id);
// plug and play - non existing device will be auto created // plug and play - non existing device will be auto created
@@ -109,7 +109,7 @@ public class DeviceSimulatorUpdater {
device.setSwversion(swVersion); device.setSwversion(swVersion);
} else { } else {
device.setSwversion( device.setSwversion(
modules.stream().map(SoftwareModule::getModuleVersion).collect(Collectors.joining(", "))); modules.stream().map(DmfSoftwareModule::getModuleVersion).collect(Collectors.joining(", ")));
} }
device.setTargetSecurityToken(targetSecurityToken); device.setTargetSecurityToken(targetSecurityToken);
eventbus.post(new InitUpdate(device)); eventbus.post(new InitUpdate(device));
@@ -134,11 +134,11 @@ public class DeviceSimulatorUpdater {
private final EventBus eventbus; private final EventBus eventbus;
private final ScheduledExecutorService threadPool; private final ScheduledExecutorService threadPool;
private final UpdaterCallback callback; private final UpdaterCallback callback;
private final List<SoftwareModule> modules; private final List<DmfSoftwareModule> modules;
private DeviceSimulatorUpdateThread(final AbstractSimulatedDevice device, final SpSenderService spSenderService, private DeviceSimulatorUpdateThread(final AbstractSimulatedDevice device, final SpSenderService spSenderService,
final long actionId, final EventBus eventbus, final ScheduledExecutorService threadPool, final long actionId, final EventBus eventbus, final ScheduledExecutorService threadPool,
final UpdaterCallback callback, final List<SoftwareModule> modules) { final UpdaterCallback callback, final List<DmfSoftwareModule> modules) {
this.device = device; this.device = device;
this.spSenderService = spSenderService; this.spSenderService = spSenderService;
this.actionId = actionId; this.actionId = actionId;
@@ -204,7 +204,7 @@ public class DeviceSimulatorUpdater {
} }
private static void handleArtifact(final String targetToken, final List<UpdateStatus> status, private static void handleArtifact(final String targetToken, final List<UpdateStatus> status,
final Artifact artifact) { final DmfArtifact artifact) {
if (artifact.getUrls().containsKey("HTTPS")) { if (artifact.getUrls().containsKey("HTTPS")) {
status.add(downloadUrl(artifact.getUrls().get("HTTPS"), targetToken, artifact.getHashes().getSha1(), status.add(downloadUrl(artifact.getUrls().get("HTTPS"), targetToken, artifact.getHashes().getSha1(),

View File

@@ -13,7 +13,7 @@ import java.util.Map;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
import org.eclipse.hawkbit.simulator.DeviceSimulatorRepository; import org.eclipse.hawkbit.simulator.DeviceSimulatorRepository;
import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater; import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -141,8 +141,8 @@ public class SpReceiverService extends ReceiverService {
final Map<String, Object> headers = messageProperties.getHeaders(); final Map<String, Object> headers = messageProperties.getHeaders();
final String tenant = (String) headers.get(MessageHeaderKey.TENANT); final String tenant = (String) headers.get(MessageHeaderKey.TENANT);
final DownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(message, final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(message,
DownloadAndUpdateRequest.class); DmfDownloadAndUpdateRequest.class);
final Long actionId = downloadAndUpdateRequest.getActionId(); final Long actionId = downloadAndUpdateRequest.getActionId();
final String targetSecurityToken = downloadAndUpdateRequest.getTargetSecurityToken(); final String targetSecurityToken = downloadAndUpdateRequest.getTargetSecurityToken();

View File

@@ -16,9 +16,9 @@ import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.ActionStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionStatus;
import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionUpdateStatus;
import org.eclipse.hawkbit.dmf.json.model.AttributeUpdate; import org.eclipse.hawkbit.dmf.json.model.DmfAttributeUpdate;
import org.eclipse.hawkbit.simulator.SimulationProperties; import org.eclipse.hawkbit.simulator.SimulationProperties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -66,7 +66,7 @@ public class SpSenderService extends SenderService {
* a description according the update process * a description according the update process
*/ */
public void finishUpdateProcess(final SimulatedUpdate update, final List<String> updateResultMessages) { public void finishUpdateProcess(final SimulatedUpdate update, final List<String> updateResultMessages) {
final Message updateResultMessage = createUpdateResultMessage(update, ActionStatus.FINISHED, final Message updateResultMessage = createUpdateResultMessage(update, DmfActionStatus.FINISHED,
updateResultMessages); updateResultMessages);
sendMessage(spExchange, updateResultMessage); sendMessage(spExchange, updateResultMessage);
} }
@@ -96,7 +96,7 @@ public class SpSenderService extends SenderService {
* the ID of the action for the error message * the ID of the action for the error message
*/ */
public void sendErrorMessage(final String tenant, final List<String> updateResultMessages, final Long actionId) { public void sendErrorMessage(final String tenant, final List<String> updateResultMessages, final Long actionId) {
final Message message = createActionStatusMessage(tenant, ActionStatus.ERROR, updateResultMessages, actionId); final Message message = createActionStatusMessage(tenant, DmfActionStatus.ERROR, updateResultMessages, actionId);
sendMessage(spExchange, message); sendMessage(spExchange, message);
} }
@@ -109,7 +109,7 @@ public class SpSenderService extends SenderService {
* a warning description * a warning description
*/ */
public void sendWarningMessage(final SimulatedUpdate update, final List<String> updateResultMessages) { public void sendWarningMessage(final SimulatedUpdate update, final List<String> updateResultMessages) {
final Message message = createActionStatusMessage(update, updateResultMessages, ActionStatus.WARNING); final Message message = createActionStatusMessage(update, updateResultMessages, DmfActionStatus.WARNING);
sendMessage(spExchange, message); sendMessage(spExchange, message);
} }
@@ -125,7 +125,7 @@ public class SpSenderService extends SenderService {
* @param actionId * @param actionId
* the cached value * the cached value
*/ */
public void sendActionStatusMessage(final String tenant, final ActionStatus actionStatus, public void sendActionStatusMessage(final String tenant, final DmfActionStatus actionStatus,
final List<String> updateResultMessages, final Long actionId) { final List<String> updateResultMessages, final Long actionId) {
final Message message = createActionStatusMessage(tenant, actionStatus, updateResultMessages, actionId); final Message message = createActionStatusMessage(tenant, actionStatus, updateResultMessages, actionId);
sendMessage(message); sendMessage(message);
@@ -179,7 +179,7 @@ public class SpSenderService extends SenderService {
messagePropertiesForSP.setHeader(MessageHeaderKey.THING_ID, targetId); messagePropertiesForSP.setHeader(MessageHeaderKey.THING_ID, targetId);
messagePropertiesForSP.setContentType(MessageProperties.CONTENT_TYPE_JSON); messagePropertiesForSP.setContentType(MessageProperties.CONTENT_TYPE_JSON);
messagePropertiesForSP.setReplyTo(amqpProperties.getSenderForSpExchange()); messagePropertiesForSP.setReplyTo(amqpProperties.getSenderForSpExchange());
final AttributeUpdate attributeUpdate = new AttributeUpdate(); final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
attributeUpdate.getAttributes().putAll(simulationProperties.getAttributes().stream().collect( attributeUpdate.getAttributes().putAll(simulationProperties.getAttributes().stream().collect(
Collectors.toMap(SimulationProperties.Attribute::getKey, SimulationProperties.Attribute::getValue))); Collectors.toMap(SimulationProperties.Attribute::getKey, SimulationProperties.Attribute::getValue)));
@@ -206,7 +206,7 @@ public class SpSenderService extends SenderService {
* a list of descriptions according the update process * a list of descriptions according the update process
*/ */
private void sendErrorgMessage(final SimulatedUpdate update, final List<String> updateResultMessages) { private void sendErrorgMessage(final SimulatedUpdate update, final List<String> updateResultMessages) {
final Message message = createActionStatusMessage(update, updateResultMessages, ActionStatus.ERROR); final Message message = createActionStatusMessage(update, updateResultMessages, DmfActionStatus.ERROR);
sendMessage(spExchange, message); sendMessage(spExchange, message);
} }
@@ -222,11 +222,11 @@ public class SpSenderService extends SenderService {
* @param cacheValue * @param cacheValue
* the cacheValue value * the cacheValue value
*/ */
private Message createActionStatusMessage(final String tenant, final ActionStatus actionStatus, private Message createActionStatusMessage(final String tenant, final DmfActionStatus actionStatus,
final List<String> updateResultMessages, final Long actionId) { final List<String> updateResultMessages, final Long actionId) {
final MessageProperties messageProperties = new MessageProperties(); final MessageProperties messageProperties = new MessageProperties();
final Map<String, Object> headers = messageProperties.getHeaders(); final Map<String, Object> headers = messageProperties.getHeaders();
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(actionId, actionStatus); final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(actionId, actionStatus);
headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name()); headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name());
headers.put(MessageHeaderKey.TENANT, tenant); headers.put(MessageHeaderKey.TENANT, tenant);
headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
@@ -236,11 +236,11 @@ public class SpSenderService extends SenderService {
return convertMessage(actionUpdateStatus, messageProperties); return convertMessage(actionUpdateStatus, messageProperties);
} }
private Message createUpdateResultMessage(final SimulatedUpdate cacheValue, final ActionStatus actionStatus, private Message createUpdateResultMessage(final SimulatedUpdate cacheValue, final DmfActionStatus actionStatus,
final List<String> updateResultMessages) { final List<String> updateResultMessages) {
final MessageProperties messageProperties = new MessageProperties(); final MessageProperties messageProperties = new MessageProperties();
final Map<String, Object> headers = messageProperties.getHeaders(); final Map<String, Object> headers = messageProperties.getHeaders();
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(cacheValue.getActionId(), actionStatus); final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(cacheValue.getActionId(), actionStatus);
headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name()); headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name());
headers.put(MessageHeaderKey.TENANT, cacheValue.getTenant()); headers.put(MessageHeaderKey.TENANT, cacheValue.getTenant());
headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
@@ -250,7 +250,7 @@ public class SpSenderService extends SenderService {
} }
private Message createActionStatusMessage(final SimulatedUpdate update, final List<String> updateResultMessages, private Message createActionStatusMessage(final SimulatedUpdate update, final List<String> updateResultMessages,
final ActionStatus status) { final DmfActionStatus status) {
return createActionStatusMessage(update.getTenant(), status, updateResultMessages, update.getActionId()); return createActionStatusMessage(update.getTenant(), status, updateResultMessages, update.getActionId());
} }

View File

@@ -18,14 +18,15 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
import org.eclipse.hawkbit.cache.DownloadArtifactCache; import org.eclipse.hawkbit.cache.DownloadArtifactCache;
import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.cache.DownloadIdCache;
import org.eclipse.hawkbit.cache.DownloadType; import org.eclipse.hawkbit.cache.DownloadType;
import org.eclipse.hawkbit.dmf.json.model.Artifact; import org.eclipse.hawkbit.dmf.json.model.DmfArtifact;
import org.eclipse.hawkbit.dmf.json.model.ArtifactHash; import org.eclipse.hawkbit.dmf.json.model.DmfArtifactHash;
import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadResponse;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpRejectAndDontRequeueException; import org.springframework.amqp.AmqpRejectAndDontRequeueException;
@@ -120,7 +121,7 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
* of the artifact to verify if the given target is allowed to * of the artifact to verify if the given target is allowed to
* download it * download it
*/ */
private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, final String sha1Hash) { private void checkIfArtifactIsAssignedToTarget(final DmfTenantSecurityToken secruityToken, final String sha1Hash) {
if (secruityToken.getControllerId() != null) { if (secruityToken.getControllerId() != null) {
checkByControllerId(sha1Hash, secruityToken.getControllerId()); checkByControllerId(sha1Hash, secruityToken.getControllerId());
@@ -154,8 +155,7 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
LOG.info("download security check for target {} and artifact {} granted", controllerId, sha1Hash); LOG.info("download security check for target {} and artifact {} granted", controllerId, sha1Hash);
} }
private Optional<org.eclipse.hawkbit.repository.model.Artifact> findArtifactByFileResource( private Optional<Artifact> findArtifactByFileResource(final FileResource fileResource) {
final FileResource fileResource) {
if (fileResource == null) { if (fileResource == null) {
return Optional.empty(); return Optional.empty();
@@ -182,29 +182,28 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
return Optional.empty(); return Optional.empty();
} }
private static Artifact convertDbArtifact(final DbArtifact dbArtifact) { private static DmfArtifact convertDbArtifact(final DbArtifact dbArtifact) {
final Artifact artifact = new Artifact(); final DmfArtifact artifact = new DmfArtifact();
artifact.setSize(dbArtifact.getSize()); artifact.setSize(dbArtifact.getSize());
final DbArtifactHash dbArtifactHash = dbArtifact.getHashes(); final DbArtifactHash dbArtifactHash = dbArtifact.getHashes();
artifact.setHashes(new ArtifactHash(dbArtifactHash.getSha1(), dbArtifactHash.getMd5())); artifact.setHashes(new DmfArtifactHash(dbArtifactHash.getSha1(), dbArtifactHash.getMd5()));
return artifact; return artifact;
} }
private Message handleAuthenticationMessage(final Message message) { private Message handleAuthenticationMessage(final Message message) {
final DownloadResponse authentificationResponse = new DownloadResponse(); final DmfDownloadResponse authentificationResponse = new DmfDownloadResponse();
final TenantSecurityToken secruityToken = convertMessage(message, TenantSecurityToken.class); final DmfTenantSecurityToken secruityToken = convertMessage(message, DmfTenantSecurityToken.class);
final FileResource fileResource = secruityToken.getFileResource(); final FileResource fileResource = secruityToken.getFileResource();
try { try {
SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthenticate(secruityToken)); SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthenticate(secruityToken));
final String sha1Hash = findArtifactByFileResource(fileResource) final String sha1Hash = findArtifactByFileResource(fileResource).map(Artifact::getSha1Hash)
.map(org.eclipse.hawkbit.repository.model.Artifact::getSha1Hash) .orElseThrow(EntityNotFoundException::new);
.orElseThrow(() -> new EntityNotFoundException());
checkIfArtifactIsAssignedToTarget(secruityToken, sha1Hash); checkIfArtifactIsAssignedToTarget(secruityToken, sha1Hash);
final Artifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(sha1Hash).orElseThrow( final DmfArtifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(sha1Hash)
() -> new EntityNotFoundException(org.eclipse.hawkbit.repository.model.Artifact.class, sha1Hash))); .orElseThrow(() -> new EntityNotFoundException(Artifact.class, sha1Hash)));
authentificationResponse.setArtifact(artifact); authentificationResponse.setArtifact(artifact);
final String downloadId = UUID.randomUUID().toString(); final String downloadId = UUID.randomUUID().toString();

View File

@@ -12,7 +12,7 @@ import java.util.List;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
@@ -121,7 +121,7 @@ public class AmqpControllerAuthentication {
* the authentication request object * the authentication request object
* @return the authentication object * @return the authentication object
*/ */
public Authentication doAuthenticate(final TenantSecurityToken securityToken) { public Authentication doAuthenticate(final DmfTenantSecurityToken securityToken) {
resolveTenant(securityToken); resolveTenant(securityToken);
PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(null, null); PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(null, null);
for (final PreAuthentificationFilter filter : filterChain) { for (final PreAuthentificationFilter filter : filterChain) {
@@ -136,7 +136,7 @@ public class AmqpControllerAuthentication {
} }
private void resolveTenant(final TenantSecurityToken securityToken) { private void resolveTenant(final DmfTenantSecurityToken securityToken) {
if (securityToken.getTenant() == null) { if (securityToken.getTenant() == null) {
securityToken.setTenant(systemSecurityContext securityToken.setTenant(systemSecurityContext
.runAsSystem(() -> systemManagement.getTenantMetadata(securityToken.getTenantId()).getTenant())); .runAsSystem(() -> systemManagement.getTenantMetadata(securityToken.getTenantId()).getTenant()));
@@ -145,7 +145,7 @@ public class AmqpControllerAuthentication {
} }
private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthentificationFilter filter, private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthentificationFilter filter,
final TenantSecurityToken secruityToken) { final DmfTenantSecurityToken secruityToken) {
if (!filter.isEnable(secruityToken)) { if (!filter.isEnable(secruityToken)) {
return null; return null;

View File

@@ -22,15 +22,17 @@ import org.eclipse.hawkbit.api.URLPlaceholder.SoftwareData;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.Artifact; import org.eclipse.hawkbit.dmf.json.model.DmfArtifact;
import org.eclipse.hawkbit.dmf.json.model.ArtifactHash; import org.eclipse.hawkbit.dmf.json.model.DmfArtifactHash;
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
import org.eclipse.hawkbit.dmf.json.model.SoftwareModule; import org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.util.IpUtil; import org.eclipse.hawkbit.util.IpUtil;
@@ -117,21 +119,21 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
} }
void sendUpdateMessageToTarget(final String tenant, final Target target, final Long actionId, void sendUpdateMessageToTarget(final String tenant, final Target target, final Long actionId,
final Collection<org.eclipse.hawkbit.repository.model.SoftwareModule> modules) { final Collection<SoftwareModule> modules) {
final URI targetAdress = target.getAddress(); final URI targetAdress = target.getAddress();
if (!IpUtil.isAmqpUri(targetAdress)) { if (!IpUtil.isAmqpUri(targetAdress)) {
return; return;
} }
final DownloadAndUpdateRequest downloadAndUpdateRequest = new DownloadAndUpdateRequest(); final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = new DmfDownloadAndUpdateRequest();
downloadAndUpdateRequest.setActionId(actionId); downloadAndUpdateRequest.setActionId(actionId);
final String targetSecurityToken = systemSecurityContext.runAsSystem(target::getSecurityToken); final String targetSecurityToken = systemSecurityContext.runAsSystem(target::getSecurityToken);
downloadAndUpdateRequest.setTargetSecurityToken(targetSecurityToken); downloadAndUpdateRequest.setTargetSecurityToken(targetSecurityToken);
for (final org.eclipse.hawkbit.repository.model.SoftwareModule softwareModule : modules) { for (final SoftwareModule softwareModule : modules) {
final SoftwareModule amqpSoftwareModule = convertToAmqpSoftwareModule(target, softwareModule); final DmfSoftwareModule amqpSoftwareModule = convertToAmqpSoftwareModule(target, softwareModule);
downloadAndUpdateRequest.addSoftwareModule(amqpSoftwareModule); downloadAndUpdateRequest.addSoftwareModule(amqpSoftwareModule);
} }
@@ -228,20 +230,18 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
return messageProperties; return messageProperties;
} }
private SoftwareModule convertToAmqpSoftwareModule(final Target target, private DmfSoftwareModule convertToAmqpSoftwareModule(final Target target, final SoftwareModule softwareModule) {
final org.eclipse.hawkbit.repository.model.SoftwareModule softwareModule) { final DmfSoftwareModule amqpSoftwareModule = new DmfSoftwareModule();
final SoftwareModule amqpSoftwareModule = new SoftwareModule();
amqpSoftwareModule.setModuleId(softwareModule.getId()); amqpSoftwareModule.setModuleId(softwareModule.getId());
amqpSoftwareModule.setModuleType(softwareModule.getType().getKey()); amqpSoftwareModule.setModuleType(softwareModule.getType().getKey());
amqpSoftwareModule.setModuleVersion(softwareModule.getVersion()); amqpSoftwareModule.setModuleVersion(softwareModule.getVersion());
final List<Artifact> artifacts = convertArtifacts(target, softwareModule.getArtifacts()); final List<DmfArtifact> artifacts = convertArtifacts(target, softwareModule.getArtifacts());
amqpSoftwareModule.setArtifacts(artifacts); amqpSoftwareModule.setArtifacts(artifacts);
return amqpSoftwareModule; return amqpSoftwareModule;
} }
private List<Artifact> convertArtifacts(final Target target, private List<DmfArtifact> convertArtifacts(final Target target, final List<Artifact> localArtifacts) {
final List<org.eclipse.hawkbit.repository.model.Artifact> localArtifacts) {
if (localArtifacts.isEmpty()) { if (localArtifacts.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -250,9 +250,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private Artifact convertArtifact(final Target target, private DmfArtifact convertArtifact(final Target target, final Artifact localArtifact) {
final org.eclipse.hawkbit.repository.model.Artifact localArtifact) { final DmfArtifact artifact = new DmfArtifact();
final Artifact artifact = new Artifact();
artifact.setUrls(artifactUrlHandler artifact.setUrls(artifactUrlHandler
.getUrls(new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(), .getUrls(new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(),
@@ -263,7 +262,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
.stream().collect(Collectors.toMap(ArtifactUrl::getProtocol, ArtifactUrl::getRef))); .stream().collect(Collectors.toMap(ArtifactUrl::getProtocol, ArtifactUrl::getRef)));
artifact.setFilename(localArtifact.getFilename()); artifact.setFilename(localArtifact.getFilename());
artifact.setHashes(new ArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash())); artifact.setHashes(new DmfArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()));
artifact.setSize(localArtifact.getSize()); artifact.setSize(localArtifact.getSize());
return artifact; return artifact;
} }

View File

@@ -20,8 +20,8 @@ import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionUpdateStatus;
import org.eclipse.hawkbit.dmf.json.model.AttributeUpdate; import org.eclipse.hawkbit.dmf.json.model.DmfAttributeUpdate;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.ControllerManagement;
@@ -223,7 +223,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
} }
private void updateAttributes(final Message message) { private void updateAttributes(final Message message) {
final AttributeUpdate attributeUpdate = convertMessage(message, AttributeUpdate.class); final DmfAttributeUpdate attributeUpdate = convertMessage(message, DmfAttributeUpdate.class);
final String thingId = getStringHeaderKey(message, MessageHeaderKey.THING_ID, "ThingId is null"); final String thingId = getStringHeaderKey(message, MessageHeaderKey.THING_ID, "ThingId is null");
controllerManagement.updateControllerAttributes(thingId, attributeUpdate.getAttributes()); controllerManagement.updateControllerAttributes(thingId, attributeUpdate.getAttributes());
@@ -236,7 +236,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
* the object form the ampq message * the object form the ampq message
*/ */
private void updateActionStatus(final Message message) { private void updateActionStatus(final Message message) {
final ActionUpdateStatus actionUpdateStatus = convertMessage(message, ActionUpdateStatus.class); final DmfActionUpdateStatus actionUpdateStatus = convertMessage(message, DmfActionUpdateStatus.class);
final Action action = checkActionExist(message, actionUpdateStatus); final Action action = checkActionExist(message, actionUpdateStatus);
final List<String> messages = actionUpdateStatus.getMessage(); final List<String> messages = actionUpdateStatus.getMessage();
@@ -256,7 +256,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
} }
} }
private Status mapStatus(final Message message, final ActionUpdateStatus actionUpdateStatus, final Action action) { private Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) {
Status status = null; Status status = null;
switch (actionUpdateStatus.getActionStatus()) { switch (actionUpdateStatus.getActionStatus()) {
case DOWNLOAD: case DOWNLOAD:
@@ -314,7 +314,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
// Exception squid:S3655 - logAndThrowMessageError throws exception, i.e. // Exception squid:S3655 - logAndThrowMessageError throws exception, i.e.
// get will not be called // get will not be called
@SuppressWarnings("squid:S3655") @SuppressWarnings("squid:S3655")
private Action checkActionExist(final Message message, final ActionUpdateStatus actionUpdateStatus) { private Action checkActionExist(final Message message, final DmfActionUpdateStatus actionUpdateStatus) {
final Long actionId = actionUpdateStatus.getActionId(); final Long actionId = actionUpdateStatus.getActionId();
LOG.debug("Target notifies intermediate about action {} with status {}.", actionId, LOG.debug("Target notifies intermediate about action {} with status {}.", actionId,

View File

@@ -25,9 +25,9 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.cache.DownloadIdCache;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadResponse;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
@@ -181,7 +181,7 @@ public class AmqpControllerAuthenticationTest {
@Test @Test
@Description("Tests authentication manager without principal") @Description("Tests authentication manager without principal")
public void testAuthenticationeBadCredantialsWithoutPricipal() { public void testAuthenticationeBadCredantialsWithoutPricipal() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1(SHA1)); FileResource.createFileResourceBySha1(SHA1));
try { try {
authenticationManager.doAuthenticate(securityToken); authenticationManager.doAuthenticate(securityToken);
@@ -195,12 +195,12 @@ public class AmqpControllerAuthenticationTest {
@Test @Test
@Description("Tests authentication manager without wrong credential") @Description("Tests authentication manager without wrong credential")
public void testAuthenticationBadCredantialsWithWrongCredential() { public void testAuthenticationBadCredantialsWithWrongCredential() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1(SHA1)); FileResource.createFileResourceBySha1(SHA1));
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
securityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID); securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID);
try { try {
authenticationManager.doAuthenticate(securityToken); authenticationManager.doAuthenticate(securityToken);
fail("BadCredentialsException was excepeted due to wrong credential"); fail("BadCredentialsException was excepeted due to wrong credential");
@@ -213,12 +213,12 @@ public class AmqpControllerAuthenticationTest {
@Test @Test
@Description("Tests authentication successfull") @Description("Tests authentication successfull")
public void testSuccessfullAuthentication() { public void testSuccessfullAuthentication() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1(SHA1)); FileResource.createFileResourceBySha1(SHA1));
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
securityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID); securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
final Authentication authentication = authenticationManager.doAuthenticate(securityToken); final Authentication authentication = authenticationManager.doAuthenticate(securityToken);
assertThat(authentication).isNotNull(); assertThat(authentication).isNotNull();
} }
@@ -228,7 +228,7 @@ public class AmqpControllerAuthenticationTest {
public void testAuthenticationMessageBadCredantialsWithoutPricipal() { public void testAuthenticationMessageBadCredantialsWithoutPricipal() {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1(SHA1)); FileResource.createFileResourceBySha1(SHA1));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -237,7 +237,7 @@ public class AmqpControllerAuthenticationTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).isNotNull(); assertThat(downloadResponse).isNotNull();
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.FORBIDDEN.value()); assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.FORBIDDEN.value());
} }
@@ -246,12 +246,12 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication message without wrong credential") @Description("Tests authentication message without wrong credential")
public void testAuthenticationMessageBadCredantialsWithWrongCredential() { public void testAuthenticationMessageBadCredantialsWithWrongCredential() {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1(SHA1)); FileResource.createFileResourceBySha1(SHA1));
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
securityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID); securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -259,7 +259,7 @@ public class AmqpControllerAuthenticationTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).isNotNull(); assertThat(downloadResponse).isNotNull();
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.FORBIDDEN.value()); assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.FORBIDDEN.value());
} }
@@ -268,12 +268,12 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication message successfull") @Description("Tests authentication message successfull")
public void successfullMessageAuthentication() { public void successfullMessageAuthentication() {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, null, CONTROLLER_ID, null, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, null, CONTROLLER_ID, null,
FileResource.createFileResourceBySha1(SHA1)); FileResource.createFileResourceBySha1(SHA1));
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
securityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID); securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -281,7 +281,7 @@ public class AmqpControllerAuthenticationTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).isNotNull(); assertThat(downloadResponse).isNotNull();
assertThat(downloadResponse.getDownloadUrl()).isNotNull(); assertThat(downloadResponse.getDownloadUrl()).isNotNull();
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.OK.value()); assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.OK.value());
@@ -296,12 +296,12 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication message successfull with targetId intead of controllerId provided and artifactId instead of SHA1.") @Description("Tests authentication message successfull with targetId intead of controllerId provided and artifactId instead of SHA1.")
public void successfullMessageAuthenticationWithTargetIdAndArtifactId() { public void successfullMessageAuthenticationWithTargetIdAndArtifactId() {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, null, null, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, null, null, TARGET_ID,
FileResource.createFileResourceByArtifactId(ARTIFACT_ID)); FileResource.createFileResourceByArtifactId(ARTIFACT_ID));
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
securityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID); securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -309,7 +309,7 @@ public class AmqpControllerAuthenticationTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).isNotNull(); assertThat(downloadResponse).isNotNull();
assertThat(downloadResponse.getDownloadUrl()).isNotNull(); assertThat(downloadResponse.getDownloadUrl()).isNotNull();
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.OK.value()); assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.OK.value());
@@ -324,12 +324,12 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication message successfull") @Description("Tests authentication message successfull")
public void successfullMessageAuthenticationWithTenantid() { public void successfullMessageAuthenticationWithTenantid() {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(null, TENANT_ID, CONTROLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(null, TENANT_ID, CONTROLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1(SHA1)); FileResource.createFileResourceBySha1(SHA1));
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
securityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID); securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -337,7 +337,7 @@ public class AmqpControllerAuthenticationTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).isNotNull(); assertThat(downloadResponse).isNotNull();
assertThat(downloadResponse.getDownloadUrl()).isNotNull(); assertThat(downloadResponse.getDownloadUrl()).isNotNull();
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.OK.value()); assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.OK.value());

View File

@@ -29,7 +29,7 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
@@ -119,7 +119,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent);
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, 1L); final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, 1L);
assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN);
assertTrue("No softwaremmodule should be contained in the request", assertTrue("No softwaremmodule should be contained in the request",
downloadAndUpdateRequest.getSoftwareModules().isEmpty()); downloadAndUpdateRequest.getSoftwareModules().isEmpty());
@@ -147,11 +147,11 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
action, serviceMatcher.getServiceId()); action, serviceMatcher.getServiceId());
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent);
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage,
action.getId()); action.getId());
assertThat(createDistributionSet.getModules()).hasSameSizeAs(downloadAndUpdateRequest.getSoftwareModules()); assertThat(createDistributionSet.getModules()).hasSameSizeAs(downloadAndUpdateRequest.getSoftwareModules());
assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN);
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest for (final org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule softwareModule : downloadAndUpdateRequest
.getSoftwareModules()) { .getSoftwareModules()) {
assertTrue("Artifact list for softwaremodule should be empty", softwareModule.getArtifacts().isEmpty()); assertTrue("Artifact list for softwaremodule should be empty", softwareModule.getArtifacts().isEmpty());
for (final SoftwareModule softwareModule2 : action.getDistributionSet().getModules()) { for (final SoftwareModule softwareModule2 : action.getDistributionSet().getModules()) {
@@ -189,14 +189,14 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
action, serviceMatcher.getServiceId()); action, serviceMatcher.getServiceId());
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent);
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage,
action.getId()); action.getId());
assertEquals("DownloadAndUpdateRequest event should contains 3 software modules", 3, assertEquals("DownloadAndUpdateRequest event should contains 3 software modules", 3,
downloadAndUpdateRequest.getSoftwareModules().size()); downloadAndUpdateRequest.getSoftwareModules().size());
assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN);
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest for (final org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule softwareModule : downloadAndUpdateRequest
.getSoftwareModules()) { .getSoftwareModules()) {
if (!softwareModule.getModuleId().equals(module.getId())) { if (!softwareModule.getModuleId().equals(module.getId())) {
continue; continue;
@@ -204,7 +204,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
assertThat(softwareModule.getArtifacts().size()).isEqualTo(module.getArtifacts().size()).isGreaterThan(0); assertThat(softwareModule.getArtifacts().size()).isEqualTo(module.getArtifacts().size()).isGreaterThan(0);
module.getArtifacts().forEach(dbArtifact -> { module.getArtifacts().forEach(dbArtifact -> {
final Optional<org.eclipse.hawkbit.dmf.json.model.Artifact> found = softwareModule.getArtifacts() final Optional<org.eclipse.hawkbit.dmf.json.model.DmfArtifact> found = softwareModule.getArtifacts()
.stream().filter(dmfartifact -> dmfartifact.getFilename().equals(dbArtifact.getFilename())) .stream().filter(dmfartifact -> dmfartifact.getFilename().equals(dbArtifact.getFilename()))
.findAny(); .findAny();
@@ -296,10 +296,10 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
.isEqualTo(MessageType.THING_DELETED); .isEqualTo(MessageType.THING_DELETED);
} }
private DownloadAndUpdateRequest assertDownloadAndInstallMessage(final Message sendMessage, final Long action) { private DmfDownloadAndUpdateRequest assertDownloadAndInstallMessage(final Message sendMessage, final Long action) {
assertEventMessage(sendMessage); assertEventMessage(sendMessage);
final DownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(sendMessage, final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(sendMessage,
DownloadAndUpdateRequest.class); DmfDownloadAndUpdateRequest.class);
assertEquals(downloadAndUpdateRequest.getActionId(), action); assertEquals(downloadAndUpdateRequest.getActionId(), action);
assertEquals("The topic of the event shuold contain DOWNLOAD_AND_INSTALL", EventTopic.DOWNLOAD_AND_INSTALL, assertEquals("The topic of the event shuold contain DOWNLOAD_AND_INSTALL", EventTopic.DOWNLOAD_AND_INSTALL,
sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC)); sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC));

View File

@@ -34,12 +34,12 @@ import org.eclipse.hawkbit.cache.DownloadIdCache;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.ActionStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionStatus;
import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionUpdateStatus;
import org.eclipse.hawkbit.dmf.json.model.AttributeUpdate; import org.eclipse.hawkbit.dmf.json.model.DmfAttributeUpdate;
import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadResponse;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
@@ -181,7 +181,7 @@ public class AmqpMessageHandlerServiceTest {
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1"); messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_ATTRIBUTES"); messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_ATTRIBUTES");
final AttributeUpdate attributeUpdate = new AttributeUpdate(); final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
attributeUpdate.getAttributes().put("testKey1", "testValue1"); attributeUpdate.getAttributes().put("testKey1", "testValue1");
attributeUpdate.getAttributes().put("testKey2", "testValue2"); attributeUpdate.getAttributes().put("testKey2", "testValue2");
@@ -279,7 +279,7 @@ public class AmqpMessageHandlerServiceTest {
when(controllerManagementMock.findActionWithDetails(any())).thenReturn(Optional.empty()); when(controllerManagementMock.findActionWithDetails(any())).thenReturn(Optional.empty());
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(1L, ActionStatus.DOWNLOAD); final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.DOWNLOAD);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus,
messageProperties); messageProperties);
@@ -298,7 +298,7 @@ public class AmqpMessageHandlerServiceTest {
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
when(controllerManagementMock.findActionWithDetails(any())).thenReturn(Optional.empty()); when(controllerManagementMock.findActionWithDetails(any())).thenReturn(Optional.empty());
final ActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(ActionStatus.DOWNLOAD); final DmfActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(DmfActionStatus.DOWNLOAD);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus,
messageProperties); messageProperties);
@@ -315,7 +315,7 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is denied for an artifact which does not exists") @Description("Tests that an download request is denied for an artifact which does not exists")
public void authenticationRequestDeniedForArtifactWhichDoesNotExists() { public void authenticationRequestDeniedForArtifactWhichDoesNotExists() {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1("12345")); FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -324,7 +324,7 @@ public class AmqpMessageHandlerServiceTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).as("Message body should not null").isNotNull(); assertThat(downloadResponse).as("Message body should not null").isNotNull();
assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong") assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong")
.isEqualTo(HttpStatus.NOT_FOUND.value()); .isEqualTo(HttpStatus.NOT_FOUND.value());
@@ -334,7 +334,7 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is denied for an artifact which is not assigned to the requested target") @Description("Tests that an download request is denied for an artifact which is not assigned to the requested target")
public void authenticationRequestDeniedForArtifactWhichIsNotAssignedToTarget() { public void authenticationRequestDeniedForArtifactWhichIsNotAssignedToTarget() {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1("12345")); FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -348,7 +348,7 @@ public class AmqpMessageHandlerServiceTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).as("Message body should not null").isNotNull(); assertThat(downloadResponse).as("Message body should not null").isNotNull();
assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong") assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong")
.isEqualTo(HttpStatus.NOT_FOUND.value()); .isEqualTo(HttpStatus.NOT_FOUND.value());
@@ -358,7 +358,7 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is allowed for an artifact which exists and assigned to the requested target") @Description("Tests that an download request is allowed for an artifact which exists and assigned to the requested target")
public void authenticationRequestAllowedForArtifactWhichExistsAndAssignedToTarget() throws MalformedURLException { public void authenticationRequestAllowedForArtifactWhichExistsAndAssignedToTarget() throws MalformedURLException {
final MessageProperties messageProperties = createMessageProperties(null); final MessageProperties messageProperties = createMessageProperties(null);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, TENANT_ID, CONTROLLLER_ID, TARGET_ID, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLLER_ID, TARGET_ID,
FileResource.createFileResourceBySha1("12345")); FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -381,7 +381,7 @@ public class AmqpMessageHandlerServiceTest {
final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message); final Message onMessage = amqpAuthenticationMessageHandlerService.onAuthenticationRequest(message);
// verify // verify
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage); final DmfDownloadResponse downloadResponse = (DmfDownloadResponse) messageConverter.fromMessage(onMessage);
assertThat(downloadResponse).as("Message body should not null").isNotNull(); assertThat(downloadResponse).as("Message body should not null").isNotNull();
assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong") assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong")
.isEqualTo(HttpStatus.OK.value()); .isEqualTo(HttpStatus.OK.value());
@@ -410,7 +410,7 @@ public class AmqpMessageHandlerServiceTest {
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
final ActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(ActionStatus.FINISHED, 23L); final DmfActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(DmfActionStatus.FINISHED, 23L);
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(actionUpdateStatus,
messageProperties); messageProperties);
@@ -433,12 +433,12 @@ public class AmqpMessageHandlerServiceTest {
} }
private ActionUpdateStatus createActionUpdateStatus(final ActionStatus status) { private DmfActionUpdateStatus createActionUpdateStatus(final DmfActionStatus status) {
return createActionUpdateStatus(status, 2L); return createActionUpdateStatus(status, 2L);
} }
private ActionUpdateStatus createActionUpdateStatus(final ActionStatus status, final Long id) { private DmfActionUpdateStatus createActionUpdateStatus(final DmfActionStatus status, final Long id) {
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(id, status); final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(id, status);
actionUpdateStatus.setSoftwareModuleId(Long.valueOf(2)); actionUpdateStatus.setSoftwareModuleId(Long.valueOf(2));
return actionUpdateStatus; return actionUpdateStatus;
} }

View File

@@ -12,8 +12,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.eclipse.hawkbit.dmf.json.model.ActionStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionStatus;
import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionUpdateStatus;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.test.matcher.Expect; import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
@@ -52,12 +52,12 @@ public class BaseAmqpServiceTest {
@Test @Test
@Description("Verify that the message conversion works") @Description("Verify that the message conversion works")
public void convertMessageTest() { public void convertMessageTest() {
final ActionUpdateStatus actionUpdateStatus = createActionStatus(); final DmfActionUpdateStatus actionUpdateStatus = createActionStatus();
final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus, final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus,
createJsonProperties()); createJsonProperties());
final ActionUpdateStatus convertedActionUpdateStatus = baseAmqpService.convertMessage(message, final DmfActionUpdateStatus convertedActionUpdateStatus = baseAmqpService.convertMessage(message,
ActionUpdateStatus.class); DmfActionUpdateStatus.class);
assertThat(convertedActionUpdateStatus).isEqualToComparingFieldByField(actionUpdateStatus); assertThat(convertedActionUpdateStatus).isEqualToComparingFieldByField(actionUpdateStatus);
@@ -68,7 +68,7 @@ public class BaseAmqpServiceTest {
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void convertMessageWithNullContent() { public void convertMessageWithNullContent() {
try { try {
baseAmqpService.convertMessage(new Message(null, createJsonProperties()), ActionUpdateStatus.class); baseAmqpService.convertMessage(new Message(null, createJsonProperties()), DmfActionUpdateStatus.class);
fail("Expected MessageConversionException for inavlid JSON"); fail("Expected MessageConversionException for inavlid JSON");
} catch (final MessageConversionException e) { } catch (final MessageConversionException e) {
// expected // expected
@@ -82,7 +82,7 @@ public class BaseAmqpServiceTest {
public void updateActionStatusWithEmptyContent() { public void updateActionStatusWithEmptyContent() {
try { try {
baseAmqpService.convertMessage(new Message("".getBytes(), createJsonProperties()), baseAmqpService.convertMessage(new Message("".getBytes(), createJsonProperties()),
ActionUpdateStatus.class); DmfActionUpdateStatus.class);
fail("Expected MessageConversionException for inavlid JSON"); fail("Expected MessageConversionException for inavlid JSON");
} catch (final MessageConversionException e) { } catch (final MessageConversionException e) {
// expected // expected
@@ -101,15 +101,15 @@ public class BaseAmqpServiceTest {
public void updateActionStatusWithInvalidJsonContent() { public void updateActionStatusWithInvalidJsonContent() {
try { try {
baseAmqpService.convertMessage(new Message("Invalid Json".getBytes(), createJsonProperties()), baseAmqpService.convertMessage(new Message("Invalid Json".getBytes(), createJsonProperties()),
ActionUpdateStatus.class); DmfActionUpdateStatus.class);
fail("Expected MessageConversionException for inavlid JSON"); fail("Expected MessageConversionException for inavlid JSON");
} catch (final MessageConversionException e) { } catch (final MessageConversionException e) {
// expected // expected
} }
} }
private ActionUpdateStatus createActionStatus() { private DmfActionUpdateStatus createActionStatus() {
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(1L, ActionStatus.RUNNING); final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING);
actionUpdateStatus.setSoftwareModuleId(2L); actionUpdateStatus.setSoftwareModuleId(2L);
actionUpdateStatus.addMessage("Message 1"); actionUpdateStatus.addMessage("Message 1");
actionUpdateStatus.addMessage("Message 2"); actionUpdateStatus.addMessage("Message 2");

View File

@@ -17,9 +17,9 @@ import java.util.List;
import org.eclipse.hawkbit.amqp.AmqpProperties; import org.eclipse.hawkbit.amqp.AmqpProperties;
import org.eclipse.hawkbit.amqp.DmfApiConfiguration; import org.eclipse.hawkbit.amqp.DmfApiConfiguration;
import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings; import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings;
import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadResponse;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken.FileResource;
import org.eclipse.hawkbit.rabbitmq.test.AbstractAmqpIntegrationTest; import org.eclipse.hawkbit.rabbitmq.test.AbstractAmqpIntegrationTest;
import org.eclipse.hawkbit.rabbitmq.test.AmqpTestConfiguration; import org.eclipse.hawkbit.rabbitmq.test.AmqpTestConfiguration;
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
@@ -82,7 +82,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
@Test @Test
@Description("Tenant in the message is null. This message is invalid and should not be requeued. Additional the receive message is null") @Description("Tenant in the message is null. This message is invalid and should not be requeued. Additional the receive message is null")
public void securityTokenTenantIsNull() { public void securityTokenTenantIsNull() {
final TenantSecurityToken securityToken = createTenantSecurityToken(null, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(null, TARGET,
FileResource.createFileResourceBySha1(TARGET_SECRUITY_TOKEN)); FileResource.createFileResourceBySha1(TARGET_SECRUITY_TOKEN));
final Message createAndSendMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message createAndSendMessage = sendAndReceiveAuthenticationMessage(securityToken);
assertThat(createAndSendMessage).isNull(); assertThat(createAndSendMessage).isNull();
@@ -93,7 +93,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
@Description("Target in the message is null.This message is invalid and should not requeued. Additional the receive message is null") @Description("Target in the message is null.This message is invalid and should not requeued. Additional the receive message is null")
public void securityTokenFileResourceIsNull() { public void securityTokenFileResourceIsNull() {
enableAnonymousAuthentification(); enableAnonymousAuthentification();
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, null); final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, null);
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
verifyResult(returnMessage, HttpStatus.NOT_FOUND, null); verifyResult(returnMessage, HttpStatus.NOT_FOUND, null);
} }
@@ -103,7 +103,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
public void loginFailedBadCredentials() { public void loginFailedBadCredentials() {
tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED,
false); false);
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceBySha1(TARGET_SECRUITY_TOKEN)); FileResource.createFileResourceBySha1(TARGET_SECRUITY_TOKEN));
final Message createAndSendMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message createAndSendMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -115,7 +115,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
@Description("Verify that the receive message contains a 404 code,if the artifact could not found") @Description("Verify that the receive message contains a 404 code,if the artifact could not found")
public void fileResourceGetSha1InSecurityTokenIsNull() { public void fileResourceGetSha1InSecurityTokenIsNull() {
enableAnonymousAuthentification(); enableAnonymousAuthentification();
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceBySha1(null)); FileResource.createFileResourceBySha1(null));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -132,7 +132,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final String sha1Hash = artifacts.get(0).getSha1Hash(); final String sha1Hash = artifacts.get(0).getSha1Hash();
final TenantSecurityToken securityToken = createTenantSecurityToken(target.getTenant(), target.getId(), null, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(target.getTenant(), target.getId(), null,
FileResource.createFileResourceBySha1(sha1Hash)); FileResource.createFileResourceBySha1(sha1Hash));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -144,7 +144,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
@Description("Verify that the receive message contains a 404 code, if there is no artifact for the given sha1") @Description("Verify that the receive message contains a 404 code, if there is no artifact for the given sha1")
public void artifactForFileResourceSHA1NotFound() { public void artifactForFileResourceSHA1NotFound() {
enableAnonymousAuthentification(); enableAnonymousAuthentification();
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceBySha1(TARGET_SECRUITY_TOKEN)); FileResource.createFileResourceBySha1(TARGET_SECRUITY_TOKEN));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -160,7 +160,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final String sha1Hash = artifacts.get(0).getSha1Hash(); final String sha1Hash = artifacts.get(0).getSha1Hash();
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceBySha1(sha1Hash)); FileResource.createFileResourceBySha1(sha1Hash));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -176,7 +176,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceBySha1(artifacts.get(0).getSha1Hash())); FileResource.createFileResourceBySha1(artifacts.get(0).getSha1Hash()));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -193,7 +193,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final Artifact artifact = artifacts.get(0); final Artifact artifact = artifacts.get(0);
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceBySha1(artifact.getSha1Hash())); FileResource.createFileResourceBySha1(artifact.getSha1Hash()));
deploymentManagement.assignDistributionSet(distributionSet.getId(), deploymentManagement.assignDistributionSet(distributionSet.getId(),
@@ -212,7 +212,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final Artifact artifact = artifacts.get(0); final Artifact artifact = artifacts.get(0);
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, target.getId(), null, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, target.getId(), null,
FileResource.createFileResourceBySha1(artifact.getSha1Hash())); FileResource.createFileResourceBySha1(artifact.getSha1Hash()));
deploymentManagement.assignDistributionSet(distributionSet.getId(), deploymentManagement.assignDistributionSet(distributionSet.getId(),
@@ -230,7 +230,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final Artifact artifact = artifacts.get(0); final Artifact artifact = artifacts.get(0);
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, null, null, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, null, null,
FileResource.createFileResourceBySha1(artifact.getSha1Hash())); FileResource.createFileResourceBySha1(artifact.getSha1Hash()));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -246,7 +246,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final Artifact artifact = artifacts.get(0); final Artifact artifact = artifacts.get(0);
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceBySha1(artifact.getSha1Hash())); FileResource.createFileResourceBySha1(artifact.getSha1Hash()));
deploymentManagement.assignDistributionSet(distributionSet.getId(), deploymentManagement.assignDistributionSet(distributionSet.getId(),
@@ -261,7 +261,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
@Description("Verify that the receive message contains a 404, if there is no artifact to the given filename") @Description("Verify that the receive message contains a 404, if there is no artifact to the given filename")
public void artifactForFileResourceFileNameNotFound() { public void artifactForFileResourceFileNameNotFound() {
enableAnonymousAuthentification(); enableAnonymousAuthentification();
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceByFilename("Test.txt")); FileResource.createFileResourceByFilename("Test.txt"));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -277,7 +277,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.createFileResourceByFilename(artifacts.get(0).getFilename())); FileResource.createFileResourceByFilename(artifacts.get(0).getFilename()));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -293,7 +293,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final DistributionSet distributionSet = createDistributionSet(); final DistributionSet distributionSet = createDistributionSet();
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final FileResource fileResource = FileResource.createFileResourceByArtifactId(artifacts.get(0).getId()); final FileResource fileResource = FileResource.createFileResourceByArtifactId(artifacts.get(0).getId());
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource); final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource);
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
verifyResult(returnMessage, HttpStatus.NOT_FOUND, "Artifact for resource FileResource [sha1=null, artifactId=" verifyResult(returnMessage, HttpStatus.NOT_FOUND, "Artifact for resource FileResource [sha1=null, artifactId="
@@ -310,7 +310,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final List<Artifact> artifacts = createArtifacts(distributionSet); final List<Artifact> artifacts = createArtifacts(distributionSet);
final Artifact artifact = artifacts.get(0); final Artifact artifact = artifacts.get(0);
final FileResource fileResource = FileResource.createFileResourceByArtifactId(artifact.getId()); final FileResource fileResource = FileResource.createFileResourceByArtifactId(artifact.getId());
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource); final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource);
deploymentManagement.assignDistributionSet(distributionSet.getId(), deploymentManagement.assignDistributionSet(distributionSet.getId(),
Arrays.asList(new TargetWithActionType(TARGET))); Arrays.asList(new TargetWithActionType(TARGET)));
@@ -324,7 +324,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
@Description("Verify that the receive message contains a 404, if there is no artifact to the given softwareModuleFilename") @Description("Verify that the receive message contains a 404, if there is no artifact to the given softwareModuleFilename")
public void artifactForFileResourceSoftwareModuleFilenameNotFound() { public void artifactForFileResourceSoftwareModuleFilenameNotFound() {
enableAnonymousAuthentification(); enableAnonymousAuthentification();
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET,
FileResource.softwareModuleFilename(1L, "Test.txt")); FileResource.softwareModuleFilename(1L, "Test.txt"));
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
@@ -345,7 +345,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final FileResource fileResource = FileResource.softwareModuleFilename(softwareModule.getId(), final FileResource fileResource = FileResource.softwareModuleFilename(softwareModule.getId(),
softwareModule.getArtifact(artifact.getId()).get().getFilename()); softwareModule.getArtifact(artifact.getId()).get().getFilename());
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource); final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource);
final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken); final Message returnMessage = sendAndReceiveAuthenticationMessage(securityToken);
verifyResult(returnMessage, HttpStatus.NOT_FOUND, verifyResult(returnMessage, HttpStatus.NOT_FOUND,
@@ -366,7 +366,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
final FileResource fileResource = FileResource.softwareModuleFilename(softwareModule.getId(), final FileResource fileResource = FileResource.softwareModuleFilename(softwareModule.getId(),
softwareModule.getArtifact(artifact.getId()).get().getFilename()); softwareModule.getArtifact(artifact.getId()).get().getFilename());
final TenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource); final DmfTenantSecurityToken securityToken = createTenantSecurityToken(TENANT_EXIST, TARGET, fileResource);
deploymentManagement.assignDistributionSet(distributionSet.getId(), deploymentManagement.assignDistributionSet(distributionSet.getId(),
Arrays.asList(new TargetWithActionType(TARGET))); Arrays.asList(new TargetWithActionType(TARGET)));
@@ -377,7 +377,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
} }
private void verifyOkResult(Message returnMessage, Artifact artifact) { private void verifyOkResult(Message returnMessage, Artifact artifact) {
final DownloadResponse convertedMessage = verifyResult(returnMessage, HttpStatus.OK, null); final DmfDownloadResponse convertedMessage = verifyResult(returnMessage, HttpStatus.OK, null);
assertThat(convertedMessage.getDownloadUrl()).isNotNull(); assertThat(convertedMessage.getDownloadUrl()).isNotNull();
assertThat(convertedMessage.getArtifact()).isNotNull(); assertThat(convertedMessage.getArtifact()).isNotNull();
assertThat(convertedMessage.getArtifact().getHashes().getSha1()).isEqualTo(artifact.getSha1Hash()); assertThat(convertedMessage.getArtifact().getHashes().getSha1()).isEqualTo(artifact.getSha1Hash());
@@ -403,18 +403,18 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
entityFactory.target().create().controllerId(controllerId).securityToken(TARGET_SECRUITY_TOKEN)); entityFactory.target().create().controllerId(controllerId).securityToken(TARGET_SECRUITY_TOKEN));
} }
private TenantSecurityToken createTenantSecurityToken(final String tenant, final String controllerId, private DmfTenantSecurityToken createTenantSecurityToken(final String tenant, final String controllerId,
final FileResource fileResource) { final FileResource fileResource) {
final TenantSecurityToken tenantSecurityToken = new TenantSecurityToken(tenant, controllerId, fileResource); final DmfTenantSecurityToken tenantSecurityToken = new DmfTenantSecurityToken(tenant, controllerId, fileResource);
tenantSecurityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, TARGET_TOKEN_HEADER); tenantSecurityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, TARGET_TOKEN_HEADER);
return tenantSecurityToken; return tenantSecurityToken;
} }
private TenantSecurityToken createTenantSecurityToken(final String tenant, final Long targetId, private DmfTenantSecurityToken createTenantSecurityToken(final String tenant, final Long targetId,
final String controllerId, final FileResource fileResource) { final String controllerId, final FileResource fileResource) {
final TenantSecurityToken tenantSecurityToken = new TenantSecurityToken(tenant, null, controllerId, targetId, final DmfTenantSecurityToken tenantSecurityToken = new DmfTenantSecurityToken(tenant, null, controllerId, targetId,
fileResource); fileResource);
tenantSecurityToken.putHeader(TenantSecurityToken.AUTHORIZATION_HEADER, TARGET_TOKEN_HEADER); tenantSecurityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, TARGET_TOKEN_HEADER);
return tenantSecurityToken; return tenantSecurityToken;
} }
@@ -430,9 +430,9 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
return artifacts; return artifacts;
} }
private DownloadResponse verifyResult(final Message returnMessage, final HttpStatus expectedStatus, private DmfDownloadResponse verifyResult(final Message returnMessage, final HttpStatus expectedStatus,
final String expectedMessage) { final String expectedMessage) {
final DownloadResponse convertedMessage = (DownloadResponse) getDmfClient().getMessageConverter() final DmfDownloadResponse convertedMessage = (DmfDownloadResponse) getDmfClient().getMessageConverter()
.fromMessage(returnMessage); .fromMessage(returnMessage);
assertThat(convertedMessage.getResponseCode()).isEqualTo(expectedStatus.value()); assertThat(convertedMessage.getResponseCode()).isEqualTo(expectedStatus.value());
@@ -442,7 +442,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq
return convertedMessage; return convertedMessage;
} }
private Message sendAndReceiveAuthenticationMessage(final TenantSecurityToken securityToken) { private Message sendAndReceiveAuthenticationMessage(final DmfTenantSecurityToken securityToken) {
return getDmfClient().sendAndReceive(createMessage(securityToken, new MessageProperties())); return getDmfClient().sendAndReceive(createMessage(securityToken, new MessageProperties()));
} }

View File

@@ -19,9 +19,9 @@ import org.eclipse.hawkbit.amqp.AmqpProperties;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.ActionStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionStatus;
import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.DmfActionUpdateStatus;
import org.eclipse.hawkbit.dmf.json.model.AttributeUpdate; import org.eclipse.hawkbit.dmf.json.model.DmfAttributeUpdate;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent; import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
@@ -327,7 +327,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Description("Tests invalid topic message header. This message should forwarded to the deadletter queue") @Description("Tests invalid topic message header. This message should forwarded to the deadletter queue")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void updateActionStatusWithInvalidActionId() { public void updateActionStatusWithInvalidActionId() {
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(1L, ActionStatus.RUNNING); final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING);
final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS,
actionUpdateStatus); actionUpdateStatus);
getDmfClient().send(eventMessage); getDmfClient().send(eventMessage);
@@ -343,7 +343,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) })
public void finishActionStatus() { public void finishActionStatus() {
registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.FINISHED, Status.FINISHED); registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.FINISHED, Status.FINISHED);
} }
@Test @Test
@@ -355,7 +355,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void runningActionStatus() { public void runningActionStatus() {
registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.RUNNING, Status.RUNNING); registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.RUNNING, Status.RUNNING);
} }
@Test @Test
@@ -367,7 +367,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void downloadActionStatus() { public void downloadActionStatus() {
registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.DOWNLOAD, Status.DOWNLOAD); registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.DOWNLOAD, Status.DOWNLOAD);
} }
@Test @Test
@@ -379,7 +379,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) })
public void errorActionStatus() { public void errorActionStatus() {
registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.ERROR, Status.ERROR); registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.ERROR, Status.ERROR);
} }
@Test @Test
@@ -391,7 +391,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void warningActionStatus() { public void warningActionStatus() {
registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.WARNING, Status.WARNING); registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.WARNING, Status.WARNING);
} }
@Test @Test
@@ -403,7 +403,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void retrievedActionStatus() { public void retrievedActionStatus() {
registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.RETRIEVED, Status.RETRIEVED); registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.RETRIEVED, Status.RETRIEVED);
} }
@Test @Test
@@ -415,7 +415,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void cancelNotAllowActionStatus() { public void cancelNotAllowActionStatus() {
registerTargetAndSendActionStatus(ActionStatus.CANCELED); registerTargetAndSendActionStatus(DmfActionStatus.CANCELED);
verifyOneDeadLetterMessage(); verifyOneDeadLetterMessage();
} }
@@ -482,7 +482,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
final Long actionId = registerTargetAndCancelActionId(); final Long actionId = registerTargetAndCancelActionId();
final Long actionNotExist = actionId + 1; final Long actionNotExist = actionId + 1;
sendActionUpdateStatus(new ActionUpdateStatus(actionNotExist, ActionStatus.CANCELED)); sendActionUpdateStatus(new DmfActionUpdateStatus(actionNotExist, DmfActionStatus.CANCELED));
verifyOneDeadLetterMessage(); verifyOneDeadLetterMessage();
} }
@@ -495,7 +495,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
public void canceledRejectedNotAllowActionStatus() { public void canceledRejectedNotAllowActionStatus() {
registerTargetAndSendActionStatus(ActionStatus.CANCEL_REJECTED); registerTargetAndSendActionStatus(DmfActionStatus.CANCEL_REJECTED);
verifyOneDeadLetterMessage(); verifyOneDeadLetterMessage();
} }
@@ -511,7 +511,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
public void canceledRejectedActionStatus() { public void canceledRejectedActionStatus() {
final Long actionId = registerTargetAndCancelActionId(); final Long actionId = registerTargetAndCancelActionId();
sendActionUpdateStatus(new ActionUpdateStatus(actionId, ActionStatus.CANCEL_REJECTED)); sendActionUpdateStatus(new DmfActionUpdateStatus(actionId, DmfActionStatus.CANCEL_REJECTED));
assertAction(actionId, Status.RUNNING, Status.CANCELING, Status.CANCEL_REJECTED); assertAction(actionId, Status.RUNNING, Status.CANCELING, Status.CANCEL_REJECTED);
} }
@@ -524,7 +524,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
// setup // setup
final String target = "ControllerAttributeTestTarget"; final String target = "ControllerAttributeTestTarget";
registerAndAssertTargetWithExistingTenant(target, 1); registerAndAssertTargetWithExistingTenant(target, 1);
final AttributeUpdate controllerAttribute = new AttributeUpdate(); final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
controllerAttribute.getAttributes().put("test1", "testA"); controllerAttribute.getAttributes().put("test1", "testA");
controllerAttribute.getAttributes().put("test2", "testB"); controllerAttribute.getAttributes().put("test2", "testB");
@@ -544,7 +544,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
// setup // setup
final String target = "ControllerAttributeTestTarget"; final String target = "ControllerAttributeTestTarget";
registerAndAssertTargetWithExistingTenant(target, 1); registerAndAssertTargetWithExistingTenant(target, 1);
final AttributeUpdate controllerAttribute = new AttributeUpdate(); final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
controllerAttribute.getAttributes().put("test1", "testA"); controllerAttribute.getAttributes().put("test1", "testA");
controllerAttribute.getAttributes().put("test2", "testB"); controllerAttribute.getAttributes().put("test2", "testB");
final Message createUpdateAttributesMessage = createUpdateAttributesMessage(null, TENANT_EXIST, final Message createUpdateAttributesMessage = createUpdateAttributesMessage(null, TENANT_EXIST,
@@ -556,7 +556,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
// verify // verify
verifyOneDeadLetterMessage(); verifyOneDeadLetterMessage();
final AttributeUpdate controllerAttributeEmpty = new AttributeUpdate(); final DmfAttributeUpdate controllerAttributeEmpty = new DmfAttributeUpdate();
assertUpdateAttributes(target, controllerAttributeEmpty.getAttributes()); assertUpdateAttributes(target, controllerAttributeEmpty.getAttributes());
} }
@@ -569,7 +569,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
// setup // setup
final String target = "ControllerAttributeTestTarget"; final String target = "ControllerAttributeTestTarget";
registerAndAssertTargetWithExistingTenant(target, 1); registerAndAssertTargetWithExistingTenant(target, 1);
final AttributeUpdate controllerAttribute = new AttributeUpdate(); final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
controllerAttribute.getAttributes().put("test1", "testA"); controllerAttribute.getAttributes().put("test1", "testA");
controllerAttribute.getAttributes().put("test2", "testB"); controllerAttribute.getAttributes().put("test2", "testB");
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody(target, final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody(target,
@@ -582,19 +582,19 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
verifyOneDeadLetterMessage(); verifyOneDeadLetterMessage();
} }
private Long registerTargetAndSendActionStatus(final ActionStatus sendActionStatus) { private Long registerTargetAndSendActionStatus(final DmfActionStatus sendActionStatus) {
final DistributionSetAssignmentResult assignmentResult = registerTargetAndAssignDistributionSet(); final DistributionSetAssignmentResult assignmentResult = registerTargetAndAssignDistributionSet();
final Long actionId = assignmentResult.getActions().get(0); final Long actionId = assignmentResult.getActions().get(0);
sendActionUpdateStatus(new ActionUpdateStatus(actionId, sendActionStatus)); sendActionUpdateStatus(new DmfActionUpdateStatus(actionId, sendActionStatus));
return actionId; return actionId;
} }
private void sendActionUpdateStatus(final ActionUpdateStatus actionStatus) { private void sendActionUpdateStatus(final DmfActionUpdateStatus actionStatus) {
final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, actionStatus); final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, actionStatus);
getDmfClient().send(eventMessage); getDmfClient().send(eventMessage);
} }
private void registerTargetAndSendAndAssertUpdateActionStatus(final ActionStatus sendActionStatus, private void registerTargetAndSendAndAssertUpdateActionStatus(final DmfActionStatus sendActionStatus,
final Status expectedActionStatus) { final Status expectedActionStatus) {
final Long actionId = registerTargetAndSendActionStatus(sendActionStatus); final Long actionId = registerTargetAndSendActionStatus(sendActionStatus);
assertAction(actionId, Status.RUNNING, expectedActionStatus); assertAction(actionId, Status.RUNNING, expectedActionStatus);
@@ -625,7 +625,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
} }
private void sendUpdateAttributeMessage(final String target, final String tenant, private void sendUpdateAttributeMessage(final String target, final String tenant,
final AttributeUpdate attributeUpdate) { final DmfAttributeUpdate attributeUpdate) {
final Message updateMessage = createUpdateAttributesMessage(target, tenant, attributeUpdate); final Message updateMessage = createUpdateAttributesMessage(target, tenant, attributeUpdate);
getDmfClient().send(updateMessage); getDmfClient().send(updateMessage);
} }

View File

@@ -21,8 +21,8 @@ import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.AttributeUpdate; import org.eclipse.hawkbit.dmf.json.model.DmfAttributeUpdate;
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
import org.eclipse.hawkbit.integration.listener.DeadletterListener; import org.eclipse.hawkbit.integration.listener.DeadletterListener;
import org.eclipse.hawkbit.integration.listener.ReplyToListener; import org.eclipse.hawkbit.integration.listener.ReplyToListener;
import org.eclipse.hawkbit.matcher.SoftwareModuleJsonMatcher; import org.eclipse.hawkbit.matcher.SoftwareModuleJsonMatcher;
@@ -31,6 +31,7 @@ import org.eclipse.hawkbit.rabbitmq.test.AmqpTestConfiguration;
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.util.IpUtil; import org.eclipse.hawkbit.util.IpUtil;
@@ -111,8 +112,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
} }
protected DistributionSetAssignmentResult registerTargetAndAssignDistributionSet(final Long assignDs, protected DistributionSetAssignmentResult registerTargetAndAssignDistributionSet(final Long assignDs,
final TargetUpdateStatus expectedStatus, final TargetUpdateStatus expectedStatus, final Set<SoftwareModule> expectedSoftwareModulesInMessage) {
final Set<org.eclipse.hawkbit.repository.model.SoftwareModule> expectedSoftwareModulesInMessage) {
registerAndAssertTargetWithExistingTenant(REGISTER_TARGET, 1, expectedStatus, CREATED_BY); registerAndAssertTargetWithExistingTenant(REGISTER_TARGET, 1, expectedStatus, CREATED_BY);
final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(assignDs, REGISTER_TARGET); final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(assignDs, REGISTER_TARGET);
@@ -138,12 +138,11 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
assertThat(headers.get(MessageHeaderKey.TYPE)).isEqualTo(MessageType.THING_DELETED.toString()); assertThat(headers.get(MessageHeaderKey.TYPE)).isEqualTo(MessageType.THING_DELETED.toString());
} }
protected void assertDownloadAndInstallMessage( protected void assertDownloadAndInstallMessage(final Set<SoftwareModule> dsModules) {
final Set<org.eclipse.hawkbit.repository.model.SoftwareModule> dsModules) {
final Message replyMessage = assertReplyMessageHeader(EventTopic.DOWNLOAD_AND_INSTALL); final Message replyMessage = assertReplyMessageHeader(EventTopic.DOWNLOAD_AND_INSTALL);
assertAllTargetsCount(1); assertAllTargetsCount(1);
final DownloadAndUpdateRequest downloadAndUpdateRequest = (DownloadAndUpdateRequest) getDmfClient() final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = (DmfDownloadAndUpdateRequest) getDmfClient()
.getMessageConverter().fromMessage(replyMessage); .getMessageConverter().fromMessage(replyMessage);
Assert.assertThat(dsModules, Assert.assertThat(dsModules,
@@ -255,7 +254,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration
} }
protected Message createUpdateAttributesMessage(final String target, final String tenant, protected Message createUpdateAttributesMessage(final String target, final String tenant,
final AttributeUpdate attributeUpdate) { final DmfAttributeUpdate attributeUpdate) {
final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant); final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant);
messageProperties.getHeaders().put(MessageHeaderKey.THING_ID, target); messageProperties.getHeaders().put(MessageHeaderKey.THING_ID, target);
messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.EVENT.toString()); messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.EVENT.toString());

View File

@@ -19,7 +19,7 @@ import org.hamcrest.Factory;
/** /**
* Set matcher for {@link SoftwareModule} and a list of * Set matcher for {@link SoftwareModule} and a list of
* {@link org.eclipse.hawkbit.dmf.json.model.SoftwareModule}. * {@link org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule}.
*/ */
public final class SoftwareModuleJsonMatcher { public final class SoftwareModuleJsonMatcher {
@@ -45,20 +45,20 @@ public final class SoftwareModuleJsonMatcher {
*/ */
@Factory @Factory
public static SoftwareModulesMatcher containsExactly( public static SoftwareModulesMatcher containsExactly(
final List<org.eclipse.hawkbit.dmf.json.model.SoftwareModule> expectedModules) { final List<org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule> expectedModules) {
return new SoftwareModulesMatcher(expectedModules); return new SoftwareModulesMatcher(expectedModules);
} }
private static class SoftwareModulesMatcher extends BaseMatcher<Set<SoftwareModule>> { private static class SoftwareModulesMatcher extends BaseMatcher<Set<SoftwareModule>> {
private final List<org.eclipse.hawkbit.dmf.json.model.SoftwareModule> expectedModules; private final List<org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule> expectedModules;
public SoftwareModulesMatcher(List<org.eclipse.hawkbit.dmf.json.model.SoftwareModule> expectedModules) { public SoftwareModulesMatcher(List<org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule> expectedModules) {
this.expectedModules = expectedModules; this.expectedModules = expectedModules;
} }
static boolean containsExactly(Object actual, static boolean containsExactly(Object actual,
List<org.eclipse.hawkbit.dmf.json.model.SoftwareModule> expected) { List<org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule> expected) {
if (actual == null) { if (actual == null) {
return expected == null; return expected == null;
} }
@@ -73,7 +73,7 @@ public final class SoftwareModuleJsonMatcher {
for (final SoftwareModule repoSoftwareModule : modules) { for (final SoftwareModule repoSoftwareModule : modules) {
boolean containsElement = false; boolean containsElement = false;
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule jsonSoftwareModule : expected) { for (final org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule jsonSoftwareModule : expected) {
if (!jsonSoftwareModule.getModuleId().equals(repoSoftwareModule.getId())) { if (!jsonSoftwareModule.getModuleId().equals(repoSoftwareModule.getId())) {
continue; continue;
} }

View File

@@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
*/ */
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public enum ActionStatus { public enum DmfActionStatus {
/** /**
* Action requests download by this target which has now started. * Action requests download by this target which has now started.
*/ */

View File

@@ -23,10 +23,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class ActionUpdateStatus { public class DmfActionUpdateStatus {
private final Long actionId; private final Long actionId;
private final ActionStatus actionStatus; private final DmfActionStatus actionStatus;
@JsonProperty @JsonProperty
private Long softwareModuleId; private Long softwareModuleId;
@@ -34,8 +34,8 @@ public class ActionUpdateStatus {
@JsonProperty @JsonProperty
private List<String> message; private List<String> message;
public ActionUpdateStatus(@JsonProperty(value = "actionId", required = true) Long actionId, public DmfActionUpdateStatus(@JsonProperty(value = "actionId", required = true) Long actionId,
@JsonProperty(value = "actionStatus", required = true) ActionStatus actionStatus) { @JsonProperty(value = "actionStatus", required = true) DmfActionStatus actionStatus) {
this.actionId = actionId; this.actionId = actionId;
this.actionStatus = actionStatus; this.actionStatus = actionStatus;
} }
@@ -52,7 +52,7 @@ public class ActionUpdateStatus {
this.softwareModuleId = softwareModuleId; this.softwareModuleId = softwareModuleId;
} }
public ActionStatus getActionStatus() { public DmfActionStatus getActionStatus() {
return actionStatus; return actionStatus;
} }

View File

@@ -24,12 +24,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class Artifact { public class DmfArtifact {
@JsonProperty @JsonProperty
private String filename; private String filename;
@JsonProperty @JsonProperty
private ArtifactHash hashes; private DmfArtifactHash hashes;
@JsonProperty @JsonProperty
private Long size; private Long size;
@@ -57,11 +57,11 @@ public class Artifact {
this.filename = filename; this.filename = filename;
} }
public ArtifactHash getHashes() { public DmfArtifactHash getHashes() {
return hashes; return hashes;
} }
public void setHashes(final ArtifactHash hashes) { public void setHashes(final DmfArtifactHash hashes) {
this.hashes = hashes; this.hashes = hashes;
} }

View File

@@ -14,7 +14,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* JSON representation of artifact hash. * JSON representation of artifact hash.
*/ */
public class ArtifactHash { public class DmfArtifactHash {
@JsonProperty @JsonProperty
private String sha1; private String sha1;
@@ -31,7 +31,7 @@ public class ArtifactHash {
* the md5 hash * the md5 hash
*/ */
@JsonCreator @JsonCreator
public ArtifactHash(@JsonProperty("sha1") final String sha1, @JsonProperty("md5") final String md5) { public DmfArtifactHash(@JsonProperty("sha1") final String sha1, @JsonProperty("md5") final String md5) {
super(); super();
this.sha1 = sha1; this.sha1 = sha1;
this.md5 = md5; this.md5 = md5;

View File

@@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class AttributeUpdate { public class DmfAttributeUpdate {
@JsonProperty @JsonProperty
private final Map<String, String> attributes = new HashMap<>(); private final Map<String, String> attributes = new HashMap<>();

View File

@@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class DownloadAndUpdateRequest { public class DmfDownloadAndUpdateRequest {
@JsonProperty @JsonProperty
private Long actionId; private Long actionId;
@@ -31,7 +31,7 @@ public class DownloadAndUpdateRequest {
private String targetSecurityToken; private String targetSecurityToken;
@JsonProperty @JsonProperty
private List<SoftwareModule> softwareModules; private List<DmfSoftwareModule> softwareModules;
public Long getActionId() { public Long getActionId() {
return actionId; return actionId;
@@ -49,7 +49,7 @@ public class DownloadAndUpdateRequest {
this.targetSecurityToken = targetSecurityToken; this.targetSecurityToken = targetSecurityToken;
} }
public List<SoftwareModule> getSoftwareModules() { public List<DmfSoftwareModule> getSoftwareModules() {
if (softwareModules == null) { if (softwareModules == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -63,7 +63,7 @@ public class DownloadAndUpdateRequest {
* @param createSoftwareModule * @param createSoftwareModule
* the module * the module
*/ */
public void addSoftwareModule(final SoftwareModule createSoftwareModule) { public void addSoftwareModule(final DmfSoftwareModule createSoftwareModule) {
if (softwareModules == null) { if (softwareModules == null) {
softwareModules = new ArrayList<>(); softwareModules = new ArrayList<>();
} }

View File

@@ -21,13 +21,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class DownloadResponse { public class DmfDownloadResponse {
@JsonProperty @JsonProperty
private String downloadUrl; private String downloadUrl;
@JsonProperty @JsonProperty
private Artifact artifact; private DmfArtifact artifact;
@JsonProperty @JsonProperty
private int responseCode; private int responseCode;
@@ -59,11 +59,11 @@ public class DownloadResponse {
this.downloadUrl = downloadUrl; this.downloadUrl = downloadUrl;
} }
public Artifact getArtifact() { public DmfArtifact getArtifact() {
return artifact; return artifact;
} }
public void setArtifact(final Artifact artifact) { public void setArtifact(final DmfArtifact artifact) {
this.artifact = artifact; this.artifact = artifact;
} }
} }

View File

@@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class SoftwareModule { public class DmfSoftwareModule {
@JsonProperty @JsonProperty
private Long moduleId; private Long moduleId;
@@ -35,7 +35,7 @@ public class SoftwareModule {
@JsonProperty @JsonProperty
private String moduleVersion; private String moduleVersion;
@JsonProperty @JsonProperty
private List<Artifact> artifacts; private List<DmfArtifact> artifacts;
public String getModuleType() { public String getModuleType() {
return moduleType; return moduleType;
@@ -53,7 +53,7 @@ public class SoftwareModule {
this.moduleVersion = moduleVersion; this.moduleVersion = moduleVersion;
} }
public List<Artifact> getArtifacts() { public List<DmfArtifact> getArtifacts() {
if (artifacts == null) { if (artifacts == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -70,7 +70,7 @@ public class SoftwareModule {
this.moduleId = moduleId; this.moduleId = moduleId;
} }
public void setArtifacts(final List<Artifact> artifacts) { public void setArtifacts(final List<DmfArtifact> artifacts) {
this.artifacts = artifacts; this.artifacts = artifacts;
} }

View File

@@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class TenantSecurityToken { public class DmfTenantSecurityToken {
public static final String AUTHORIZATION_HEADER = "Authorization"; public static final String AUTHORIZATION_HEADER = "Authorization";
@@ -58,7 +58,7 @@ public class TenantSecurityToken {
* the file to obtain * the file to obtain
*/ */
@JsonCreator @JsonCreator
public TenantSecurityToken(@JsonProperty("tenant") final String tenant, public DmfTenantSecurityToken(@JsonProperty("tenant") final String tenant,
@JsonProperty("tenantId") final Long tenantId, @JsonProperty("controllerId") final String controllerId, @JsonProperty("tenantId") final Long tenantId, @JsonProperty("controllerId") final String controllerId,
@JsonProperty("targetId") final Long targetId, @JsonProperty("targetId") final Long targetId,
@JsonProperty("fileResource") final FileResource fileResource) { @JsonProperty("fileResource") final FileResource fileResource) {
@@ -79,7 +79,7 @@ public class TenantSecurityToken {
* @param fileResource * @param fileResource
* the file to obtain * the file to obtain
*/ */
public TenantSecurityToken(final String tenant, final String controllerId, final FileResource fileResource) { public DmfTenantSecurityToken(final String tenant, final String controllerId, final FileResource fileResource) {
this(tenant, null, controllerId, null, fileResource); this(tenant, null, controllerId, null, fileResource);
} }
@@ -93,7 +93,7 @@ public class TenantSecurityToken {
* @param fileResource * @param fileResource
* the file to obtain * the file to obtain
*/ */
public TenantSecurityToken(final Long tenantId, final Long targetId, final FileResource fileResource) { public DmfTenantSecurityToken(final Long tenantId, final Long targetId, final FileResource fileResource) {
this(null, tenantId, null, targetId, fileResource); this(null, tenantId, null, targetId, fileResource);
} }

View File

@@ -20,8 +20,8 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -97,7 +97,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
return; return;
} }
final TenantSecurityToken secruityToken = createTenantSecruityTokenVariables((HttpServletRequest) request); final DmfTenantSecurityToken secruityToken = createTenantSecruityTokenVariables((HttpServletRequest) request);
if (secruityToken == null) { if (secruityToken == null) {
chain.doFilter(request, response); chain.doFilter(request, response);
return; return;
@@ -134,7 +134,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
* request does not match the pattern and no variables could be * request does not match the pattern and no variables could be
* extracted * extracted
*/ */
protected TenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request) { protected DmfTenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request) {
final String requestURI = request.getRequestURI(); final String requestURI = request.getRequestURI();
if (pathExtractor.match(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI)) { if (pathExtractor.match(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI)) {
@@ -166,9 +166,9 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
} }
} }
private TenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request, private DmfTenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request,
final String tenant, final String controllerId) { final String tenant, final String controllerId) {
final TenantSecurityToken secruityToken = new TenantSecurityToken(tenant, null, controllerId, null, final DmfTenantSecurityToken secruityToken = new DmfTenantSecurityToken(tenant, null, controllerId, null,
FileResource.createFileResourceBySha1("")); FileResource.createFileResourceBySha1(""));
final UnmodifiableIterator<String> forEnumeration = Iterators.forEnumeration(request.getHeaderNames()); final UnmodifiableIterator<String> forEnumeration = Iterators.forEnumeration(request.getHeaderNames());
forEnumeration.forEachRemaining(header -> secruityToken.putHeader(header, request.getHeader(header))); forEnumeration.forEachRemaining(header -> secruityToken.putHeader(header, request.getHeader(header)));
@@ -177,7 +177,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
@Override @Override
protected Object getPreAuthenticatedPrincipal(final HttpServletRequest request) { protected Object getPreAuthenticatedPrincipal(final HttpServletRequest request) {
final TenantSecurityToken secruityToken = createTenantSecruityTokenVariables(request); final DmfTenantSecurityToken secruityToken = createTenantSecruityTokenVariables(request);
if (secruityToken == null) { if (secruityToken == null) {
return null; return null;
} }
@@ -186,7 +186,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
@Override @Override
protected Object getPreAuthenticatedCredentials(final HttpServletRequest request) { protected Object getPreAuthenticatedCredentials(final HttpServletRequest request) {
final TenantSecurityToken secruityToken = createTenantSecruityTokenVariables(request); final DmfTenantSecurityToken secruityToken = createTenantSecruityTokenVariables(request);
if (secruityToken == null) { if (secruityToken == null) {
return null; return null;
} }

View File

@@ -8,7 +8,7 @@
*/ */
package org.eclipse.hawkbit.security; package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -41,7 +41,7 @@ public abstract class AbstractControllerAuthenticationFilter implements PreAuthe
protected abstract String getTenantConfigurationKey(); protected abstract String getTenantConfigurationKey();
@Override @Override
public boolean isEnable(final TenantSecurityToken secruityToken) { public boolean isEnable(final DmfTenantSecurityToken secruityToken) {
return tenantAware.runAsTenant(secruityToken.getTenant(), configurationKeyTenantRunner); return tenantAware.runAsTenant(secruityToken.getTenant(), configurationKeyTenantRunner);
} }

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.security;
import java.util.Optional; import java.util.Optional;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
@@ -62,9 +62,9 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken) {
final String controllerId = resolveControllerId(secruityToken); final String controllerId = resolveControllerId(secruityToken);
final String authHeader = secruityToken.getHeader(TenantSecurityToken.AUTHORIZATION_HEADER); final String authHeader = secruityToken.getHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER);
if ((authHeader != null) && authHeader.startsWith(TARGET_SECURITY_TOKEN_AUTH_SCHEME)) { if ((authHeader != null) && authHeader.startsWith(TARGET_SECURITY_TOKEN_AUTH_SCHEME)) {
LOGGER.debug("found authorization header with scheme {} using target security token for authentication", LOGGER.debug("found authorization header with scheme {} using target security token for authentication",
TARGET_SECURITY_TOKEN_AUTH_SCHEME); TARGET_SECURITY_TOKEN_AUTH_SCHEME);
@@ -77,7 +77,7 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken securityToken) { public HeaderAuthentication getPreAuthenticatedCredentials(final DmfTenantSecurityToken securityToken) {
final Optional<Target> target = systemSecurityContext.runAsSystemAsTenant(() -> { final Optional<Target> target = systemSecurityContext.runAsSystemAsTenant(() -> {
if (securityToken.getTargetId() != null) { if (securityToken.getTargetId() != null) {
return controllerManagement.findByTargetId(securityToken.getTargetId()); return controllerManagement.findByTargetId(securityToken.getTargetId());
@@ -90,7 +90,7 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro
.orElse(null); .orElse(null);
} }
private String resolveControllerId(final TenantSecurityToken securityToken) { private String resolveControllerId(final DmfTenantSecurityToken securityToken) {
if (securityToken.getControllerId() != null) { if (securityToken.getControllerId() != null) {
return securityToken.getControllerId(); return securityToken.getControllerId();
} }

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.security;
import java.util.Collection; import java.util.Collection;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
@@ -48,12 +48,12 @@ public class ControllerPreAuthenticatedAnonymousDownload extends AbstractControl
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken) {
return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId());
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken) {
return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId());
} }

View File

@@ -8,7 +8,7 @@
*/ */
package org.eclipse.hawkbit.security; package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
/** /**
* An anonymous controller filter which is only enabled in case of anonymous * An anonymous controller filter which is only enabled in case of anonymous
@@ -30,17 +30,17 @@ public class ControllerPreAuthenticatedAnonymousFilter implements PreAuthentific
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken) {
return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId());
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken) {
return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId());
} }
@Override @Override
public boolean isEnable(final TenantSecurityToken secruityToken) { public boolean isEnable(final DmfTenantSecurityToken secruityToken) {
return ddiSecurityConfiguration.getAuthentication().getAnonymous().isEnabled(); return ddiSecurityConfiguration.getAuthentication().getAnonymous().isEnabled();
} }

View File

@@ -8,7 +8,7 @@
*/ */
package org.eclipse.hawkbit.security; package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
@@ -56,8 +56,8 @@ public class ControllerPreAuthenticatedGatewaySecurityTokenFilter extends Abstra
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken) {
final String authHeader = secruityToken.getHeader(TenantSecurityToken.AUTHORIZATION_HEADER); final String authHeader = secruityToken.getHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER);
if ((authHeader != null) && authHeader.startsWith(GATEWAY_SECURITY_TOKEN_AUTH_SCHEME)) { if ((authHeader != null) && authHeader.startsWith(GATEWAY_SECURITY_TOKEN_AUTH_SCHEME)) {
LOGGER.debug("found authorization header with scheme {} using target security token for authentication", LOGGER.debug("found authorization header with scheme {} using target security token for authentication",
GATEWAY_SECURITY_TOKEN_AUTH_SCHEME); GATEWAY_SECURITY_TOKEN_AUTH_SCHEME);
@@ -71,7 +71,7 @@ public class ControllerPreAuthenticatedGatewaySecurityTokenFilter extends Abstra
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken) {
final String gatewayToken = tenantAware.runAsTenant(secruityToken.getTenant(), final String gatewayToken = tenantAware.runAsTenant(secruityToken.getTenant(),
gatewaySecurityTokenKeyConfigRunner); gatewaySecurityTokenKeyConfigRunner);
return new HeaderAuthentication(secruityToken.getControllerId(), gatewayToken); return new HeaderAuthentication(secruityToken.getControllerId(), gatewayToken);

View File

@@ -12,7 +12,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
@@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
/** /**
* An pre-authenticated processing filter which extracts the principal from a * An pre-authenticated processing filter which extracts the principal from a
* request URI and the credential from a request header in a the * request URI and the credential from a request header in a the
* {@link TenantSecurityToken}. * {@link DmfTenantSecurityToken}.
* *
*/ */
public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractControllerAuthenticationFilter { public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractControllerAuthenticationFilter {
@@ -77,7 +77,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont
} }
@Override @Override
public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { public HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken) {
// retrieve the common name header and the authority name header from // retrieve the common name header and the authority name header from
// the http request and combine them together // the http request and combine them together
final String commonNameValue = secruityToken.getHeader(caCommonNameHeader); final String commonNameValue = secruityToken.getHeader(caCommonNameHeader);
@@ -98,7 +98,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont
} }
@Override @Override
public Object getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { public Object getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken) {
final String authorityNameConfigurationValue = tenantAware.runAsTenant(secruityToken.getTenant(), final String authorityNameConfigurationValue = tenantAware.runAsTenant(secruityToken.getTenant(),
sslIssuerNameConfigTenantRunner); sslIssuerNameConfigTenantRunner);
String controllerId = secruityToken.getControllerId(); String controllerId = secruityToken.getControllerId();
@@ -121,7 +121,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont
* It's ok if we find the the hash in any the trusted CA chain to accept * It's ok if we find the the hash in any the trusted CA chain to accept
* this request for this tenant. * this request for this tenant.
*/ */
private String getIssuerHashHeader(final TenantSecurityToken secruityToken, final String knownIssuerHashes) { private String getIssuerHashHeader(final DmfTenantSecurityToken secruityToken, final String knownIssuerHashes) {
// there may be several knownIssuerHashes configured for the tenant // there may be several knownIssuerHashes configured for the tenant
final List<String> knownHashes = splitMultiHashBySemicolon(knownIssuerHashes); final List<String> knownHashes = splitMultiHashBySemicolon(knownIssuerHashes);

View File

@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.security;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
@@ -27,7 +27,7 @@ public interface PreAuthentificationFilter {
* the secruity info * the secruity info
* @return <true> is enabled <false> diabled * @return <true> is enabled <false> diabled
*/ */
boolean isEnable(TenantSecurityToken secruityToken); boolean isEnable(DmfTenantSecurityToken secruityToken);
/** /**
* Extract the principal information from the current secruityToken. * Extract the principal information from the current secruityToken.
@@ -36,7 +36,7 @@ public interface PreAuthentificationFilter {
* the secruityToken * the secruityToken
* @return the extracted tenant and controller id * @return the extracted tenant and controller id
*/ */
HeaderAuthentication getPreAuthenticatedPrincipal(TenantSecurityToken secruityToken); HeaderAuthentication getPreAuthenticatedPrincipal(DmfTenantSecurityToken secruityToken);
/** /**
* Extract the principal credentials from the current secruityToken. * Extract the principal credentials from the current secruityToken.
@@ -45,7 +45,7 @@ public interface PreAuthentificationFilter {
* the secruityToken * the secruityToken
* @return the extracted tenant and controller id * @return the extracted tenant and controller id
*/ */
Object getPreAuthenticatedCredentials(TenantSecurityToken secruityToken); Object getPreAuthenticatedCredentials(DmfTenantSecurityToken secruityToken);
/** /**
* Allows to add additional authorities to the successful authenticated * Allows to add additional authorities to the successful authenticated

View File

@@ -15,8 +15,8 @@ import static org.mockito.Mockito.when;
import java.util.Collection; import java.util.Collection;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
@@ -41,7 +41,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
private TenantConfigurationManagement tenantConfigurationManagementMock; private TenantConfigurationManagement tenantConfigurationManagementMock;
@Mock @Mock
private TenantSecurityToken tenantSecurityTokenMock; private DmfTenantSecurityToken tenantSecurityTokenMock;
private final SecurityContextTenantAware tenantAware = new SecurityContextTenantAware(); private final SecurityContextTenantAware tenantAware = new SecurityContextTenantAware();
@@ -71,7 +71,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
@Test @Test
@Description("Tests the filter for issuer hash based authentication with a single known hash") @Description("Tests the filter for issuer hash based authentication with a single known hash")
public void testIssuerHashBasedAuthenticationWithSingleKnownHash() { public void testIssuerHashBasedAuthenticationWithSingleKnownHash() {
final TenantSecurityToken securityToken = prepareSecurityToken(SINGLE_HASH); final DmfTenantSecurityToken securityToken = prepareSecurityToken(SINGLE_HASH);
// use single known hash // use single known hash
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class)))
@@ -82,7 +82,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
@Test @Test
@Description("Tests the filter for issuer hash based authentication with multiple known hashes") @Description("Tests the filter for issuer hash based authentication with multiple known hashes")
public void testIssuerHashBasedAuthenticationWithMultipleKnownHashes() { public void testIssuerHashBasedAuthenticationWithMultipleKnownHashes() {
final TenantSecurityToken securityToken = prepareSecurityToken(SINGLE_HASH); final DmfTenantSecurityToken securityToken = prepareSecurityToken(SINGLE_HASH);
// use multiple known hashes // use multiple known hashes
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class)))
@@ -93,7 +93,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
@Test @Test
@Description("Tests the filter for issuer hash based authentication with unknown hash") @Description("Tests the filter for issuer hash based authentication with unknown hash")
public void testIssuerHashBasedAuthenticationWithUnknownHash() { public void testIssuerHashBasedAuthenticationWithUnknownHash() {
final TenantSecurityToken securityToken = prepareSecurityToken(UNKNOWN_HASH); final DmfTenantSecurityToken securityToken = prepareSecurityToken(UNKNOWN_HASH);
// use single known hash // use single known hash
when(tenantConfigurationManagementMock.getConfigurationValue( when(tenantConfigurationManagementMock.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME), eq(String.class)))
@@ -104,8 +104,8 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
@Test @Test
@Description("Tests different values for issuer hash header and inspects the credentials") @Description("Tests different values for issuer hash header and inspects the credentials")
public void useDifferentValuesForIssuerHashHeader() { public void useDifferentValuesForIssuerHashHeader() {
final TenantSecurityToken securityToken1 = prepareSecurityToken(SINGLE_HASH); final DmfTenantSecurityToken securityToken1 = prepareSecurityToken(SINGLE_HASH);
final TenantSecurityToken securityToken2 = prepareSecurityToken(SECOND_HASH); final DmfTenantSecurityToken securityToken2 = prepareSecurityToken(SECOND_HASH);
final HeaderAuthentication expected1 = new HeaderAuthentication(CA_COMMON_NAME_VALUE, SINGLE_HASH); final HeaderAuthentication expected1 = new HeaderAuthentication(CA_COMMON_NAME_VALUE, SINGLE_HASH);
final HeaderAuthentication expected2 = new HeaderAuthentication(CA_COMMON_NAME_VALUE, SECOND_HASH); final HeaderAuthentication expected2 = new HeaderAuthentication(CA_COMMON_NAME_VALUE, SECOND_HASH);
@@ -130,8 +130,8 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
} }
private static TenantSecurityToken prepareSecurityToken(final String issuerHashHeaderValue) { private static DmfTenantSecurityToken prepareSecurityToken(final String issuerHashHeaderValue) {
final TenantSecurityToken securityToken = new TenantSecurityToken("DEFAULT", CA_COMMON_NAME_VALUE, final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken("DEFAULT", CA_COMMON_NAME_VALUE,
FileResource.createFileResourceBySha1("12345")); FileResource.createFileResourceBySha1("12345"));
securityToken.putHeader(CA_COMMON_NAME, CA_COMMON_NAME_VALUE); securityToken.putHeader(CA_COMMON_NAME, CA_COMMON_NAME_VALUE);
securityToken.putHeader(X_SSL_ISSUER_HASH_1, issuerHashHeaderValue); securityToken.putHeader(X_SSL_ISSUER_HASH_1, issuerHashHeaderValue);