當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。