Improved AccessContext (#3029)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.audit.AuditLog;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.context.Principal;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
|
||||
@@ -47,7 +48,6 @@ import org.eclipse.hawkbit.repository.model.ActionProperties;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAwareAuthenticationDetails;
|
||||
import org.eclipse.hawkbit.utils.IpUtil;
|
||||
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
|
||||
import org.springframework.amqp.core.Message;
|
||||
@@ -170,11 +170,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
private static void setTenantSecurityContext(final String tenant) {
|
||||
final AnonymousAuthenticationToken authenticationToken = new AnonymousAuthenticationToken(
|
||||
UUID.randomUUID().toString(), "AMQP-Controller",
|
||||
List.of(new SimpleGrantedAuthority(SpRole.CONTROLLER_ROLE)));
|
||||
authenticationToken.setDetails(new TenantAwareAuthenticationDetails(tenant, true));
|
||||
setSecurityContext(authenticationToken);
|
||||
setSecurityContext(new AnonymousAuthenticationToken(
|
||||
UUID.randomUUID().toString(), new Principal(tenant, "AMQP-Controller"),
|
||||
List.of(new SimpleGrantedAuthority(SpRole.CONTROLLER_ROLE))));
|
||||
}
|
||||
|
||||
private static boolean isOptionalMessageBodyEmpty(final Message message) {
|
||||
|
||||
@@ -70,7 +70,6 @@ import org.springframework.util.CollectionUtils;
|
||||
abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegrationTest {
|
||||
|
||||
protected static final String TENANT_EXIST = "DEFAULT";
|
||||
protected static final String CREATED_BY = "CONTROLLER_PLUG_AND_PLAY";
|
||||
protected static final String CORRELATION_ID = UUID.randomUUID().toString();
|
||||
|
||||
protected ReplyToListener replyToListener;
|
||||
@@ -132,7 +131,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
protected DistributionSetAssignmentResult registerTargetAndAssignDistributionSet(final Long assignDs,
|
||||
final TargetUpdateStatus expectedStatus, final Set<SoftwareModule> expectedSoftwareModulesInMessage,
|
||||
final String controllerId) {
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, 1, expectedStatus, CREATED_BY);
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, 1, expectedStatus, CONTROLLER_PLUG_AND_PLAY);
|
||||
|
||||
final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(assignDs, controllerId);
|
||||
if (isConfirmationFlowEnabled()) {
|
||||
@@ -253,7 +252,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
protected void registerAndAssertTargetWithExistingTenant(final String controllerId,
|
||||
final int existingTargetsAfterCreation) {
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, existingTargetsAfterCreation,
|
||||
TargetUpdateStatus.REGISTERED, CREATED_BY);
|
||||
TargetUpdateStatus.REGISTERED, CONTROLLER_PLUG_AND_PLAY);
|
||||
}
|
||||
|
||||
protected void registerAndAssertTargetWithExistingTenant(final String controllerId,
|
||||
@@ -282,7 +281,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
final Map<String, String> attributes) {
|
||||
final int version = controllerManagement.findByControllerId(controllerId).get().getOptLockRevision();
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, name, existingTargetsAfterCreation,
|
||||
expectedTargetStatus, CREATED_BY, attributes, () -> findTargetBasedOnNewVersion(controllerId, version));
|
||||
expectedTargetStatus, CONTROLLER_PLUG_AND_PLAY, attributes, () -> findTargetBasedOnNewVersion(controllerId, version));
|
||||
}
|
||||
|
||||
protected Message createTargetMessage(final String controllerId, final String tenant) {
|
||||
|
||||
@@ -133,7 +133,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
void registerTargetWithName() {
|
||||
final String controllerId = TARGET_PREFIX + "registerTargetWithName";
|
||||
final String name = "NonDefaultTargetName";
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CREATED_BY, null);
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CONTROLLER_PLUG_AND_PLAY, null);
|
||||
registerSameTargetAndAssertBasedOnVersion(controllerId, name + "_updated", 1, TargetUpdateStatus.REGISTERED, null);
|
||||
|
||||
Mockito.verifyNoInteractions(getDeadletterListener());
|
||||
@@ -153,7 +153,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
attributes.put("testKey1", "testValue1");
|
||||
attributes.put("testKey2", "testValue2");
|
||||
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, null, 1, TargetUpdateStatus.REGISTERED, CREATED_BY, attributes);
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, null, 1, TargetUpdateStatus.REGISTERED, CONTROLLER_PLUG_AND_PLAY, attributes);
|
||||
|
||||
attributes.put("testKey3", "testValue3");
|
||||
registerSameTargetAndAssertBasedOnVersion(controllerId, null, 1, TargetUpdateStatus.REGISTERED, attributes);
|
||||
@@ -176,7 +176,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("testKey1", "testValue1");
|
||||
attributes.put("testKey2", "testValue2");
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CREATED_BY, attributes);
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CONTROLLER_PLUG_AND_PLAY, attributes);
|
||||
|
||||
attributes.put("testKey3", "testValue3");
|
||||
registerSameTargetAndAssertBasedOnVersion(controllerId, name + "_updated", 1, TargetUpdateStatus.REGISTERED, attributes);
|
||||
|
||||
Reference in New Issue
Block a user