Align reactive auto-configuration names
Rename a few reactive auto-configuration and related classes for better consistency.
This commit is contained in:
@@ -79,7 +79,7 @@ import org.springframework.web.server.WebFilter;
|
||||
@ConditionalOnBooleanProperty(name = "management.cloudfoundry.enabled", matchIfMissing = true)
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.CLOUD_FOUNDRY)
|
||||
public class ReactiveCloudFoundryActuatorAutoConfiguration {
|
||||
public class CloudFoundryReactiveActuatorAutoConfiguration {
|
||||
|
||||
private static final String BASE_PATH = "/cloudfoundryapplication";
|
||||
|
||||
@@ -115,7 +115,7 @@ public class ReactiveCloudFoundryActuatorAutoConfiguration {
|
||||
CloudFoundryWebEndpointDiscoverer endpointDiscoverer = new CloudFoundryWebEndpointDiscoverer(applicationContext,
|
||||
parameterMapper, endpointMediaTypes, null, Collections.emptyList(), Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
CloudFoundrySecurityInterceptor securityInterceptor = getSecurityInterceptor(webClientBuilder,
|
||||
SecurityInterceptor securityInterceptor = getSecurityInterceptor(webClientBuilder,
|
||||
applicationContext.getEnvironment());
|
||||
Collection<ExposableWebEndpoint> webEndpoints = endpointDiscoverer.getEndpoints();
|
||||
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
|
||||
@@ -125,23 +125,20 @@ public class ReactiveCloudFoundryActuatorAutoConfiguration {
|
||||
endpointMediaTypes, getCorsConfiguration(), securityInterceptor, allEndpoints);
|
||||
}
|
||||
|
||||
private CloudFoundrySecurityInterceptor getSecurityInterceptor(WebClient.Builder webClientBuilder,
|
||||
Environment environment) {
|
||||
ReactiveCloudFoundrySecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService(
|
||||
webClientBuilder, environment);
|
||||
ReactiveTokenValidator tokenValidator = new ReactiveTokenValidator(cloudfoundrySecurityService);
|
||||
return new CloudFoundrySecurityInterceptor(tokenValidator, cloudfoundrySecurityService,
|
||||
private SecurityInterceptor getSecurityInterceptor(WebClient.Builder webClientBuilder, Environment environment) {
|
||||
SecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService(webClientBuilder, environment);
|
||||
TokenValidator tokenValidator = new TokenValidator(cloudfoundrySecurityService);
|
||||
return new SecurityInterceptor(tokenValidator, cloudfoundrySecurityService,
|
||||
environment.getProperty("vcap.application.application_id"));
|
||||
}
|
||||
|
||||
private ReactiveCloudFoundrySecurityService getCloudFoundrySecurityService(WebClient.Builder webClientBuilder,
|
||||
private SecurityService getCloudFoundrySecurityService(WebClient.Builder webClientBuilder,
|
||||
Environment environment) {
|
||||
String cloudControllerUrl = environment.getProperty("vcap.application.cf_api");
|
||||
boolean skipSslValidation = environment.getProperty("management.cloudfoundry.skip-ssl-validation",
|
||||
Boolean.class, false);
|
||||
return (cloudControllerUrl != null)
|
||||
? new ReactiveCloudFoundrySecurityService(webClientBuilder, cloudControllerUrl, skipSslValidation)
|
||||
: null;
|
||||
? new SecurityService(webClientBuilder, cloudControllerUrl, skipSslValidation) : null;
|
||||
}
|
||||
|
||||
private CorsConfiguration getCorsConfiguration() {
|
||||
@@ -61,7 +61,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
@ImportRuntimeHints(CloudFoundryWebFluxEndpointHandlerMappingRuntimeHints.class)
|
||||
class CloudFoundryWebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointHandlerMapping {
|
||||
|
||||
private final CloudFoundrySecurityInterceptor securityInterceptor;
|
||||
private final SecurityInterceptor securityInterceptor;
|
||||
|
||||
private final EndpointLinksResolver linksResolver;
|
||||
|
||||
@@ -69,7 +69,7 @@ class CloudFoundryWebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointH
|
||||
|
||||
CloudFoundryWebFluxEndpointHandlerMapping(EndpointMapping endpointMapping,
|
||||
Collection<ExposableWebEndpoint> endpoints, EndpointMediaTypes endpointMediaTypes,
|
||||
CorsConfiguration corsConfiguration, CloudFoundrySecurityInterceptor securityInterceptor,
|
||||
CorsConfiguration corsConfiguration, SecurityInterceptor securityInterceptor,
|
||||
Collection<ExposableEndpoint<?>> allEndpoints) {
|
||||
super(endpointMapping, endpoints, endpointMediaTypes, corsConfiguration, true);
|
||||
this.linksResolver = new EndpointLinksResolver(allEndpoints);
|
||||
@@ -135,11 +135,11 @@ class CloudFoundryWebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointH
|
||||
|
||||
private final ReactiveWebOperation delegate;
|
||||
|
||||
private final CloudFoundrySecurityInterceptor securityInterceptor;
|
||||
private final SecurityInterceptor securityInterceptor;
|
||||
|
||||
private final EndpointId endpointId;
|
||||
|
||||
SecureReactiveWebOperation(ReactiveWebOperation delegate, CloudFoundrySecurityInterceptor securityInterceptor,
|
||||
SecureReactiveWebOperation(ReactiveWebOperation delegate, SecurityInterceptor securityInterceptor,
|
||||
EndpointId endpointId) {
|
||||
this.delegate = delegate;
|
||||
this.securityInterceptor = securityInterceptor;
|
||||
|
||||
@@ -37,20 +37,20 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class CloudFoundrySecurityInterceptor {
|
||||
class SecurityInterceptor {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(CloudFoundrySecurityInterceptor.class);
|
||||
private static final Log logger = LogFactory.getLog(SecurityInterceptor.class);
|
||||
|
||||
private final ReactiveTokenValidator tokenValidator;
|
||||
private final TokenValidator tokenValidator;
|
||||
|
||||
private final ReactiveCloudFoundrySecurityService cloudFoundrySecurityService;
|
||||
private final SecurityService cloudFoundrySecurityService;
|
||||
|
||||
private final String applicationId;
|
||||
|
||||
private static final Mono<SecurityResponse> SUCCESS = Mono.just(SecurityResponse.success());
|
||||
|
||||
CloudFoundrySecurityInterceptor(ReactiveTokenValidator tokenValidator,
|
||||
ReactiveCloudFoundrySecurityService cloudFoundrySecurityService, String applicationId) {
|
||||
SecurityInterceptor(TokenValidator tokenValidator, SecurityService cloudFoundrySecurityService,
|
||||
String applicationId) {
|
||||
this.tokenValidator = tokenValidator;
|
||||
this.cloudFoundrySecurityService = cloudFoundrySecurityService;
|
||||
this.applicationId = applicationId;
|
||||
@@ -45,7 +45,7 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class ReactiveCloudFoundrySecurityService {
|
||||
class SecurityService {
|
||||
|
||||
private static final ParameterizedTypeReference<Map<String, Object>> STRING_OBJECT_MAP = new ParameterizedTypeReference<>() {
|
||||
};
|
||||
@@ -54,8 +54,7 @@ class ReactiveCloudFoundrySecurityService {
|
||||
|
||||
private final String cloudControllerUrl;
|
||||
|
||||
ReactiveCloudFoundrySecurityService(WebClient.Builder webClientBuilder, String cloudControllerUrl,
|
||||
boolean skipSslValidation) {
|
||||
SecurityService(WebClient.Builder webClientBuilder, String cloudControllerUrl, boolean skipSslValidation) {
|
||||
Assert.notNull(webClientBuilder, "'webClientBuilder' must not be null");
|
||||
Assert.notNull(cloudControllerUrl, "'cloudControllerUrl' must not be null");
|
||||
if (skipSslValidation) {
|
||||
@@ -39,13 +39,13 @@ import org.springframework.boot.cloudfoundry.actuate.autoconfigure.endpoint.Toke
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class ReactiveTokenValidator {
|
||||
class TokenValidator {
|
||||
|
||||
private final ReactiveCloudFoundrySecurityService securityService;
|
||||
private final SecurityService securityService;
|
||||
|
||||
private volatile Map<String, String> cachedTokenKeys = Collections.emptyMap();
|
||||
|
||||
ReactiveTokenValidator(ReactiveCloudFoundrySecurityService securityService) {
|
||||
TokenValidator(SecurityService securityService) {
|
||||
this.securityService = securityService;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class CloudFoundryActuatorAutoConfiguration {
|
||||
CloudFoundryWebEndpointDiscoverer discoverer = new CloudFoundryWebEndpointDiscoverer(applicationContext,
|
||||
parameterMapper, endpointMediaTypes, null, Collections.emptyList(), Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
CloudFoundrySecurityInterceptor securityInterceptor = getSecurityInterceptor(restTemplateBuilder,
|
||||
SecurityInterceptor securityInterceptor = getSecurityInterceptor(restTemplateBuilder,
|
||||
applicationContext.getEnvironment());
|
||||
Collection<ExposableWebEndpoint> webEndpoints = discoverer.getEndpoints();
|
||||
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
|
||||
@@ -130,22 +130,21 @@ public class CloudFoundryActuatorAutoConfiguration {
|
||||
endpointMediaTypes, getCorsConfiguration(), securityInterceptor, allEndpoints);
|
||||
}
|
||||
|
||||
private CloudFoundrySecurityInterceptor getSecurityInterceptor(RestTemplateBuilder restTemplateBuilder,
|
||||
private SecurityInterceptor getSecurityInterceptor(RestTemplateBuilder restTemplateBuilder,
|
||||
Environment environment) {
|
||||
CloudFoundrySecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService(restTemplateBuilder,
|
||||
environment);
|
||||
SecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService(restTemplateBuilder, environment);
|
||||
TokenValidator tokenValidator = new TokenValidator(cloudfoundrySecurityService);
|
||||
return new CloudFoundrySecurityInterceptor(tokenValidator, cloudfoundrySecurityService,
|
||||
return new SecurityInterceptor(tokenValidator, cloudfoundrySecurityService,
|
||||
environment.getProperty("vcap.application.application_id"));
|
||||
}
|
||||
|
||||
private CloudFoundrySecurityService getCloudFoundrySecurityService(RestTemplateBuilder restTemplateBuilder,
|
||||
private SecurityService getCloudFoundrySecurityService(RestTemplateBuilder restTemplateBuilder,
|
||||
Environment environment) {
|
||||
String cloudControllerUrl = environment.getProperty("vcap.application.cf_api");
|
||||
boolean skipSslValidation = environment.getProperty("management.cloudfoundry.skip-ssl-validation",
|
||||
Boolean.class, false);
|
||||
return (cloudControllerUrl != null)
|
||||
? new CloudFoundrySecurityService(restTemplateBuilder, cloudControllerUrl, skipSslValidation) : null;
|
||||
? new SecurityService(restTemplateBuilder, cloudControllerUrl, skipSslValidation) : null;
|
||||
}
|
||||
|
||||
private CorsConfiguration getCorsConfiguration() {
|
||||
|
||||
@@ -64,7 +64,7 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebMvcEndpoin
|
||||
|
||||
private static final Log logger = LogFactory.getLog(CloudFoundryWebEndpointServletHandlerMapping.class);
|
||||
|
||||
private final CloudFoundrySecurityInterceptor securityInterceptor;
|
||||
private final SecurityInterceptor securityInterceptor;
|
||||
|
||||
private final EndpointLinksResolver linksResolver;
|
||||
|
||||
@@ -72,7 +72,7 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebMvcEndpoin
|
||||
|
||||
CloudFoundryWebEndpointServletHandlerMapping(EndpointMapping endpointMapping,
|
||||
Collection<ExposableWebEndpoint> endpoints, EndpointMediaTypes endpointMediaTypes,
|
||||
CorsConfiguration corsConfiguration, CloudFoundrySecurityInterceptor securityInterceptor,
|
||||
CorsConfiguration corsConfiguration, SecurityInterceptor securityInterceptor,
|
||||
Collection<ExposableEndpoint<?>> allEndpoints) {
|
||||
super(endpointMapping, endpoints, endpointMediaTypes, corsConfiguration, true);
|
||||
this.securityInterceptor = securityInterceptor;
|
||||
@@ -143,11 +143,11 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebMvcEndpoin
|
||||
|
||||
private final ServletWebOperation delegate;
|
||||
|
||||
private final CloudFoundrySecurityInterceptor securityInterceptor;
|
||||
private final SecurityInterceptor securityInterceptor;
|
||||
|
||||
private final EndpointId endpointId;
|
||||
|
||||
SecureServletWebOperation(ServletWebOperation delegate, CloudFoundrySecurityInterceptor securityInterceptor,
|
||||
SecureServletWebOperation(ServletWebOperation delegate, SecurityInterceptor securityInterceptor,
|
||||
EndpointId endpointId) {
|
||||
this.delegate = delegate;
|
||||
this.securityInterceptor = securityInterceptor;
|
||||
|
||||
@@ -38,20 +38,20 @@ import org.springframework.web.cors.CorsUtils;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class CloudFoundrySecurityInterceptor {
|
||||
class SecurityInterceptor {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(CloudFoundrySecurityInterceptor.class);
|
||||
private static final Log logger = LogFactory.getLog(SecurityInterceptor.class);
|
||||
|
||||
private final TokenValidator tokenValidator;
|
||||
|
||||
private final CloudFoundrySecurityService cloudFoundrySecurityService;
|
||||
private final SecurityService cloudFoundrySecurityService;
|
||||
|
||||
private final String applicationId;
|
||||
|
||||
private static final SecurityResponse SUCCESS = SecurityResponse.success();
|
||||
|
||||
CloudFoundrySecurityInterceptor(TokenValidator tokenValidator,
|
||||
CloudFoundrySecurityService cloudFoundrySecurityService, String applicationId) {
|
||||
SecurityInterceptor(TokenValidator tokenValidator, SecurityService cloudFoundrySecurityService,
|
||||
String applicationId) {
|
||||
this.tokenValidator = tokenValidator;
|
||||
this.cloudFoundrySecurityService = cloudFoundrySecurityService;
|
||||
this.applicationId = applicationId;
|
||||
@@ -39,7 +39,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class CloudFoundrySecurityService {
|
||||
class SecurityService {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
@@ -47,8 +47,7 @@ class CloudFoundrySecurityService {
|
||||
|
||||
private String uaaUrl;
|
||||
|
||||
CloudFoundrySecurityService(RestTemplateBuilder restTemplateBuilder, String cloudControllerUrl,
|
||||
boolean skipSslValidation) {
|
||||
SecurityService(RestTemplateBuilder restTemplateBuilder, String cloudControllerUrl, boolean skipSslValidation) {
|
||||
Assert.notNull(restTemplateBuilder, "'restTemplateBuilder' must not be null");
|
||||
Assert.notNull(cloudControllerUrl, "'cloudControllerUrl' must not be null");
|
||||
if (skipSslValidation) {
|
||||
@@ -38,11 +38,11 @@ import org.springframework.boot.cloudfoundry.actuate.autoconfigure.endpoint.Toke
|
||||
*/
|
||||
class TokenValidator {
|
||||
|
||||
private final CloudFoundrySecurityService securityService;
|
||||
private final SecurityService securityService;
|
||||
|
||||
private Map<String, String> tokenKeys;
|
||||
|
||||
TokenValidator(CloudFoundrySecurityService cloudFoundrySecurityService) {
|
||||
TokenValidator(SecurityService cloudFoundrySecurityService) {
|
||||
this.securityService = cloudFoundrySecurityService;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
org.springframework.boot.cloudfoundry.actuate.autoconfigure.endpoint.reactive.ReactiveCloudFoundryActuatorAutoConfiguration
|
||||
org.springframework.boot.cloudfoundry.actuate.autoconfigure.endpoint.reactive.CloudFoundryReactiveActuatorAutoConfiguration
|
||||
org.springframework.boot.cloudfoundry.actuate.autoconfigure.endpoint.servlet.CloudFoundryActuatorAutoConfiguration
|
||||
|
||||
@@ -83,12 +83,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReactiveCloudFoundryActuatorAutoConfiguration}.
|
||||
* Tests for {@link CloudFoundryReactiveActuatorAutoConfiguration}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ReactiveCloudFoundryActuatorAutoConfigurationTests {
|
||||
class CloudFoundryReactiveActuatorAutoConfigurationTests {
|
||||
|
||||
private static final String V2_JSON = ApiVersion.V2.getProducedMimeType().toString();
|
||||
|
||||
@@ -103,7 +103,7 @@ class ReactiveCloudFoundryActuatorAutoConfigurationTests {
|
||||
EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class,
|
||||
HealthContributorAutoConfiguration.class, HealthEndpointAutoConfiguration.class,
|
||||
InfoContributorAutoConfiguration.class, InfoEndpointAutoConfiguration.class,
|
||||
ProjectInfoAutoConfiguration.class, ReactiveCloudFoundryActuatorAutoConfiguration.class))
|
||||
ProjectInfoAutoConfiguration.class, CloudFoundryReactiveActuatorAutoConfiguration.class))
|
||||
.withUserConfiguration(UserDetailsServiceConfiguration.class);
|
||||
|
||||
private static final String BASE_PATH = "/cloudfoundryapplication";
|
||||
@@ -57,11 +57,11 @@ class CloudFoundryReactiveHealthEndpointWebExtensionTests {
|
||||
.withConfiguration(AutoConfigurations.of(ReactiveSecurityAutoConfiguration.class,
|
||||
WebFluxAutoConfiguration.class, JacksonAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
ReactiveCloudFoundryActuatorAutoConfigurationTests.WebClientCustomizerConfig.class,
|
||||
CloudFoundryReactiveActuatorAutoConfigurationTests.WebClientCustomizerConfig.class,
|
||||
WebClientAutoConfiguration.class, ManagementContextAutoConfiguration.class,
|
||||
EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class,
|
||||
HealthContributorAutoConfiguration.class, HealthEndpointAutoConfiguration.class,
|
||||
ReactiveCloudFoundryActuatorAutoConfiguration.class))
|
||||
CloudFoundryReactiveActuatorAutoConfiguration.class))
|
||||
.withUserConfiguration(TestHealthIndicator.class, UserDetailsServiceConfiguration.class);
|
||||
|
||||
@Test
|
||||
|
||||
@@ -75,17 +75,17 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
class CloudFoundryWebFluxEndpointIntegrationTests {
|
||||
|
||||
private final ReactiveTokenValidator tokenValidator = mock(ReactiveTokenValidator.class);
|
||||
private final TokenValidator tokenValidator = mock(TokenValidator.class);
|
||||
|
||||
private final ReactiveCloudFoundrySecurityService securityService = mock(ReactiveCloudFoundrySecurityService.class);
|
||||
private final SecurityService securityService = mock(SecurityService.class);
|
||||
|
||||
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner(
|
||||
AnnotationConfigReactiveWebServerApplicationContext::new)
|
||||
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class, HttpHandlerAutoConfiguration.class,
|
||||
NettyReactiveWebServerAutoConfiguration.class))
|
||||
.withUserConfiguration(TestEndpointConfiguration.class)
|
||||
.withBean(ReactiveTokenValidator.class, () -> this.tokenValidator)
|
||||
.withBean(ReactiveCloudFoundrySecurityService.class, () -> this.securityService)
|
||||
.withBean(TokenValidator.class, () -> this.tokenValidator)
|
||||
.withBean(SecurityService.class, () -> this.securityService)
|
||||
.withPropertyValues("server.port=0");
|
||||
|
||||
@Test
|
||||
@@ -233,9 +233,8 @@ class CloudFoundryWebFluxEndpointIntegrationTests {
|
||||
static class CloudFoundryReactiveConfiguration {
|
||||
|
||||
@Bean
|
||||
CloudFoundrySecurityInterceptor interceptor(ReactiveTokenValidator tokenValidator,
|
||||
ReactiveCloudFoundrySecurityService securityService) {
|
||||
return new CloudFoundrySecurityInterceptor(tokenValidator, securityService, "app-id");
|
||||
SecurityInterceptor interceptor(TokenValidator tokenValidator, SecurityService securityService) {
|
||||
return new SecurityInterceptor(tokenValidator, securityService, "app-id");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -247,7 +246,7 @@ class CloudFoundryWebFluxEndpointIntegrationTests {
|
||||
@Bean
|
||||
CloudFoundryWebFluxEndpointHandlerMapping cloudFoundryWebEndpointServletHandlerMapping(
|
||||
WebEndpointDiscoverer webEndpointDiscoverer, EndpointMediaTypes endpointMediaTypes,
|
||||
CloudFoundrySecurityInterceptor interceptor) {
|
||||
SecurityInterceptor interceptor) {
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.setAllowedOrigins(Arrays.asList("https://example.com"));
|
||||
corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST"));
|
||||
|
||||
@@ -40,24 +40,24 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Tests for {@link CloudFoundrySecurityInterceptor}.
|
||||
* Tests for {@link SecurityInterceptor}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ReactiveCloudFoundrySecurityInterceptorTests {
|
||||
class SecurityInterceptorTests {
|
||||
|
||||
@Mock
|
||||
private ReactiveTokenValidator tokenValidator;
|
||||
private TokenValidator tokenValidator;
|
||||
|
||||
@Mock
|
||||
private ReactiveCloudFoundrySecurityService securityService;
|
||||
private SecurityService securityService;
|
||||
|
||||
private CloudFoundrySecurityInterceptor interceptor;
|
||||
private SecurityInterceptor interceptor;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, "my-app-id");
|
||||
this.interceptor = new SecurityInterceptor(this.tokenValidator, this.securityService, "my-app-id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +95,7 @@ class ReactiveCloudFoundrySecurityInterceptorTests {
|
||||
|
||||
@Test
|
||||
void preHandleWhenApplicationIdIsNullShouldReturnError() {
|
||||
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, null);
|
||||
this.interceptor = new SecurityInterceptor(this.tokenValidator, this.securityService, null);
|
||||
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.get("/a")
|
||||
.header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken())
|
||||
.build());
|
||||
@@ -107,7 +107,7 @@ class ReactiveCloudFoundrySecurityInterceptorTests {
|
||||
|
||||
@Test
|
||||
void preHandleWhenCloudFoundrySecurityServiceIsNullShouldReturnError() {
|
||||
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, null, "my-app-id");
|
||||
this.interceptor = new SecurityInterceptor(this.tokenValidator, null, "my-app-id");
|
||||
MockServerWebExchange request = MockServerWebExchange
|
||||
.from(MockServerHttpRequest.get("/a").header(HttpHeaders.AUTHORIZATION, mockAccessToken()).build());
|
||||
StepVerifier.create(this.interceptor.preHandle(request, "/a"))
|
||||
@@ -35,11 +35,11 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReactiveCloudFoundrySecurityService}.
|
||||
* Tests for {@link SecurityService}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class ReactiveCloudFoundrySecurityServiceTests {
|
||||
class SecurityServiceTests {
|
||||
|
||||
private static final String CLOUD_CONTROLLER = "/my-cloud-controller.com";
|
||||
|
||||
@@ -47,7 +47,7 @@ class ReactiveCloudFoundrySecurityServiceTests {
|
||||
|
||||
private static final String UAA_URL = "https://my-cloud-controller.com/uaa";
|
||||
|
||||
private ReactiveCloudFoundrySecurityService securityService;
|
||||
private SecurityService securityService;
|
||||
|
||||
private MockWebServer server;
|
||||
|
||||
@@ -55,7 +55,7 @@ class ReactiveCloudFoundrySecurityServiceTests {
|
||||
void setup() {
|
||||
this.server = new MockWebServer();
|
||||
WebClient.Builder builder = WebClient.builder().baseUrl(this.server.url("/").toString());
|
||||
this.securityService = new ReactiveCloudFoundrySecurityService(builder, CLOUD_CONTROLLER, false);
|
||||
this.securityService = new SecurityService(builder, CLOUD_CONTROLLER, false);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -50,19 +50,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReactiveTokenValidator}.
|
||||
* Tests for {@link TokenValidator}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ReactiveTokenValidatorTests {
|
||||
class TokenValidatorTests {
|
||||
|
||||
private static final byte[] DOT = ".".getBytes();
|
||||
|
||||
@Mock
|
||||
private ReactiveCloudFoundrySecurityService securityService;
|
||||
private SecurityService securityService;
|
||||
|
||||
private ReactiveTokenValidator tokenValidator;
|
||||
private TokenValidator tokenValidator;
|
||||
|
||||
private static final String VALID_KEY = """
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
@@ -94,7 +94,7 @@ class ReactiveTokenValidatorTests {
|
||||
void setup() {
|
||||
VALID_KEYS.put("valid-key", VALID_KEY);
|
||||
INVALID_KEYS.put("invalid-key", INVALID_KEY);
|
||||
this.tokenValidator = new ReactiveTokenValidator(this.securityService);
|
||||
this.tokenValidator = new TokenValidator(this.securityService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ class CloudFoundryMvcWebEndpointIntegrationTests {
|
||||
|
||||
private final TokenValidator tokenValidator = mock(TokenValidator.class);
|
||||
|
||||
private final CloudFoundrySecurityService securityService = mock(CloudFoundrySecurityService.class);
|
||||
private final SecurityService securityService = mock(SecurityService.class);
|
||||
|
||||
@Test
|
||||
void operationWithSecurityInterceptorForbidden() {
|
||||
@@ -204,7 +204,7 @@ class CloudFoundryMvcWebEndpointIntegrationTests {
|
||||
new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new)
|
||||
.withUserConfiguration(configuration, CloudFoundryMvcConfiguration.class)
|
||||
.withBean(TokenValidator.class, () -> this.tokenValidator)
|
||||
.withBean(CloudFoundrySecurityService.class, () -> this.securityService)
|
||||
.withBean(SecurityService.class, () -> this.securityService)
|
||||
.run((context) -> consumer.accept(context, WebTestClient.bindToServer()
|
||||
.baseUrl("http://localhost:" + getPort(
|
||||
(AnnotationConfigServletWebServerApplicationContext) context.getSourceApplicationContext()))
|
||||
@@ -227,9 +227,8 @@ class CloudFoundryMvcWebEndpointIntegrationTests {
|
||||
static class CloudFoundryMvcConfiguration {
|
||||
|
||||
@Bean
|
||||
CloudFoundrySecurityInterceptor interceptor(TokenValidator tokenValidator,
|
||||
CloudFoundrySecurityService securityService) {
|
||||
return new CloudFoundrySecurityInterceptor(tokenValidator, securityService, "app-id");
|
||||
SecurityInterceptor interceptor(TokenValidator tokenValidator, SecurityService securityService) {
|
||||
return new SecurityInterceptor(tokenValidator, securityService, "app-id");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -241,7 +240,7 @@ class CloudFoundryMvcWebEndpointIntegrationTests {
|
||||
@Bean
|
||||
CloudFoundryWebEndpointServletHandlerMapping cloudFoundryWebEndpointServletHandlerMapping(
|
||||
WebEndpointDiscoverer webEndpointDiscoverer, EndpointMediaTypes endpointMediaTypes,
|
||||
CloudFoundrySecurityInterceptor interceptor) {
|
||||
SecurityInterceptor interceptor) {
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.setAllowedOrigins(Arrays.asList("https://example.com"));
|
||||
corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST"));
|
||||
|
||||
@@ -38,26 +38,26 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
|
||||
/**
|
||||
* Tests for {@link CloudFoundrySecurityInterceptor}.
|
||||
* Tests for {@link SecurityInterceptor}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CloudFoundrySecurityInterceptorTests {
|
||||
class SecurityInterceptorTests {
|
||||
|
||||
@Mock
|
||||
private TokenValidator tokenValidator;
|
||||
|
||||
@Mock
|
||||
private CloudFoundrySecurityService securityService;
|
||||
private SecurityService securityService;
|
||||
|
||||
private CloudFoundrySecurityInterceptor interceptor;
|
||||
private SecurityInterceptor interceptor;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, "my-app-id");
|
||||
this.interceptor = new SecurityInterceptor(this.tokenValidator, this.securityService, "my-app-id");
|
||||
this.request = new MockHttpServletRequest();
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class CloudFoundrySecurityInterceptorTests {
|
||||
|
||||
@Test
|
||||
void preHandleWhenApplicationIdIsNullShouldReturnFalse() {
|
||||
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, null);
|
||||
this.interceptor = new SecurityInterceptor(this.tokenValidator, this.securityService, null);
|
||||
this.request.addHeader("Authorization", "bearer " + mockAccessToken());
|
||||
SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test"));
|
||||
assertThat(response.getStatus()).isEqualTo(Reason.SERVICE_UNAVAILABLE.getStatus());
|
||||
@@ -93,7 +93,7 @@ class CloudFoundrySecurityInterceptorTests {
|
||||
|
||||
@Test
|
||||
void preHandleWhenCloudFoundrySecurityServiceIsNullShouldReturnFalse() {
|
||||
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, null, "my-app-id");
|
||||
this.interceptor = new SecurityInterceptor(this.tokenValidator, null, "my-app-id");
|
||||
this.request.addHeader("Authorization", "bearer " + mockAccessToken());
|
||||
SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test"));
|
||||
assertThat(response.getStatus()).isEqualTo(Reason.SERVICE_UNAVAILABLE.getStatus());
|
||||
@@ -43,11 +43,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withUnauthorizedRequest;
|
||||
|
||||
/**
|
||||
* Tests for {@link CloudFoundrySecurityService}.
|
||||
* Tests for {@link SecurityService}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class CloudFoundrySecurityServiceTests {
|
||||
class SecurityServiceTests {
|
||||
|
||||
private static final String CLOUD_CONTROLLER = "https://my-cloud-controller.com";
|
||||
|
||||
@@ -55,7 +55,7 @@ class CloudFoundrySecurityServiceTests {
|
||||
|
||||
private static final String UAA_URL = "https://my-uaa.com";
|
||||
|
||||
private CloudFoundrySecurityService securityService;
|
||||
private SecurityService securityService;
|
||||
|
||||
private MockRestServiceServer server;
|
||||
|
||||
@@ -63,14 +63,14 @@ class CloudFoundrySecurityServiceTests {
|
||||
void setup() {
|
||||
MockServerRestTemplateCustomizer mockServerCustomizer = new MockServerRestTemplateCustomizer();
|
||||
RestTemplateBuilder builder = new RestTemplateBuilder(mockServerCustomizer);
|
||||
this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, false);
|
||||
this.securityService = new SecurityService(builder, CLOUD_CONTROLLER, false);
|
||||
this.server = mockServerCustomizer.getServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipSslValidationWhenTrue() {
|
||||
RestTemplateBuilder builder = new RestTemplateBuilder();
|
||||
this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, true);
|
||||
this.securityService = new SecurityService(builder, CLOUD_CONTROLLER, true);
|
||||
RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(this.securityService, "restTemplate");
|
||||
assertThat(restTemplate.getRequestFactory()).isInstanceOf(SkipSslVerificationHttpRequestFactory.class);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class CloudFoundrySecurityServiceTests {
|
||||
@Test
|
||||
void doNotSkipSslValidationWhenFalse() {
|
||||
RestTemplateBuilder builder = new RestTemplateBuilder();
|
||||
this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, false);
|
||||
this.securityService = new SecurityService(builder, CLOUD_CONTROLLER, false);
|
||||
RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(this.securityService, "restTemplate");
|
||||
assertThat(restTemplate.getRequestFactory()).isNotInstanceOf(SkipSslVerificationHttpRequestFactory.class);
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class TokenValidatorTests {
|
||||
private static final byte[] DOT = ".".getBytes();
|
||||
|
||||
@Mock
|
||||
private CloudFoundrySecurityService securityService;
|
||||
private SecurityService securityService;
|
||||
|
||||
private TokenValidator tokenValidator;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user