Repository: SAP/cloud-security-xsuaa-integration
Pull request #177 (2019-10-25 11:52:54)

Disable default property source
The default property source can now be disabled by setting the property `disable-default-property-source` to `true`.

SECAUTH-524


Patch:
diff --git a/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfiguration.java b/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfiguration.java
index 940234f9..d1538d18 100644
--- a/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfiguration.java
+++ b/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfiguration.java
@@ -3,10 +3,12 @@ package com.sap.cloud.security.xsuaa.autoconfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
 import org.springframework.security.oauth2.jwt.Jwt;
@@ -37,7 +39,7 @@ public class XsuaaAutoConfiguration {
 
 	@Configuration
 	@PropertySource(factory = XsuaaServicePropertySourceFactory.class, value = { "" })
-	@ConditionalOnProperty(prefix = "spring.xsuaa", name = "multiple-bindings", havingValue = "false", matchIfMissing = true)
+	@Conditional(PropertyConditions.class)
 	public static class XsuaaServiceAutoConfiguration {
 
 		@Bean
@@ -48,6 +50,20 @@ public class XsuaaAutoConfiguration {
 		}
 	}
 
+	private static class PropertyConditions extends AllNestedConditions {
+
+		public PropertyConditions() {
+			super(ConfigurationPhase.PARSE_CONFIGURATION);
+		}
+
+		@ConditionalOnProperty(prefix = "spring.xsuaa", name = "multiple-bindings", havingValue = "false", matchIfMissing = true)
+		static class MultipleBindingsCondition { }
+
+		@ConditionalOnProperty(prefix = "spring.xsuaa", name = "disable-default-property-source", havingValue = "false", matchIfMissing = true)
+		static class DisableDefaultPropertySourceCondition { }
+
+	}
+
 	/**
 	 * Creates a {@link RestOperations} instance if the application has not yet
 	 * defined any yet.
@@ -61,4 +77,5 @@ public class XsuaaAutoConfiguration {
 		return new RestTemplate();
 	}
 
+
 }
\ No newline at end of file


Test patch:
diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java
index 7a4e9e06..3bb99d6d 100644
--- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java
+++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java
@@ -57,6 +57,7 @@ public class XsuaaAutoConfigurationTest {
 	public void configures_xsuaaServiceConfiguration_withProperties() {
 		contextRunner
 				.withPropertyValues("spring.xsuaa.auto:true")
+				.withPropertyValues("spring.xsuaa.disable-default-property-source:false")
 				.withPropertyValues("spring.xsuaa.multiple-bindings:false").run((context) -> {
 					assertThat(context.containsBean("xsuaaServiceConfiguration"), is(true));
 					assertThat(context.getBean("xsuaaServiceConfiguration"),
@@ -76,12 +77,19 @@ public class XsuaaAutoConfigurationTest {
 	}
 
 	@Test
-	public void serviceConfigurationDisabledByProperty() {
+	public void serviceConfigurationDisabledByMultipleBindingsProperty() {
 		contextRunner.withPropertyValues("spring.xsuaa.multiple-bindings:true").run((context) -> {
 			assertThat(context).doesNotHaveBean("xsuaaServiceConfiguration");
 		});
 	}
 
+	@Test
+	public void serviceConfigurationDisabledByDisableDefaultPropertySourceProperty() {
+		contextRunner.withPropertyValues("spring.xsuaa.disable-default-property-source:true").run((context) -> {
+			assertThat(context).doesNotHaveBean("xsuaaServiceConfiguration");
+		});
+	}
+	
 	@Test
 	public void autoConfigurationInactive_if_noJwtOnClasspath() {
 		contextRunner.withClassLoader(new FilteredClassLoader(Jwt.class)) // removes Jwt.class from classpath