Fix class cast exception when deserielize getRemoteEvent() by any ServiceEvent (#2593)
Co-authored-by: vasilchev <vasil.ilchev@bosch.com>
This commit is contained in:
@@ -10,15 +10,15 @@
|
||||
package org.eclipse.hawkbit.repository.event.remote.service;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.AbstractRemoteEvent;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractServiceRemoteEvent<T extends RemoteTenantAwareEvent> extends RemoteTenantAwareEvent {
|
||||
public abstract class AbstractServiceRemoteEvent<T extends AbstractRemoteEvent> extends AbstractRemoteEvent {
|
||||
|
||||
private final T remoteEvent;
|
||||
|
||||
protected AbstractServiceRemoteEvent(T remoteEvent) {
|
||||
super(remoteEvent == null ? "_empty_tenant_" : remoteEvent.getTenant(), remoteEvent == null ? "_empty_source_" : remoteEvent.getSource());
|
||||
super(remoteEvent == null ? "_empty_source_" : remoteEvent.getSource());
|
||||
this.remoteEvent = remoteEvent;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
||||
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.event.remote.AbstractRemoteEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.service.AbstractServiceRemoteEvent;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -101,6 +102,15 @@ public class EventPublisherConfiguration {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof final AbstractServiceRemoteEvent<?> serviceRemoteEvent
|
||||
&& serviceRemoteEvent.getRemoteEvent() instanceof RemoteTenantAwareEvent tenantAwareEvent) {
|
||||
systemSecurityContext.runAsSystemAsTenant(() -> {
|
||||
super.multicastEvent(event, eventType);
|
||||
return null;
|
||||
}, tenantAwareEvent.getTenant());
|
||||
return;
|
||||
}
|
||||
|
||||
super.multicastEvent(event, eventType);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user