當前位置: 首頁>>代碼示例>>Java>>正文


Java CorsConfiguration.setAllowedMethods方法代碼示例

本文整理匯總了Java中org.springframework.web.cors.CorsConfiguration.setAllowedMethods方法的典型用法代碼示例。如果您正苦於以下問題:Java CorsConfiguration.setAllowedMethods方法的具體用法?Java CorsConfiguration.setAllowedMethods怎麽用?Java CorsConfiguration.setAllowedMethods使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.cors.CorsConfiguration的用法示例。


在下文中一共展示了CorsConfiguration.setAllowedMethods方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: casCorsFilter

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
@ConditionalOnProperty(prefix = "cas.httpWebRequest.cors", name = "enabled", havingValue = "true")
@Bean
@RefreshScope
public FilterRegistrationBean casCorsFilter() {
    final HttpWebRequestProperties.Cors cors = casProperties.getHttpWebRequest().getCors();
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(cors.isEnabled());
    config.setAllowedOrigins(cors.getAllowOrigins());
    config.setAllowedMethods(cors.getAllowMethods());
    config.setAllowedHeaders(cors.getAllowHeaders());
    config.setMaxAge(cors.getMaxAge());
    config.setExposedHeaders(cors.getExposedHeaders());
    source.registerCorsConfiguration("/**", config);
    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setName("casCorsFilter");
    bean.setAsyncSupported(true);
    bean.setOrder(0);
    return bean;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:21,代碼來源:CasFiltersConfiguration.java

示例2: corsFilterBean

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
/**
 * <a href="https://github.com/spring-projects/spring-boot/issues/5834#issuecomment-296370088">See explanation here</a>
 */
@Bean
public FilterRegistrationBean corsFilterBean() {
	final CorsConfiguration configuration = new CorsConfiguration();
	configuration.setAllowedOrigins(Collections.singletonList("*"));
	configuration.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"));
	// setAllowCredentials(true) is important, otherwise:
	// The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
	configuration.setAllowCredentials(true);
	// setAllowedHeaders is important! Without it, OPTIONS preflight request
	// will fail with 403 Invalid CORS request
	configuration.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type"));
	final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	source.registerCorsConfiguration("/**", configuration);
	FilterRegistrationBean corsFilter = new FilterRegistrationBean(new CorsFilter(source));
	corsFilter.setOrder(Ordered.HIGHEST_PRECEDENCE);
	return corsFilter;
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:21,代碼來源:WebSecurityConfig.java

示例3: corsFilter

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
@Bean
public CorsFilter corsFilter() {
    return new CorsFilter(request -> {
        String pathInfo = request.getPathInfo();
        if (pathInfo != null &&
            (pathInfo.endsWith("/swagger.json") ||
             pathInfo.endsWith("/swagger.yaml"))) {
            return new CorsConfiguration().applyPermitDefaultValues();
        }

        CorsConfiguration config = new CorsConfiguration();
        config.setAllowedOrigins(allowedOrigins);
        config.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"));
        config.applyPermitDefaultValues();
        return config;
    });
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:18,代碼來源:SyndesisCorsConfiguration.java

示例4: corsConfigurationSource

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
@Bean
public CorsConfigurationSource corsConfigurationSource() {
	CorsConfiguration configuration = new CorsConfiguration();
	configuration.setAllowedOrigins(ImmutableList.of("*"));
	configuration.setAllowedMethods(ImmutableList.of("*"));
	configuration.setAllowCredentials(true);

	configuration.setAllowedHeaders(ImmutableList.of("*"));
	UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	source.registerCorsConfiguration("/**", configuration);

	return source;
}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:14,代碼來源:SecurityConfig.java

示例5: getCorsConfiguration

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
private CorsConfiguration getCorsConfiguration(EndpointCorsProperties properties) {
	if (CollectionUtils.isEmpty(properties.getAllowedOrigins())) {
		return null;
	}
	CorsConfiguration configuration = new CorsConfiguration();
	configuration.setAllowedOrigins(properties.getAllowedOrigins());
	if (!CollectionUtils.isEmpty(properties.getAllowedHeaders())) {
		configuration.setAllowedHeaders(properties.getAllowedHeaders());
	}
	if (!CollectionUtils.isEmpty(properties.getAllowedMethods())) {
		configuration.setAllowedMethods(properties.getAllowedMethods());
	}
	if (!CollectionUtils.isEmpty(properties.getExposedHeaders())) {
		configuration.setExposedHeaders(properties.getExposedHeaders());
	}
	if (properties.getMaxAge() != null) {
		configuration.setMaxAge(properties.getMaxAge());
	}
	if (properties.getAllowCredentials() != null) {
		configuration.setAllowCredentials(properties.getAllowCredentials());
	}
	return configuration;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:24,代碼來源:EndpointWebMvcManagementContextConfiguration.java

示例6: corsFilter

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration corsConfiguration = new CorsConfiguration();

    corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:4200"));
    corsConfiguration.setAllowedMethods(Arrays.asList(CorsConfiguration.ALL));
    corsConfiguration.setAllowedHeaders(Arrays.asList(CorsConfiguration.ALL));
    corsConfiguration.addExposedHeader(SecurityConstant.HEADER_SECURITY_TOKEN);
    corsConfiguration.setAllowCredentials(true);

    source.registerCorsConfiguration("/**", corsConfiguration);
    return new CorsFilter(source);
}
 
開發者ID:yuexine,項目名稱:loafer,代碼行數:15,代碼來源:WebConfiguration.java

示例7: corsConfigurationSource

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
protected CorsConfigurationSource corsConfigurationSource() {
    final CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowCredentials(true);
    configuration.setAllowedOrigins(Arrays.asList("*"));
    configuration.setAllowedMethods(Arrays.asList("GET", "POST", "DELETE", "PUT"));
    configuration.setAllowedHeaders(Arrays.asList("X-Requested-With", "Authorization"));
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
}
 
開發者ID:panga,項目名稱:unibave-backend,代碼行數:11,代碼來源:WebSecurityConfig.java

示例8: configurationSource

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
private static UrlBasedCorsConfigurationSource configurationSource() {
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.setMaxAge(36000L);
    config.setAllowedMethods(Arrays.asList("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"));
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return source;
}
 
開發者ID:mjfcolas,項目名稱:infotaf,代碼行數:12,代碼來源:CustomCorsFilter.java

示例9: corsConfigurationSource

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
@Bean
public CorsConfigurationSource corsConfigurationSource() {
    final CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowedOrigins(ImmutableList.of("http://localhost:4200"));
    configuration.setAllowedMethods(Arrays.asList(CORS_ALLOWED_METHODS));
    configuration.setAllowCredentials(false);
    configuration.setAllowedHeaders(Arrays.asList(CORS_ALLOW_HEADERS));

    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
}
 
開發者ID:vlsidlyarevich,項目名稱:unity,代碼行數:13,代碼來源:SecurityConfig.java

示例10: corsConfigurationSource

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
/**
 * CorsConfigurationSource bean initializer.
 * @return cors configuration
 */
@Bean
public CorsConfigurationSource corsConfigurationSource() {
  UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
  if (allowedOrigins.length > 0) {
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowedOrigins(Arrays.asList(allowedOrigins));
    configuration.setAllowedMethods(Arrays.asList(allowedMethods));
    source.registerCorsConfiguration("/**", configuration);
  }
  return source;
}
 
開發者ID:OpenLMIS,項目名稱:openlmis-stockmanagement,代碼行數:16,代碼來源:ResourceServerSecurityConfiguration.java

示例11: corsFilter

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowCredentials(true);
    configuration.addAllowedOrigin("*");
    configuration.addAllowedHeader("*");
    configuration.setAllowedMethods(Arrays.asList("GET", "PUT", "POST", "DELETE"));
    source.registerCorsConfiguration("/**", configuration);
    return new CorsFilter(source);
}
 
開發者ID:MSUNorg,項目名稱:luckyBlog,代碼行數:12,代碼來源:WebMvcConf.java

示例12: corsFilter

import org.springframework.web.cors.CorsConfiguration; //導入方法依賴的package包/類
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowCredentials(true);
    configuration.addAllowedOrigin("*");
    configuration.addAllowedHeader("*");
    configuration.setAllowedMethods(Arrays.asList("GET", "PUT", "POST","DELETE"));
    source.registerCorsConfiguration("/**", configuration);
    return new CorsFilter(source);
}
 
開發者ID:jcalaz,項目名稱:jcalaBlog,代碼行數:12,代碼來源:WebMvcConf.java


注:本文中的org.springframework.web.cors.CorsConfiguration.setAllowedMethods方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。