当前位置: 首页>>代码示例>>Java>>正文


Java CorsConfiguration.addAllowedOrigin方法代码示例

本文整理汇总了Java中org.springframework.web.cors.CorsConfiguration.addAllowedOrigin方法的典型用法代码示例。如果您正苦于以下问题:Java CorsConfiguration.addAllowedOrigin方法的具体用法?Java CorsConfiguration.addAllowedOrigin怎么用?Java CorsConfiguration.addAllowedOrigin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.cors.CorsConfiguration的用法示例。


在下文中一共展示了CorsConfiguration.addAllowedOrigin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
FilterRegistrationBean corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("*");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);

    FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(Ordered.HIGHEST_PRECEDENCE);

    return bean;
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:17,代码来源:AuthorizationServerConfig.java

示例2: webSocketMapping

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
HandlerMapping webSocketMapping(CommentService commentService) {
	Map<String, WebSocketHandler> urlMap = new HashMap<>();
	urlMap.put("/topic/comments.new", commentService);

	Map<String, CorsConfiguration> corsConfigurationMap =
		new HashMap<>();
	CorsConfiguration corsConfiguration = new CorsConfiguration();
	corsConfiguration.addAllowedOrigin("http://localhost:8080");
	corsConfigurationMap.put(
		"/topic/comments.new", corsConfiguration);

	SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
	mapping.setOrder(10);
	mapping.setUrlMap(urlMap);
	mapping.setCorsConfigurations(corsConfigurationMap);

	return mapping;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:WebSocketConfig.java

示例3: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
public FilterRegistrationBean corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    // return new CorsFilter(source);
    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(0);
    return bean;
}
 
开发者ID:lorderikir,项目名称:googlecloud-techtalk,代码行数:21,代码来源:CorsConfig.java

示例4: buildConfig

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
/**
 * CORS配置
 * 
 * @return
 */
private CorsConfiguration buildConfig() {
	// 新建CORS配置
	CorsConfiguration corsConfiguration = new CorsConfiguration();
	// 设置允许访问的请求源HTTP
	corsConfiguration.addAllowedOrigin("*");
	// 设置允许访问的请求源方法
	corsConfiguration.addAllowedMethod("*");
	corsConfiguration.setAllowCredentials(true);
	// 添加了新的header,需要配置白名单
	List<String> allowedHeaders = Lists.newArrayList();
	allowedHeaders.add("Content-Type");
	allowedHeaders.add("authorization");
	allowedHeaders.add("x-requested-with");
	corsConfiguration.setAllowedHeaders(allowedHeaders);
	// 返回CORS配置
	return corsConfiguration;
}
 
开发者ID:sdc1234,项目名称:zhihu-spider,代码行数:23,代码来源:CorsConfig.java

示例5: webSocketMapping

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
HandlerMapping webSocketMapping(CommentService commentService,
								InboundChatService inboundChatService,
								OutboundChatService outboundChatService) {
	SimpleUrlHandlerMapping mapping =
		configureUrlMappings(commentService, inboundChatService, outboundChatService);

	Map<String, CorsConfiguration> corsConfigurationMap = new HashMap<>();
	CorsConfiguration corsConfiguration = new CorsConfiguration();
	corsConfiguration.addAllowedOrigin(chatConfigProperties.getOrigin());

	mapping.getUrlMap().keySet().forEach(route ->
		corsConfigurationMap.put(route, corsConfiguration)
	);

	mapping.setCorsConfigurations(corsConfigurationMap);

	return mapping;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:WebSocketConfig.java

示例6: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
/**
 *
 * @return
 */
@Bean
public CorsFilter corsFilter() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
开发者ID:PacktPublishing,项目名称:Microservices-Building-Scalable-Software,代码行数:22,代码来源:EdgeApp.java

示例7: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
/**
 * Enables CORS
 *
 * @return
 */
@Bean
public FilterRegistrationBean corsFilter() {
	UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	CorsConfiguration config = new CorsConfiguration();
	config.setAllowCredentials(true);
	config.addAllowedOrigin("*");
	config.addAllowedHeader("*");
	config.addAllowedMethod("OPTIONS");
	config.addAllowedMethod("HEAD");
	config.addAllowedMethod("GET");
	config.addAllowedMethod("PUT");
	config.addAllowedMethod("POST");
	config.addAllowedMethod("DELETE");
	config.addAllowedMethod("PATCH");
	source.registerCorsConfiguration("/**", config);
	final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
	bean.setOrder(0);
	return bean;
}
 
开发者ID:jiaweizhang,项目名称:assimulator,代码行数:25,代码来源:Application.java

示例8: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
public FilterRegistrationBean corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(0);
    return bean;
}
 
开发者ID:fku233,项目名称:Plum,代码行数:20,代码来源:CorsConfig.java

示例9: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
public CorsFilter corsFilter() {

    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);

    // TODO - Lock down to specific host in Prod
    config.addAllowedOrigin("*");
    //config.addAllowedOrigin("http://localhost:3000");

    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("DELETE");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:21,代码来源:RestCorsConfig.java

示例10: getCorsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
private CorsFilter getCorsFilter() {

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
  }
 
开发者ID:oasp,项目名称:oasp-tutorial-sources,代码行数:18,代码来源:BaseWebSecurityConfig.java

示例11: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
public FilterRegistrationBean corsFilter() {
    // setup origin url
    String origin = corsProperties.getHost() + ":" +
                    corsProperties.getPort();

    // setup cors config
    CorsConfiguration corsConfig = new CorsConfiguration();
    corsConfig.setAllowCredentials(true);
    corsConfig.addAllowedOrigin(origin);
    corsConfig.addAllowedHeader("*");
    corsConfig.addAllowedMethod("*");

    // setup source
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/api/**", corsConfig);
    FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(0);

    return bean;
}
 
开发者ID:rvep,项目名称:dev_backend,代码行数:22,代码来源:CorsFilterRegistration.java

示例12: actualRequestWithMappedCorsConfiguration

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Test
public void actualRequestWithMappedCorsConfiguration() throws Exception {
	CorsConfiguration config = new CorsConfiguration();
	config.addAllowedOrigin("*");
	this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/foo", config));
	this.request.setMethod(RequestMethod.GET.name());
	this.request.setRequestURI("/foo");
	this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
	this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
	HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
	assertNotNull(chain);
	assertTrue(chain.getHandler() instanceof SimpleHandler);
	config = getCorsConfiguration(chain, false);
	assertNotNull(config);
	assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:CorsAbstractHandlerMappingTests.java

示例13: preflightRequestWithMappedCorsConfiguration

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Test
public void preflightRequestWithMappedCorsConfiguration() throws Exception {
	CorsConfiguration config = new CorsConfiguration();
	config.addAllowedOrigin("*");
	this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/foo", config));
	this.request.setMethod(RequestMethod.OPTIONS.name());
	this.request.setRequestURI("/foo");
	this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
	this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
	HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
	assertNotNull(chain);
	assertNotNull(chain.getHandler());
	assertTrue(chain.getHandler().getClass().getSimpleName().equals("PreFlightHandler"));
	config = getCorsConfiguration(chain, true);
	assertNotNull(config);
	assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CorsAbstractHandlerMappingTests.java

示例14: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
@Bean
public FilterRegistrationBean corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);

    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return bean;
}
 
开发者ID:sys-devel-d,项目名称:pimp,代码行数:21,代码来源:SecurityConfig.java

示例15: corsFilter

import org.springframework.web.cors.CorsConfiguration; //导入方法依赖的package包/类
/**
 * Enables CORS
 *
 * @return
 */
@Bean
public FilterRegistrationBean corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(0);
    return bean;
}
 
开发者ID:jiaweizhang,项目名称:spotify-pull-requests,代码行数:25,代码来源:Application.java


注:本文中的org.springframework.web.cors.CorsConfiguration.addAllowedOrigin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。