Code refactoring of hawkbit-core and hawkbit-autoconfigure (#2051)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.autoconfigure.cache;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
* is used for the lifetime limit of data in caches. After lifetime the data
|
||||
* gets reloaded out of the database.
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties("hawkbit.cache.global")
|
||||
public class CacheProperties {
|
||||
|
||||
@@ -31,23 +33,7 @@ public class CacheProperties {
|
||||
*/
|
||||
private int initialDelay;
|
||||
|
||||
public long getInitialDelay() {
|
||||
return initialDelay;
|
||||
}
|
||||
|
||||
public void setInitialDelay(final int initialDelay) {
|
||||
this.initialDelay = initialDelay;
|
||||
}
|
||||
|
||||
public int getTtl() {
|
||||
return ttl;
|
||||
}
|
||||
|
||||
public void setTtl(final int ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
|
||||
public final TimeUnit getTtlUnit() {
|
||||
return TimeUnit.MILLISECONDS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,4 @@ public class JpaRepositoryAutoConfiguration {
|
||||
public LockRegistry lockRegistry() {
|
||||
return new DefaultLockRegistry();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.messaging.converter.MessageConverter;
|
||||
|
||||
/**
|
||||
* Auto configuration for the event bus.
|
||||
* Autoconfiguration for the event bus.
|
||||
*/
|
||||
@Configuration
|
||||
@RemoteApplicationEventScan(basePackages = "org.eclipse.hawkbit.repository.event.remote")
|
||||
@@ -47,14 +47,12 @@ import org.springframework.messaging.converter.MessageConverter;
|
||||
public class EventPublisherAutoConfiguration {
|
||||
|
||||
/**
|
||||
* Server internal event publisher that allows parallel event processing if
|
||||
* the event listener is marked as so.
|
||||
* Server internal event publisher that allows parallel event processing if the event listener is marked as so.
|
||||
*
|
||||
* @return publisher bean
|
||||
*/
|
||||
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
|
||||
ApplicationEventMulticaster applicationEventMulticaster(@Qualifier("asyncExecutor") final Executor executor,
|
||||
final TenantAware tenantAware) {
|
||||
ApplicationEventMulticaster applicationEventMulticaster(@Qualifier("asyncExecutor") final Executor executor, final TenantAware tenantAware) {
|
||||
final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new TenantAwareApplicationEventPublisher(
|
||||
tenantAware, applicationEventFilter());
|
||||
simpleApplicationEventMulticaster.setTaskExecutor(executor);
|
||||
@@ -85,26 +83,18 @@ public class EventPublisherAutoConfiguration {
|
||||
private static class TenantAwareApplicationEventPublisher extends SimpleApplicationEventMulticaster {
|
||||
|
||||
private final TenantAware tenantAware;
|
||||
|
||||
private final ApplicationEventFilter applicationEventFilter;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ServiceMatcher serviceMatcher;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param tenantAware the tenant ware
|
||||
*/
|
||||
protected TenantAwareApplicationEventPublisher(final TenantAware tenantAware,
|
||||
final ApplicationEventFilter applicationEventFilter) {
|
||||
protected TenantAwareApplicationEventPublisher(final TenantAware tenantAware, final ApplicationEventFilter applicationEventFilter) {
|
||||
this.tenantAware = tenantAware;
|
||||
this.applicationEventFilter = applicationEventFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Was overridden that not every event has to run within a own
|
||||
* tenantAware.
|
||||
* Was overridden that not every event has to run within an own tenantAware.
|
||||
*/
|
||||
@Override
|
||||
public void multicastEvent(final ApplicationEvent event, final ResolvableType eventType) {
|
||||
@@ -112,11 +102,10 @@ public class EventPublisherAutoConfiguration {
|
||||
return;
|
||||
}
|
||||
|
||||
if (serviceMatcher == null || !(event instanceof RemoteTenantAwareEvent)) {
|
||||
if (serviceMatcher == null || !(event instanceof final RemoteTenantAwareEvent remoteEvent)) {
|
||||
super.multicastEvent(event, eventType);
|
||||
return;
|
||||
}
|
||||
final RemoteTenantAwareEvent remoteEvent = (RemoteTenantAwareEvent) event;
|
||||
|
||||
if (serviceMatcher.isFromSelf(remoteEvent)) {
|
||||
super.multicastEvent(event, eventType);
|
||||
@@ -128,7 +117,6 @@ public class EventPublisherAutoConfiguration {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnBusEnabled
|
||||
@@ -142,7 +130,5 @@ public class EventPublisherAutoConfiguration {
|
||||
public MessageConverter busProtoBufConverter() {
|
||||
return new BusProtoStuffMessageConverter();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,4 @@ public class AsyncConfigurerThreadPoolProperties {
|
||||
* time that excess idle threads will wait for new tasks before terminating.
|
||||
*/
|
||||
private Long idleTimeout = 10000L;
|
||||
}
|
||||
}
|
||||
@@ -57,8 +57,8 @@ import org.springframework.util.CollectionUtils;
|
||||
public class SecurityAutoConfiguration {
|
||||
|
||||
/**
|
||||
* Creates a {@link ContextAware} (hence {@link TenantAware}) bean based on the given
|
||||
* {@link UserAuthoritiesResolver} and {@link SecurityContextSerializer}.
|
||||
* Creates a {@link ContextAware} (hence {@link TenantAware}) bean based on the given {@link UserAuthoritiesResolver} and
|
||||
* {@link SecurityContextSerializer}.
|
||||
*
|
||||
* @param authoritiesResolver The user authorities/roles resolver
|
||||
* @param securityContextSerializer The security context serializer.
|
||||
@@ -73,8 +73,7 @@ public class SecurityAutoConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link UserAuthoritiesResolver} bean that is responsible for
|
||||
* resolving user authorities/roles.
|
||||
* Creates a {@link UserAuthoritiesResolver} bean that is responsible for resolving user authorities/roles.
|
||||
*
|
||||
* @param securityProperties The Spring {@link SecurityProperties} for the security user
|
||||
* @param tenantAwareUserProperties The {@link TenantAwareUserProperties} for the managed users
|
||||
@@ -82,7 +81,8 @@ public class SecurityAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public UserAuthoritiesResolver inMemoryAuthoritiesResolver(final SecurityProperties securityProperties,
|
||||
public UserAuthoritiesResolver inMemoryAuthoritiesResolver(
|
||||
final SecurityProperties securityProperties,
|
||||
final TenantAwareUserProperties tenantAwareUserProperties) {
|
||||
final Map<String, User> tenantAwareUsers = tenantAwareUserProperties.getUser();
|
||||
final Map<String, List<String>> usersToPermissions;
|
||||
@@ -113,8 +113,7 @@ public class SecurityAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SystemSecurityContext systemSecurityContext(
|
||||
final TenantAware tenantAware, final RoleHierarchy roleHierarchy) {
|
||||
public SystemSecurityContext systemSecurityContext(final TenantAware tenantAware, final RoleHierarchy roleHierarchy) {
|
||||
return new SystemSecurityContext(tenantAware, roleHierarchy);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user