diff --git a/CHANGES.md b/CHANGES.md index bb54a95aa8a..c65704e7b1d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,5 +12,6 @@ Apollo 2.1.0 * [fix:occur a 400 error request when openapi key's parameter contain "a[0]"](https://github.com/apolloconfig/apollo/pull/4424) * [Upgrade mysql-connector-java version to fix possible transaction rollback failure issue](https://github.com/apolloconfig/apollo/pull/4425) * [Remove database migration tool Flyway](https://github.com/apolloconfig/apollo/pull/4361) +* [Optimize Spring-Security Firewall Deny Request Response 400](https://github.com/apolloconfig/apollo/pull/4428) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/11?closed=1) diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java index 5b77df6eaba..7a6302bf188 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java @@ -27,7 +27,7 @@ import org.springframework.test.annotation.Rollback; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Created by kezhenxu94 at 2019/1/18 15:33. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java index 2f4703bdc76..7ce41dcaf9a 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java @@ -263,7 +263,7 @@ public String[] getArrayProperty(String key, final String delimiter, String[] de if (!m_arrayCache.containsKey(delimiter)) { synchronized (this) { if (!m_arrayCache.containsKey(delimiter)) { - m_arrayCache.put(delimiter, this.newCache()); + m_arrayCache.put(delimiter, this.newCache()); } } } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java index df83a9c3552..92701e2981b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java @@ -88,7 +88,7 @@ private void processPropertyValues(BeanDefinitionRegistry beanRegistry) { } if (!beanName2SpringValueDefinitions.containsKey(beanRegistry)) { - beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.create()); + beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.create()); } Multimap springValueDefinitions = beanName2SpringValueDefinitions.get(beanRegistry); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java index f224c9fda66..2600960ece1 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java @@ -45,7 +45,7 @@ public void register(BeanFactory beanFactory, String key, SpringValue springValu if (!registry.containsKey(beanFactory)) { synchronized (LOCK) { if (!registry.containsKey(beanFactory)) { - registry.put(beanFactory, Multimaps.synchronizedListMultimap(LinkedListMultimap.create())); + registry.put(beanFactory, Multimaps.synchronizedListMultimap(LinkedListMultimap.create())); } } } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java index aeac6326fab..39e666a2424 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java @@ -22,7 +22,7 @@ * @author Jason Song(song_s@ctrip.com) */ public class HttpRequest { - private String m_url; + private final String m_url; private Map headers; private int m_connectTimeout; private int m_readTimeout; diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/integration/ConfigIntegrationTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/integration/ConfigIntegrationTest.java index f09a17f319f..1f1d74b6259 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/integration/ConfigIntegrationTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/integration/ConfigIntegrationTest.java @@ -18,7 +18,7 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import com.ctrip.framework.apollo.util.OrderedProperties; diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigManagerTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigManagerTest.java index 66810167c96..fdc9bb41976 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigManagerTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigManagerTest.java @@ -18,7 +18,7 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import com.ctrip.framework.apollo.enums.ConfigSourceType; diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigTest.java index e619f69db48..93792b41cb1 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigTest.java @@ -902,7 +902,7 @@ public void testGetPropertyWithFunction() throws Exception { public List apply(String s) { return Splitter.on(",").trimResults().omitEmptyStrings().splitToList(s); } - }, Lists.newArrayList()), Lists.newArrayList("a", "b", "c")); + }, Lists.newArrayList()), Lists.newArrayList("a", "b", "c")); assertEquals(defaultConfig.getProperty(someNullKey, new Function>() { @Override public List apply(String s) { diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManagerTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManagerTest.java index b2db782ff2c..e72fcc6d41e 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManagerTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManagerTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.After; import org.junit.Before; diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryTest.java index ca96cc16ee8..fb670fe5b7b 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryTest.java @@ -20,7 +20,7 @@ import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistryTest.java index 43ed933d27a..27d3ce62681 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistryTest.java @@ -18,7 +18,7 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Before; import org.junit.Test; diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java index c3194c6cf74..7bca19520dc 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java @@ -17,12 +17,25 @@ package com.ctrip.framework.apollo.common; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; +import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler; +import org.springframework.security.web.firewall.RequestRejectedHandler; @EnableAutoConfiguration @Configuration @ComponentScan(basePackageClasses = ApolloCommonConfig.class) public class ApolloCommonConfig { + /** + * Spring-Security Firewall Deny Request Response 400 + * @return RequestRejectedHandler + */ + @Bean + public RequestRejectedHandler requestRejectedHandler() { + return new HttpStatusRequestRejectedHandler(HttpStatus.BAD_REQUEST.value()); + } + } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java index 3480b400dcc..8a446ffccb0 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java @@ -32,10 +32,7 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) if (!StringUtils.isEmpty(context.getEnvironment().getProperty("uat.titan.url"))) { return true; } - if (!StringUtils.isEmpty(context.getEnvironment().getProperty("pro.titan.url"))) { - return true; - } - return false; + return !StringUtils.isEmpty(context.getEnvironment().getProperty("pro.titan.url")); } } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java index c98523c356d..fb25a3d3564 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java @@ -39,7 +39,7 @@ public TitanEntityManager(final TitanSettings settings) { public DataSource datasource() throws Exception { Class clazz = Class.forName("com.ctrip.datasource.configure.DalDataSourceFactory"); Object obj = clazz.newInstance(); - Method method = clazz.getMethod("createDataSource", new Class[] {String.class, String.class}); + Method method = clazz.getMethod("createDataSource", String.class, String.class); DataSource ds = ((DataSource) method.invoke(obj, new Object[] {settings.getTitanDbname(), settings.getTitanUrl()})); Tracer.logEvent("Apollo.Datasource.Titan", settings.getTitanDbname()); diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloNotificationMessages.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloNotificationMessages.java index afdf3fe2aa0..0e1967a5155 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloNotificationMessages.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloNotificationMessages.java @@ -28,7 +28,7 @@ public class ApolloNotificationMessages { private Map details; public ApolloNotificationMessages() { - this(Maps.newTreeMap()); + this(Maps.newTreeMap()); } private ApolloNotificationMessages(Map details) { diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java index 977196c69a8..2c1dca0abda 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java @@ -65,7 +65,7 @@ public static Properties readConfigFile(String configPath, Properties defaults) } if (sb.length() > 0) { - logger.debug("Reading properties: \n" + sb.toString()); + logger.debug("Reading properties: \n" + sb); } else { logger.warn("No available properties: {}", configPath); } diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/NetworkInterfaceManager.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/NetworkInterfaceManager.java index ce030cb74ea..cd31bcf3b00 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/NetworkInterfaceManager.java +++ b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/NetworkInterfaceManager.java @@ -119,7 +119,7 @@ private void load() { try { Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); - List nis = interfaces == null ? Collections.emptyList() + List nis = interfaces == null ? Collections.emptyList() : Collections.list(interfaces); //sort the network interfaces according to the index asc Collections.sort(nis, new Comparator() { diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java index 0edf9d5e404..9624a3a816d 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java @@ -42,7 +42,7 @@ public static void main(String[] args) throws IOException { System.exit(0); } - System.out.println(annotatedBean.toString()); + System.out.println(annotatedBean); } } } diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java index 9b7c5cad0e2..a93b055a45d 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java @@ -49,6 +49,6 @@ public SpringBootApolloRefreshConfig( public void onChange(ConfigChangeEvent changeEvent) { logger.info("before refresh {}", sampleRedisConfig.toString()); refreshScope.refresh("sampleRedisConfig"); - logger.info("after refresh {}", sampleRedisConfig.toString()); + logger.info("after refresh {}", sampleRedisConfig); } } diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java index ca7dbdc3925..eb4859b249d 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java @@ -43,7 +43,7 @@ public static void main(String[] args) throws IOException { System.exit(0); } - System.out.println(xmlBean.toString()); + System.out.println(xmlBean); } } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java index ef02a76cddb..b9b56d7306b 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java @@ -54,7 +54,7 @@ public ItemChangeSets resolve(long namespaceId, String configText, List String[] newItems = configText.split(ITEM_SEPARATOR); Set repeatKeys = new HashSet<>(); if (isHasRepeatKey(newItems, repeatKeys)) { - throw new BadRequestException(String.format("Config text has repeated keys: %s, please check your input.", repeatKeys.toString())); + throw new BadRequestException(String.format("Config text has repeated keys: %s, please check your input.", repeatKeys)); } ItemChangeSets changeSets = new ItemChangeSets(); diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/CommitControllerTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/CommitControllerTest.java index ac707409825..53cdb261cad 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/CommitControllerTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/CommitControllerTest.java @@ -17,11 +17,13 @@ package com.ctrip.framework.apollo.portal.controller; import com.ctrip.framework.apollo.portal.AbstractIntegrationTest; -import java.util.List; import org.junit.Test; import org.springframework.web.client.HttpClientErrorException; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; /** @@ -40,7 +42,7 @@ public void shouldFailWhenPageOrSiseIsNegative() { ); fail("should throw"); } catch (final HttpClientErrorException e) { - assertThat( + assertThat( new String(e.getResponseBodyAsByteArray()), containsString("page should be positive or 0") ); } diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/ServerConfigControllerTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/ServerConfigControllerTest.java index 6db3ecbc441..3495d6d7b2b 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/ServerConfigControllerTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/ServerConfigControllerTest.java @@ -25,7 +25,7 @@ import org.springframework.web.client.HttpClientErrorException; import static org.hamcrest.core.StringContains.containsString; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Created by kezhenxu at 2019/1/14 13:24.