Skip to content

Commit

Permalink
Minor Performance Improvement: Avoid Redundant Calls to Environment L…
Browse files Browse the repository at this point in the history
…ayer During Bootstrapping (#1321)

* Reduce redundant Calls to env.getXsuaaConfiguration*()

* Reduce redundant Calls to env.getIasConfiguration()

---------

Co-authored-by: Manuel Fink <[email protected]>
  • Loading branch information
clnative and finkmanAtSap authored Oct 23, 2023
1 parent 1f94a59 commit 12cc7ea
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.sap.cloud.security.config.Environment;
import com.sap.cloud.security.config.Environments;
import com.sap.cloud.security.config.OAuth2ServiceConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.PropertiesPropertySource;
Expand Down Expand Up @@ -76,19 +77,22 @@ public PropertySource<?> createPropertySource(String name, EncodedResource resou
@Nonnull
private Properties getXsuaaProperties(Environment environment, boolean multipleXsuaaServicesBound) {
Properties properties = new Properties();
if (environment.getXsuaaConfiguration() != null) {
final OAuth2ServiceConfiguration xsuaaConfiguration = environment.getXsuaaConfiguration();
if (xsuaaConfiguration != null) {
String xsuaaPrefix = multipleXsuaaServicesBound ? PROPERTIES_KEY + ".xsuaa[0]." : XSUAA_PREFIX;
for (String key : XSUAA_ATTRIBUTES) {
if (environment.getXsuaaConfiguration().hasProperty(key)) {
properties.put(xsuaaPrefix + key, environment.getXsuaaConfiguration().getProperty(key));
if (xsuaaConfiguration.hasProperty(key)) {
properties.put(xsuaaPrefix + key, xsuaaConfiguration.getProperty(key));
}
}
}
if (multipleXsuaaServicesBound) {
final OAuth2ServiceConfiguration xsuaaConfigurationForTokenExchange =
environment.getXsuaaConfigurationForTokenExchange();
for (String key : XSUAA_ATTRIBUTES) {
if (environment.getXsuaaConfigurationForTokenExchange().hasProperty(key)) {
if (xsuaaConfigurationForTokenExchange.hasProperty(key)) {
properties.put(PROPERTIES_KEY + ".xsuaa[1]." + key,
environment.getXsuaaConfigurationForTokenExchange().getProperty(key));
xsuaaConfigurationForTokenExchange.getProperty(key));
}
}
}
Expand All @@ -98,13 +102,14 @@ private Properties getXsuaaProperties(Environment environment, boolean multipleX
@Nonnull
private Properties getIasProperties(Environment environment) {
Properties properties = new Properties();
if (environment.getIasConfiguration() != null) {
final OAuth2ServiceConfiguration iasConfiguration = environment.getIasConfiguration();
if (iasConfiguration != null) {
for (String key : IAS_ATTRIBUTES) {
if (environment.getIasConfiguration().hasProperty(key)) { // will not find "domains" among properties
properties.put(IAS_PREFIX + key, environment.getIasConfiguration().getProperty(key));
if (iasConfiguration.hasProperty(key)) { // will not find "domains" among properties
properties.put(IAS_PREFIX + key, iasConfiguration.getProperty(key));
}
}
properties.put(IAS_PREFIX + DOMAINS, environment.getIasConfiguration().getDomains());
properties.put(IAS_PREFIX + DOMAINS, iasConfiguration.getDomains());
}
return properties;
}
Expand Down

0 comments on commit 12cc7ea

Please sign in to comment.