pull/9828/head
Phillip Webb 7 years ago
parent cd23de6ed5
commit 68910f2b8f

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -43,9 +43,11 @@ import org.springframework.context.annotation.Condition;
* }
* </pre>
* <p>
* The {@link ConfigurationPhase} should be specified according to the conditions that
* are defined. In the example above, all conditions are static and can be evaluated
* early so {@code PARSE_CONFIGURATION} is a right fit.
* The
* {@link org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase
* ConfigurationPhase} should be specified according to the conditions that are defined.
* In the example above, all conditions are static and can be evaluated early so
* {@code PARSE_CONFIGURATION} is a right fit.
*
* @author Phillip Webb
* @since 1.3.0

@ -45,9 +45,11 @@ import org.springframework.core.annotation.Order;
* }
* </pre>
* <p>
* The {@link ConfigurationPhase} should be specified according to the conditions that
* are defined. In the example above, all conditions are static and can be evaluated
* early so {@code PARSE_CONFIGURATION} is a right fit.
* The
* {@link org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase
* ConfigurationPhase} should be specified according to the conditions that are defined.
* In the example above, all conditions are static and can be evaluated early so
* {@code PARSE_CONFIGURATION} is a right fit.
*
* @author Phillip Webb
* @since 1.2.0

@ -43,9 +43,11 @@ import org.springframework.context.annotation.Condition;
* }
* </pre>
* <p>
* The {@link ConfigurationPhase} should be specified according to the conditions that
* are defined. In the example above, all conditions are static and can be evaluated
* early so {@code PARSE_CONFIGURATION} is a right fit.
* The
* {@link org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase
* ConfigurationPhase} should be specified according to the conditions that are defined.
* In the example above, all conditions are static and can be evaluated early so
* {@code PARSE_CONFIGURATION} is a right fit.
*
* @author Phillip Webb
* @since 1.3.0

@ -264,8 +264,8 @@ public class ResourceServerTokenServicesConfigurationTests {
EnvironmentTestUtils.addEnvironment(this.environment,
"security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys");
this.context = new SpringApplicationBuilder(JwkTokenStoreConfiguration.class,
ResourceConfiguration.class)
.environment(this.environment).web(false).run();
ResourceConfiguration.class).environment(this.environment).web(false)
.run();
assertThat(this.context.getBeansOfType(JwkTokenStore.class)).hasSize(1);
}
@ -273,8 +273,9 @@ public class ResourceServerTokenServicesConfigurationTests {
public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
EnvironmentTestUtils.addEnvironment(this.environment,
"security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY);
this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class, ResourceConfiguration.class)
.environment(this.environment).web(false).run();
this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class,
ResourceConfiguration.class).environment(this.environment).web(false)
.run();
assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1);
}

@ -28,11 +28,6 @@ import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class ExitCodeApplication {
public static void main(String[] args) {
System.exit(SpringApplication.exit(
SpringApplication.run(ExitCodeApplication.class, args)));
}
@Bean
public ExitCodeGenerator exitCodeGenerator() {
return new ExitCodeGenerator() {
@ -43,5 +38,10 @@ public class ExitCodeApplication {
};
}
public static void main(String[] args) {
System.exit(SpringApplication
.exit(SpringApplication.run(ExitCodeApplication.class, args)));
}
}
// end::example[]

@ -51,37 +51,37 @@ public class CorsSampleActuatorApplicationTests {
@Test
public void sensitiveEndpointShouldReturnUnauthorized() throws Exception {
ResponseEntity<Map> entity = this.testRestTemplate.getForEntity("/env", Map.class);
ResponseEntity<?> entity = this.testRestTemplate.getForEntity("/env", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
public void preflightRequestForInsensitiveShouldReturnOk() throws Exception {
RequestEntity<?> healthRequest = RequestEntity.options(new URI("/health"))
.header("Origin","http://localhost:8080")
.header("Access-Control-Request-Method", "GET")
.build();
ResponseEntity<Map> exchange = this.testRestTemplate.exchange(healthRequest, Map.class);
.header("Origin", "http://localhost:8080")
.header("Access-Control-Request-Method", "GET").build();
ResponseEntity<?> exchange = this.testRestTemplate.exchange(healthRequest,
Map.class);
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
public void preflightRequestForSensitiveEndpointShouldReturnOk() throws Exception {
RequestEntity<?> entity = RequestEntity.options(new URI("/env"))
.header("Origin","http://localhost:8080")
.header("Access-Control-Request-Method", "GET")
.build();
ResponseEntity<Map> env = this.testRestTemplate.exchange(entity, Map.class);
.header("Origin", "http://localhost:8080")
.header("Access-Control-Request-Method", "GET").build();
ResponseEntity<?> env = this.testRestTemplate.exchange(entity, Map.class);
assertThat(env.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception {
public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden()
throws Exception {
RequestEntity<?> entity = RequestEntity.options(new URI("/health"))
.header("Origin","http://localhost:9095")
.header("Access-Control-Request-Method", "GET")
.build();
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity, byte[].class);
.header("Origin", "http://localhost:9095")
.header("Access-Control-Request-Method", "GET").build();
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity,
byte[].class);
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}

Loading…
Cancel
Save