More ordering issues in service apps
* The TraceAutoConfiguration in the service project was loading too early because it contains a BPP * It also had a Spring Security dependency without any @Conditional* configuration * Fixed by nesting the BPP in a class with @Conditional*
This commit is contained in:
@@ -37,6 +37,7 @@ import org.springframework.bootstrap.service.properties.ContainerProperties;
|
||||
import org.springframework.bootstrap.service.properties.ContainerProperties.Tomcat;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -48,6 +49,7 @@ import org.springframework.util.StringUtils;
|
||||
// the right order
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Servlet.class })
|
||||
@Order(Integer.MIN_VALUE)
|
||||
public class ContainerConfiguration implements BeanPostProcessor, BeanFactoryAware {
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
@@ -18,17 +18,19 @@ package org.springframework.bootstrap.autoconfigure.service;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||
import org.springframework.bootstrap.service.properties.ContainerProperties;
|
||||
import org.springframework.bootstrap.service.trace.InMemoryTraceRepository;
|
||||
import org.springframework.bootstrap.service.trace.SecurityFilterPostProcessor;
|
||||
import org.springframework.bootstrap.service.trace.TraceEndpoint;
|
||||
import org.springframework.bootstrap.service.trace.TraceRepository;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
/**
|
||||
@@ -41,24 +43,34 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
@ConditionalOnMissingBean({ TraceEndpoint.class })
|
||||
public class TraceAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private ContainerProperties configuration = new ContainerProperties();
|
||||
|
||||
@Autowired(required = false)
|
||||
private TraceRepository traceRepository = new InMemoryTraceRepository();
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean({ TraceRepository.class })
|
||||
@ConditionalOnMissingBean(TraceRepository.class)
|
||||
protected TraceRepository traceRepository() {
|
||||
return this.traceRepository;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterPostProcessor securityFilterPostProcessor() {
|
||||
SecurityFilterPostProcessor processor = new SecurityFilterPostProcessor(
|
||||
traceRepository());
|
||||
processor.setDumpRequests(this.configuration.isDumpRequests());
|
||||
return processor;
|
||||
@Configuration
|
||||
@ConditionalOnClass(SecurityFilterChain.class)
|
||||
public static class SecurityFilterPostProcessorConfiguration {
|
||||
|
||||
@Autowired
|
||||
private TraceRepository traceRepository;
|
||||
|
||||
@Value("${container.dump_requests:false}")
|
||||
private boolean dumpRequests;
|
||||
|
||||
@Bean
|
||||
public SecurityFilterPostProcessor securityFilterPostProcessor(
|
||||
BeanFactory beanFactory) {
|
||||
SecurityFilterPostProcessor processor = new SecurityFilterPostProcessor(
|
||||
this.traceRepository);
|
||||
processor.setDumpRequests(this.dumpRequests);
|
||||
return processor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.security.web.FilterChainProxy;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -51,7 +52,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SecurityFilterPostProcessor implements BeanPostProcessor {
|
||||
public class SecurityFilterPostProcessor implements BeanPostProcessor, Ordered {
|
||||
|
||||
private final static Log logger = LogFactory
|
||||
.getLog(SecurityFilterPostProcessor.class);
|
||||
@@ -60,6 +61,20 @@ public class SecurityFilterPostProcessor implements BeanPostProcessor {
|
||||
|
||||
private TraceRepository traceRepository = new InMemoryTraceRepository();
|
||||
|
||||
private int order = Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* @param order the order to set
|
||||
*/
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param traceRepository
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user