Fix EventPublisherAuthConfiguration to run as system (#2099)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter;
|
|||||||
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent;
|
import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent;
|
||||||
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
@@ -53,9 +53,10 @@ public class EventPublisherAutoConfiguration {
|
|||||||
*/
|
*/
|
||||||
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
|
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
|
||||||
ApplicationEventMulticaster applicationEventMulticaster(
|
ApplicationEventMulticaster applicationEventMulticaster(
|
||||||
@Qualifier("asyncExecutor") final Executor executor, final TenantAware tenantAware) {
|
@Qualifier("asyncExecutor") final Executor executor,
|
||||||
|
final SystemSecurityContext systemSecurityContext, final ApplicationEventFilter applicationEventFilter) {
|
||||||
final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new TenantAwareApplicationEventPublisher(
|
final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new TenantAwareApplicationEventPublisher(
|
||||||
tenantAware, applicationEventFilter());
|
systemSecurityContext, applicationEventFilter);
|
||||||
simpleApplicationEventMulticaster.setTaskExecutor(executor);
|
simpleApplicationEventMulticaster.setTaskExecutor(executor);
|
||||||
return simpleApplicationEventMulticaster;
|
return simpleApplicationEventMulticaster;
|
||||||
}
|
}
|
||||||
@@ -82,14 +83,15 @@ public class EventPublisherAutoConfiguration {
|
|||||||
|
|
||||||
private static class TenantAwareApplicationEventPublisher extends SimpleApplicationEventMulticaster {
|
private static class TenantAwareApplicationEventPublisher extends SimpleApplicationEventMulticaster {
|
||||||
|
|
||||||
private final TenantAware tenantAware;
|
private final SystemSecurityContext systemSecurityContext;
|
||||||
private final ApplicationEventFilter applicationEventFilter;
|
private final ApplicationEventFilter applicationEventFilter;
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private ServiceMatcher serviceMatcher;
|
private ServiceMatcher serviceMatcher;
|
||||||
|
|
||||||
protected TenantAwareApplicationEventPublisher(final TenantAware tenantAware, final ApplicationEventFilter applicationEventFilter) {
|
protected TenantAwareApplicationEventPublisher(
|
||||||
this.tenantAware = tenantAware;
|
final SystemSecurityContext systemSecurityContext, final ApplicationEventFilter applicationEventFilter) {
|
||||||
|
this.systemSecurityContext = systemSecurityContext;
|
||||||
this.applicationEventFilter = applicationEventFilter;
|
this.applicationEventFilter = applicationEventFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,10 +114,10 @@ public class EventPublisherAutoConfiguration {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tenantAware.runAsTenant(remoteEvent.getTenant(), () -> {
|
systemSecurityContext.runAsSystemAsTenant(() -> {
|
||||||
super.multicastEvent(event, eventType);
|
super.multicastEvent(event, eventType);
|
||||||
return null;
|
return null;
|
||||||
});
|
}, remoteEvent.getTenant());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,17 +153,13 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
systemSecurityContext.runAsSystemAsTenant(() -> {
|
final List<Target> filteredTargetList = getTargetsWithoutPendingCancellations(
|
||||||
final List<Target> filteredTargetList = getTargetsWithoutPendingCancellations(
|
assignedEvent.getTenant(), assignedEvent.getActions().keySet());
|
||||||
assignedEvent.getTenant(), assignedEvent.getActions().keySet());
|
|
||||||
|
|
||||||
if (!filteredTargetList.isEmpty()) {
|
if (!filteredTargetList.isEmpty()) {
|
||||||
log.debug("targetAssignDistributionSet retrieved. I will forward it to DMF broker.");
|
log.debug("targetAssignDistributionSet retrieved. I will forward it to DMF broker.");
|
||||||
sendUpdateMessageToTargets(assignedEvent.getDistributionSetId(), assignedEvent.getActions(), filteredTargetList);
|
sendUpdateMessageToTargets(assignedEvent.getDistributionSetId(), assignedEvent.getActions(), filteredTargetList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}, assignedEvent.getTenant());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,11 +173,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
systemSecurityContext.runAsSystemAsTenant(() -> {
|
log.debug("MultiActionEvent received for {}", multiActionEvent.getControllerIds());
|
||||||
log.debug("MultiActionEvent received for {}", multiActionEvent.getControllerIds());
|
sendMultiActionRequestMessages(multiActionEvent.getTenant(), multiActionEvent.getControllerIds());
|
||||||
sendMultiActionRequestMessages(multiActionEvent.getTenant(), multiActionEvent.getControllerIds());
|
|
||||||
return null;
|
|
||||||
}, multiActionEvent.getTenant());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendUpdateMessageToTarget(
|
protected void sendUpdateMessageToTarget(
|
||||||
@@ -238,20 +231,16 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
systemSecurityContext.runAsSystemAsTenant(() -> {
|
final List<Target> eventTargets = partitionedParallelExecution(
|
||||||
final List<Target> eventTargets = partitionedParallelExecution(
|
cancelEvent.getActions().keySet(), targetManagement::getByControllerID);
|
||||||
cancelEvent.getActions().keySet(), targetManagement::getByControllerID);
|
|
||||||
|
|
||||||
eventTargets.forEach(target ->
|
eventTargets.forEach(target ->
|
||||||
cancelEvent.getActionPropertiesForController(target.getControllerId())
|
cancelEvent.getActionPropertiesForController(target.getControllerId())
|
||||||
.map(ActionProperties::getId)
|
.map(ActionProperties::getId)
|
||||||
.ifPresent(actionId ->
|
.ifPresent(actionId ->
|
||||||
sendCancelMessageToTarget(cancelEvent.getTenant(), target.getControllerId(), actionId, target.getAddress())
|
sendCancelMessageToTarget(cancelEvent.getTenant(), target.getControllerId(), actionId, target.getAddress())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
|
||||||
}, cancelEvent.getTenant());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user