diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java index c708ac0c7..b7570f185 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java @@ -153,4 +153,7 @@ public class AmqpControllerAuthentfication { this.tenantAware = tenantAware; } + void setSystemSecurityContext(final SystemSecurityContext systemSecurityContext) { + this.systemSecurityContext = systemSecurityContext; + } } diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java index e25afe490..19ecc22ca 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java @@ -26,6 +26,7 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SecurityProperties; +import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.junit.Before; import org.junit.Test; @@ -81,7 +82,8 @@ public class AmqpControllerAuthentficationTest { tenantConfigurationManagement = mock(TenantConfigurationManagement.class); authenticationManager.setTenantConfigurationManagement(tenantConfigurationManagement); - when(tenantConfigurationManagement.getConfigurationValue(any(), eq(Boolean.class))).thenReturn(CONFIG_VALUE_FALSE); + when(tenantConfigurationManagement.getConfigurationValue(any(), eq(Boolean.class))) + .thenReturn(CONFIG_VALUE_FALSE); final ControllerManagement controllerManagement = mock(ControllerManagement.class); when(controllerManagement.getSecurityTokenByControllerId(anyString())).thenReturn(CONTROLLLER_ID); @@ -89,7 +91,10 @@ public class AmqpControllerAuthentficationTest { amqpMessageHandlerService.setArtifactManagement(mock(ArtifactManagement.class)); - authenticationManager.setTenantAware(new SecurityContextTenantAware()); + final SecurityContextTenantAware tenantAware = new SecurityContextTenantAware(); + authenticationManager.setTenantAware(tenantAware); + final SystemSecurityContext systemSecurityContext = new SystemSecurityContext(tenantAware); + authenticationManager.setSystemSecurityContext(systemSecurityContext); authenticationManager.postConstruct(); amqpMessageHandlerService.setAuthenticationManager(authenticationManager); } diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java index 7e3dc8de7..334065a10 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java @@ -38,8 +38,18 @@ public class SystemSecurityContext { private static final Logger logger = LoggerFactory.getLogger(SystemSecurityContext.class); + private final TenantAware tenantAware; + + /** + * Autowired constructor. + * + * @param tenantAware + * the tenant aware bean to retrieve the current tenant + */ @Autowired - private TenantAware tenantAware; + public SystemSecurityContext(final TenantAware tenantAware) { + this.tenantAware = tenantAware; + } public T runAsSystem(final Callable callable) { final SecurityContext oldContext = SecurityContextHolder.getContext();