我有以下的架构。
我有一个spring云网关服务器,它处理身份验证、授权和路由。我们可以叫他服务器A。
另一个服务器是身份验证服务器B,它使用Kerberos对用户进行身份验证。要使用它,A将表单A/a/route的请求重定向到具有状态307的表单B/a/route的请求。
然后服务器B对用户进行身份验证,并使用JWT添加cookie,并使用状态307以重定向A/a/route进行响应。
当服务器A使用JWT获得重定向请求时,他会将其代理到API服务器。
在整个过程中,我们得到以下错误
未能加载
A/a/route:从A/a/route重定向到B/a/route已被CORS策略阻止:“访问控制-允许-原产地”标头包含多个值'*,http://localhost:4200',但只允许一个。因此,“http://localhost:4200”源是不允许访问的。
我们将所有Access-Control-Allow-*头设置为允许服务器、A和B上的所有请求按以下方式进行
在spring网关服务器中
@Bean
public WebFilter corsFilter() {
return (ServerWebExchange exchange, WebFilterChain chain) -> {
ServerHttpRequest request = exchange.getRequest();
if (CorsUtils.isCorsRequest(request)) {
ServerHttpResponse response = exchange.getResponse();
HttpHeaders headers = response.getHeaders();
headers.add("Access-Control-Allow-Method", "POST, GET, OPTIONS, PUT");
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Headers", /* HEADRS */);
headers.add("Access-Control-Allow-Credentials", "true");
if (HttpMethod.OPTIONS.equals(request.getMethod())) {
response.setStatusCode(HttpStatus.OK);
return Mono.empty();
}
}
return chain.filter(exchange);
}
} 在apache-httpd Kerberos服务器中。
<VirtualHost *>
LuaRoot /etc/httpd/lua
LuaHookFixups authz.lua check_authz_cookie
ProxyPreserveHost On
SetEnvIf Origin "(.*)" origin=$0
Header always set Access-Control-Allow-Origin "%{origin}e"
Header always set Access-Control-Allow-Method "POST, GET, OPTIONS, PUT"
Header always set Access-Control-Allow-Credentials "true"
Header always set Access-Control-Allow-Headers # HEADERS...
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
ProxyPass /whoami !
ProxyPass / A
ProxyPassReverse / A
</VirtualHost>我们期望重定向工作,但CORS的问题会发生。
发布于 2019-06-27 11:44:43
CORS策略不允许“访问-控制-允许-原产地”标题中的多个值。尝试删除“*”,并确保在“访问控制-允许-原产地”中只设置一个地址。
https://stackoverflow.com/questions/56789566
复制相似问题