本文整理汇总了Java中org.springframework.web.cors.CorsConfigurationSource类的典型用法代码示例。如果您正苦于以下问题:Java CorsConfigurationSource类的具体用法?Java CorsConfigurationSource怎么用?Java CorsConfigurationSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CorsConfigurationSource类属于org.springframework.web.cors包,在下文中一共展示了CorsConfigurationSource类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: corsConfigurationSource
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的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;
}
示例2: corsConfiguration
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的package包/类
private CorsConfigurationSource corsConfiguration() {
return new CorsConfigurationSource() {
@Override
public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
CorsConfiguration corsConfig = new CorsConfiguration();
if(asList(env.getActiveProfiles()).contains(PROFILE_DEV)) {
corsConfig.setAllowedOrigins(asList("http://localhost:9090", "http://127.0.0.1:9090", "http://localhost:7070", "http://127.0.0.1:7070"));
} else if (asList(env.getActiveProfiles()).contains(PROFILE_TEST)) {
corsConfig.setAllowedOrigins(asList("https://bitcoin2-test.csg.uzh.ch"));
} else if (asList(env.getActiveProfiles()).contains(PROFILE_PROD)) {
corsConfig.setAllowedOrigins(asList("https://bitcoin.csg.uzh.ch"));
}
corsConfig.setAllowedMethods(asList("GET", "PUT", "POST", "DELETE", "OPTIONS"));
corsConfig.setAllowedHeaders(asList("*"));
corsConfig.setMaxAge(1800L);
return corsConfig;
}
};
}
示例3: corsConfigurationSource
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的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;
}
示例4: getCorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的package包/类
/**
* Retrieve the CORS configuration for the given handler.
* @param handler the handler to check (never {@code null}).
* @param request the current request.
* @return the CORS configuration for the handler or {@code null}.
* @since 4.2
*/
protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) {
if (handler instanceof HandlerExecutionChain) {
handler = ((HandlerExecutionChain) handler).getHandler();
}
if (handler instanceof CorsConfigurationSource) {
return ((CorsConfigurationSource) handler).getCorsConfiguration(request);
}
return null;
}
示例5: getCorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的package包/类
@Override
public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
if (this.sockJsService instanceof CorsConfigurationSource) {
return ((CorsConfigurationSource) this.sockJsService).getCorsConfiguration(request);
}
return null;
}
示例6: corsConfigurationSource
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的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;
}
示例7: corsConfigurationSource
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的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;
}
示例8: CorsFilter
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的package包/类
public CorsFilter(CorsConfigurationSource configSource) {
super(configSource);
}
示例9: corsConfigurationSource
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的package包/类
@Bean
public CorsConfigurationSource corsConfigurationSource() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
return source;
}
示例10: CorsFilter
import org.springframework.web.cors.CorsConfigurationSource; //导入依赖的package包/类
/**
* Constructor accepting a {@link CorsConfigurationSource} used by the filter to find
* the {@link CorsConfiguration} to use for each incoming request.
* @see UrlBasedCorsConfigurationSource
*/
public CorsFilter(CorsConfigurationSource configSource) {
this.configSource = configSource;
}