- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在升级到 spring-boot 1.3 后,我试图切换到 spring 4.2 的本地全局 CORS 支持,但它似乎不适用于 CAS 过滤器进程 url(/login/cas)。
最初,我使用 spring-boot 1.2.7 和 spring 4.2 和 spring-security 4.0.2,并使用自制的基于过滤的 cors 支持。我自己的休息服务或 CAS ST 验证 URL 运行良好。在我升级到 spring-boot 1.3 并推出 spring 和 spring-security 版本之后。它停止工作。
经过一番挖掘,通过 AddFilterBefore 修复了这个问题.所以基于过滤的 CORS 似乎也适用于 spring-boot 1.3.0 + spring-security-cas。
但是,我想使用 native 全局 CORS,但似乎无法识别 CAS ST 验证 URL(/login/cas),尽管其他其余端点都可以。
请帮忙。
设置非常简单。
@Configuration
public class CorsConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
};
}
}
Request URL:http://localhost:9000/login/cas?ticket=ST-1357-15aQrv93jGEUsQpQRF1P-cas01.example.org
Request Method:GET
Status Code:302 Found
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Length:0
Date:Thu, 19 Nov 2015 09:19:31 GMT
Expires:0
Location:http://localhost:9000/
Pragma:no-cache
Server:Apache-Coyote/1.1
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
XMLHttpRequest cannot load http://localhost:9000/login/cas?ticket=ST-1357-15aQrv93jGEUsQpQRF1P-cas01.example.org. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
最佳答案
默认情况下,在 Spring MVC HandlerMapping
中完成 CORS 原生支持级别,因此预计您的 CAS 过滤器不会启用 CORS,因为它会更早地处理请求。
要考虑的一种选择是使用 org.springframework.web.filter.CorsFilter
我们还提供带有 AddFilterBefore
的 Spring Framework 4.2方法。
请注意 CorsConfiguration
没有与 @CrossOrigin
相同的默认配置或 CorsRegistry
,因此您需要自己定义大部分属性,例如:
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true); // you USUALLY want this
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
source.registerCorsConfiguration("/**", config);
CorsFilter filter = new CorsFilter(source);
// ...
关于Spring 4. 2's native Global CORS support won' t 与 CAS filterProcessesUrl 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33799406/
在升级到 spring-boot 1.3 后,我试图切换到 spring 4.2 的本地全局 CORS 支持,但它似乎不适用于 CAS 过滤器进程 url(/login/cas)。 最初,我使用 sp
我是一名优秀的程序员,十分优秀!