use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class CloudPlatformTests method getActiveWhenHasVcapServicesShouldReturnCloudFoundry.
@Test
void getActiveWhenHasVcapServicesShouldReturnCloudFoundry() {
Environment environment = new MockEnvironment().withProperty("VCAP_SERVICES", "---");
CloudPlatform platform = CloudPlatform.getActive(environment);
assertThat(platform).isEqualTo(CloudPlatform.CLOUD_FOUNDRY);
assertThat(platform.isActive(environment)).isTrue();
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class CloudPlatformTests method getActiveWhenHasAllAzureEnvVariablesShouldReturnAzureAppService.
@Test
void getActiveWhenHasAllAzureEnvVariablesShouldReturnAzureAppService() {
Map<String, Object> envVars = new HashMap<>();
envVars.put("WEBSITE_SITE_NAME", "---");
envVars.put("WEBSITE_INSTANCE_ID", "1234");
envVars.put("WEBSITE_RESOURCE_GROUP", "test");
envVars.put("WEBSITE_SKU", "1234");
Environment environment = getEnvironmentWithEnvVariables(envVars);
CloudPlatform platform = CloudPlatform.getActive(environment);
assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE);
assertThat(platform.isActive(environment)).isTrue();
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class AbstractSessionCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("Session Condition");
Environment environment = context.getEnvironment();
StoreType required = SessionStoreMappings.getType(this.webApplicationType, ((AnnotationMetadata) metadata).getClassName());
if (!environment.containsProperty("spring.session.store-type")) {
return ConditionOutcome.match(message.didNotFind("property", "properties").items(ConditionMessage.Style.QUOTE, "spring.session.store-type"));
}
try {
Binder binder = Binder.get(environment);
return binder.bind("spring.session.store-type", StoreType.class).map((t) -> new ConditionOutcome(t == required, message.found("spring.session.store-type property").items(t))).orElseGet(() -> ConditionOutcome.noMatch(message.didNotFind("spring.session.store-type property").atAll()));
} catch (BindException ex) {
return ConditionOutcome.noMatch(message.found("invalid spring.session.store-type property").atAll());
}
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class KeyValueCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("Public Key Value Condition");
Environment environment = context.getEnvironment();
String publicKeyLocation = environment.getProperty("spring.security.oauth2.resourceserver.jwt.public-key-location");
if (!StringUtils.hasText(publicKeyLocation)) {
return ConditionOutcome.noMatch(message.didNotFind("public-key-location property").atAll());
}
String issuerUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.issuer-uri");
String jwkSetUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
if (StringUtils.hasText(jwkSetUri)) {
return ConditionOutcome.noMatch(message.found("jwk-set-uri property").items(jwkSetUri));
}
if (StringUtils.hasText(issuerUri)) {
return ConditionOutcome.noMatch(message.found("issuer-uri property").items(issuerUri));
}
return ConditionOutcome.match(message.foundExactly("public key location property"));
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class IssuerUriCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("OpenID Connect Issuer URI Condition");
Environment environment = context.getEnvironment();
String issuerUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.issuer-uri");
String jwkSetUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
if (!StringUtils.hasText(issuerUri)) {
return ConditionOutcome.noMatch(message.didNotFind("issuer-uri property").atAll());
}
if (StringUtils.hasText(jwkSetUri)) {
return ConditionOutcome.noMatch(message.found("jwk-set-uri property").items(jwkSetUri));
}
return ConditionOutcome.match(message.foundExactly("issuer-uri property"));
}
Aggregations