Skip to content

Commit 12cc7ea

Browse files
Minor Performance Improvement: Avoid Redundant Calls to Environment Layer During Bootstrapping (#1321)
* Reduce redundant Calls to env.getXsuaaConfiguration*() * Reduce redundant Calls to env.getIasConfiguration() --------- Co-authored-by: Manuel Fink <123368068+finkmanAtSap@users.noreply.github.com>
1 parent 1f94a59 commit 12cc7ea

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

spring-security/src/main/java/com/sap/cloud/security/spring/config/IdentityServicesPropertySourceFactory.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.sap.cloud.security.config.Environment;
99
import com.sap.cloud.security.config.Environments;
10+
import com.sap.cloud.security.config.OAuth2ServiceConfiguration;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
1213
import org.springframework.core.env.PropertiesPropertySource;
@@ -76,19 +77,22 @@ public PropertySource<?> createPropertySource(String name, EncodedResource resou
7677
@Nonnull
7778
private Properties getXsuaaProperties(Environment environment, boolean multipleXsuaaServicesBound) {
7879
Properties properties = new Properties();
79-
if (environment.getXsuaaConfiguration() != null) {
80+
final OAuth2ServiceConfiguration xsuaaConfiguration = environment.getXsuaaConfiguration();
81+
if (xsuaaConfiguration != null) {
8082
String xsuaaPrefix = multipleXsuaaServicesBound ? PROPERTIES_KEY + ".xsuaa[0]." : XSUAA_PREFIX;
8183
for (String key : XSUAA_ATTRIBUTES) {
82-
if (environment.getXsuaaConfiguration().hasProperty(key)) {
83-
properties.put(xsuaaPrefix + key, environment.getXsuaaConfiguration().getProperty(key));
84+
if (xsuaaConfiguration.hasProperty(key)) {
85+
properties.put(xsuaaPrefix + key, xsuaaConfiguration.getProperty(key));
8486
}
8587
}
8688
}
8789
if (multipleXsuaaServicesBound) {
90+
final OAuth2ServiceConfiguration xsuaaConfigurationForTokenExchange =
91+
environment.getXsuaaConfigurationForTokenExchange();
8892
for (String key : XSUAA_ATTRIBUTES) {
89-
if (environment.getXsuaaConfigurationForTokenExchange().hasProperty(key)) {
93+
if (xsuaaConfigurationForTokenExchange.hasProperty(key)) {
9094
properties.put(PROPERTIES_KEY + ".xsuaa[1]." + key,
91-
environment.getXsuaaConfigurationForTokenExchange().getProperty(key));
95+
xsuaaConfigurationForTokenExchange.getProperty(key));
9296
}
9397
}
9498
}
@@ -98,13 +102,14 @@ private Properties getXsuaaProperties(Environment environment, boolean multipleX
98102
@Nonnull
99103
private Properties getIasProperties(Environment environment) {
100104
Properties properties = new Properties();
101-
if (environment.getIasConfiguration() != null) {
105+
final OAuth2ServiceConfiguration iasConfiguration = environment.getIasConfiguration();
106+
if (iasConfiguration != null) {
102107
for (String key : IAS_ATTRIBUTES) {
103-
if (environment.getIasConfiguration().hasProperty(key)) { // will not find "domains" among properties
104-
properties.put(IAS_PREFIX + key, environment.getIasConfiguration().getProperty(key));
108+
if (iasConfiguration.hasProperty(key)) { // will not find "domains" among properties
109+
properties.put(IAS_PREFIX + key, iasConfiguration.getProperty(key));
105110
}
106111
}
107-
properties.put(IAS_PREFIX + DOMAINS, environment.getIasConfiguration().getDomains());
112+
properties.put(IAS_PREFIX + DOMAINS, iasConfiguration.getDomains());
108113
}
109114
return properties;
110115
}

0 commit comments

Comments
 (0)