RED-4512: Intercept queue messages and add/read tenant
This commit is contained in:
parent
9ab04acece
commit
5df851ed06
@ -23,6 +23,7 @@ import com.iqser.red.service.peristence.v1.server.client.RedactionClient;
|
||||
import com.iqser.red.service.peristence.v1.server.configuration.CleanupDownloadSchedulerConfiguration;
|
||||
import com.iqser.red.service.peristence.v1.server.configuration.MessagingConfiguration;
|
||||
import com.iqser.red.service.peristence.v1.server.multitenancy.AsyncConfig;
|
||||
import com.iqser.red.service.peristence.v1.server.multitenancy.MultiTenancyMessagingConfiguration;
|
||||
import com.iqser.red.service.peristence.v1.server.multitenancy.MultiTenancyWebConfiguration;
|
||||
import com.iqser.red.service.peristence.v1.server.settings.FileManagementServiceSettings;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.PersistenceServiceProcessorConfiguration;
|
||||
@ -32,7 +33,7 @@ import com.iqser.red.service.persistence.management.v1.processor.PersistenceServ
|
||||
@EnableScheduling
|
||||
@EnableConfigurationProperties(FileManagementServiceSettings.class)
|
||||
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class, CassandraAutoConfiguration.class, DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class, QuartzAutoConfiguration.class})
|
||||
@Import({MultiTenancyWebConfiguration.class, PersistenceServiceProcessorConfiguration.class, MessagingConfiguration.class, CleanupDownloadSchedulerConfiguration.class, AsyncConfig.class})
|
||||
@Import({MultiTenancyWebConfiguration.class, PersistenceServiceProcessorConfiguration.class, MessagingConfiguration.class, CleanupDownloadSchedulerConfiguration.class, AsyncConfig.class, MultiTenancyMessagingConfiguration.class})
|
||||
@EnableFeignClients(basePackageClasses = {RedactionClient.class})
|
||||
public class Application {
|
||||
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
package com.iqser.red.service.peristence.v1.server.multitenancy;
|
||||
|
||||
import static com.iqser.red.service.peristence.v1.server.multitenancy.TenantInterceptor.DEFAULT_TENANT;
|
||||
import static com.iqser.red.service.peristence.v1.server.multitenancy.TenantInterceptor.TENANT_HEADER_NAME;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.utils.multitenancy.TenantContext;
|
||||
|
||||
@Configuration
|
||||
public class MultiTenancyMessagingConfiguration {
|
||||
|
||||
@Bean
|
||||
public static BeanPostProcessor multitenancyBeanPostProcessor() {
|
||||
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
if (bean instanceof RabbitTemplate) {
|
||||
|
||||
RabbitTemplate rabbitTemplate = (RabbitTemplate) bean;
|
||||
|
||||
rabbitTemplate.setBeforePublishPostProcessors(m -> {
|
||||
m.getMessageProperties().setHeader(TENANT_HEADER_NAME, TenantContext.getTenantId());
|
||||
return m;
|
||||
});
|
||||
|
||||
rabbitTemplate.addAfterReceivePostProcessors(m -> {
|
||||
String tenant = m.getMessageProperties().getHeader(TENANT_HEADER_NAME);
|
||||
|
||||
if (tenant != null) {
|
||||
TenantContext.setTenantId(tenant);
|
||||
} else {
|
||||
// TODO Remove if multitenancy is fully integrated.
|
||||
TenantContext.setTenantId(DEFAULT_TENANT);
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,18 +11,17 @@ import com.iqser.red.service.persistence.management.v1.processor.utils.multitena
|
||||
public class TenantInterceptor implements WebRequestInterceptor {
|
||||
|
||||
public static final String DEFAULT_TENANT = "redaction";
|
||||
public static final String TENANT_HEADER_NAME = "X-TENANT-ID";
|
||||
|
||||
|
||||
@Override
|
||||
public void preHandle(WebRequest request) {
|
||||
|
||||
String tenantId = null;
|
||||
if (request.getHeader("X-TENANT-ID") != null) {
|
||||
tenantId = request.getHeader("X-TENANT-ID");
|
||||
if (request.getHeader(TENANT_HEADER_NAME) != null) {
|
||||
TenantContext.setTenantId(request.getHeader(TENANT_HEADER_NAME));
|
||||
} else {
|
||||
tenantId = DEFAULT_TENANT; // TODO Remove if multitenancy is fully integrated.
|
||||
TenantContext.setTenantId(DEFAULT_TENANT);
|
||||
}
|
||||
TenantContext.setTenantId(tenantId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user