Java Code Examples for org.springframework.web.reactive.config.CorsRegistry

The following examples show how to use org.springframework.web.reactive.config.CorsRegistry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void addCorsMappings(CorsRegistry registry) {
	registry.addMapping("/cors-restricted")
			.allowedOrigins("https://foo")
			.allowedMethods("GET", "POST");
	registry.addMapping("/cors");
	registry.addMapping("/ambiguous")
			.allowedMethods("GET", "POST");
}
 
Example 2
Source Project: spring-analysis-note   Source File: DefaultControllerSpecTests.java    License: MIT License 5 votes vote down vote up
@Test
public void configurerConsumers() {
	TestConsumer<ArgumentResolverConfigurer> argumentResolverConsumer = new TestConsumer<>();
	TestConsumer<RequestedContentTypeResolverBuilder> contenTypeResolverConsumer = new TestConsumer<>();
	TestConsumer<CorsRegistry> corsRegistryConsumer = new TestConsumer<>();
	TestConsumer<FormatterRegistry> formatterConsumer = new TestConsumer<>();
	TestConsumer<ServerCodecConfigurer> codecsConsumer = new TestConsumer<>();
	TestConsumer<PathMatchConfigurer> pathMatchingConsumer = new TestConsumer<>();
	TestConsumer<ViewResolverRegistry> viewResolverConsumer = new TestConsumer<>();

	new DefaultControllerSpec(new MyController())
			.argumentResolvers(argumentResolverConsumer)
			.contentTypeResolver(contenTypeResolverConsumer)
			.corsMappings(corsRegistryConsumer)
			.formatters(formatterConsumer)
			.httpMessageCodecs(codecsConsumer)
			.pathMatching(pathMatchingConsumer)
			.viewResolvers(viewResolverConsumer)
			.build();

	assertNotNull(argumentResolverConsumer.getValue());
	assertNotNull(contenTypeResolverConsumer.getValue());
	assertNotNull(corsRegistryConsumer.getValue());
	assertNotNull(formatterConsumer.getValue());
	assertNotNull(codecsConsumer.getValue());
	assertNotNull(pathMatchingConsumer.getValue());
	assertNotNull(viewResolverConsumer.getValue());

}
 
Example 3
@Override
protected void addCorsMappings(CorsRegistry registry) {
	registry.addMapping("/cors-restricted")
			.allowedOrigins("http://foo")
			.allowedMethods("GET", "POST");
	registry.addMapping("/cors");
	registry.addMapping("/ambiguous")
			.allowedMethods("GET", "POST");
}
 
Example 4
Source Project: java-technology-stack   Source File: DefaultControllerSpecTests.java    License: MIT License 5 votes vote down vote up
@Test
public void configurerConsumers() {
	TestConsumer<ArgumentResolverConfigurer> argumentResolverConsumer = new TestConsumer<>();
	TestConsumer<RequestedContentTypeResolverBuilder> contenTypeResolverConsumer = new TestConsumer<>();
	TestConsumer<CorsRegistry> corsRegistryConsumer = new TestConsumer<>();
	TestConsumer<FormatterRegistry> formatterConsumer = new TestConsumer<>();
	TestConsumer<ServerCodecConfigurer> codecsConsumer = new TestConsumer<>();
	TestConsumer<PathMatchConfigurer> pathMatchingConsumer = new TestConsumer<>();
	TestConsumer<ViewResolverRegistry> viewResolverConsumer = new TestConsumer<>();

	new DefaultControllerSpec(new MyController())
			.argumentResolvers(argumentResolverConsumer)
			.contentTypeResolver(contenTypeResolverConsumer)
			.corsMappings(corsRegistryConsumer)
			.formatters(formatterConsumer)
			.httpMessageCodecs(codecsConsumer)
			.pathMatching(pathMatchingConsumer)
			.viewResolvers(viewResolverConsumer)
			.build();

	assertNotNull(argumentResolverConsumer.getValue());
	assertNotNull(contenTypeResolverConsumer.getValue());
	assertNotNull(corsRegistryConsumer.getValue());
	assertNotNull(formatterConsumer.getValue());
	assertNotNull(codecsConsumer.getValue());
	assertNotNull(pathMatchingConsumer.getValue());
	assertNotNull(viewResolverConsumer.getValue());

}
 
Example 5
Source Project: spring-5-examples   Source File: FrontendApplication.java    License: MIT License 5 votes vote down vote up
@Override
public void addCorsMappings(final CorsRegistry registry) {
  registry.addMapping("/api/**")
          .allowedOrigins("*")
          .allowedMethods("POST", "PUT", "DELETE")
          .allowCredentials(true)
          .maxAge(3600);
}
 
Example 6
Source Project: streaming-file-server   Source File: CorsWebFluxConfigurer.java    License: MIT License 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry corsRegistry) {
  corsRegistry.addMapping("/**")
              .allowedHeaders("x-requested-with", "authorization", "Content-Type",
                              "Authorization", "credential", "X-XSRF-TOKEN")
              .allowedMethods("GET", "PUT", "POST", "DELETE", "OPTIONS")
              .allowedOrigins("*")
              .maxAge(3600);
}
 
Example 7
Source Project: tutorials   Source File: CorsGlobalConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry corsRegistry) {
    corsRegistry.addMapping("/**")
        .allowedOrigins("http://allowed-origin.com")
        .allowedMethods("PUT")
        .allowedHeaders("Baeldung-Allowed", "Baledung-Another-Allowed")
        .exposedHeaders("Baeldung-Allowed", "Baeldung-Exposed")
        .maxAge(3600);
}
 
Example 8
Source Project: spring-analysis-note   Source File: DefaultControllerSpec.java    License: MIT License 4 votes vote down vote up
@Override
public DefaultControllerSpec corsMappings(Consumer<CorsRegistry> consumer) {
	this.configurer.corsRegistryConsumer = consumer;
	return this;
}
 
Example 9
Source Project: spring-analysis-note   Source File: DefaultControllerSpec.java    License: MIT License 4 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
	if (this.corsRegistryConsumer != null) {
		this.corsRegistryConsumer.accept(registry);
	}
}
 
Example 10
Source Project: java-technology-stack   Source File: DefaultControllerSpec.java    License: MIT License 4 votes vote down vote up
@Override
public DefaultControllerSpec corsMappings(Consumer<CorsRegistry> consumer) {
	this.configurer.corsRegistryConsumer = consumer;
	return this;
}
 
Example 11
Source Project: java-technology-stack   Source File: DefaultControllerSpec.java    License: MIT License 4 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
	if (this.corsRegistryConsumer != null) {
		this.corsRegistryConsumer.accept(registry);
	}
}
 
Example 12
Source Project: spring-boot-webflux-jjwt   Source File: CORSFilter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
	registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*");
}
 
Example 13
Source Project: spring-reactive-playground   Source File: Application.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
	registry.addMapping("/cors/config");
}
 
Example 14
Source Project: spring-analysis-note   Source File: WebTestClient.java    License: MIT License 2 votes vote down vote up
/**
 * Configure CORS support.
 * @see WebFluxConfigurer#addCorsMappings
 */
ControllerSpec corsMappings(Consumer<CorsRegistry> consumer);
 
Example 15
Source Project: java-technology-stack   Source File: WebTestClient.java    License: MIT License 2 votes vote down vote up
/**
 * Configure CORS support.
 * @see WebFluxConfigurer#addCorsMappings
 */
ControllerSpec corsMappings(Consumer<CorsRegistry> consumer);