Spring 如何在从KeyClope重定向后获取https链接
我们有一个spring启动应用程序,很久以前就建立了KeyClope。 一切正常,直到我们看到重定向后的一些链接是http而不是https: 这是我已经尝试解决的问题: (一) 添加了以下属性:Spring 如何在从KeyClope重定向后获取https链接,spring,spring-boot,https,keycloak,Spring,Spring Boot,Https,Keycloak,我们有一个spring启动应用程序,很久以前就建立了KeyClope。 一切正常,直到我们看到重定向后的一些链接是http而不是https: 这是我已经尝试解决的问题: (一) 添加了以下属性: server.use-forward-headers=true server.tomcat.internal-proxies=.* server.tomcat.remote-ip-header=x-forwarded-for server.tomcat.protocol-header=x-forward
server.use-forward-headers=true
server.tomcat.internal-proxies=.*
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
当我以某种方式添加这些内容时,行为发生了变化,keybeave“生成”了一个URI,并将端口0添加到(外部)链接中。这导致了403错误
为了解决这个问题,我必须在我的KeyClope配置中添加以下行:
(二)
这成功地从我的链接中删除了端口0并重定向了我,但我仍然收到403错误
这是我在日志中看到的:
ERROR [bootstrap,,,] 1 --- [nio-8080-exec-9] o.k.adapters.OAuthRequestAuthenticator : Adapter requires SSL. Request: http://example.be/REST/location/sso/login?state=df826bc4-86c1-4af5-b5fb-51f03107c18b&session_state=9ba8e48a-9d81-407f-9cf4-d50308793818&code=ea14f45f-775a-4a28-b94b-8856b7880890.9ba8e48a-9d81-407f-9cf4-d50308793818.915a1b76-9f38-48fe-bed6-7404bd5caf21
这一次我也试了很多,但没有任何结果
注意,在日志中我们看到的是http而不是https。
在我的浏览器中,我转到导航栏中的https
编辑:
我对代码进行了调试,发现以下内容:
if (!isRequestSecure() && deployment.getSslRequired().isRequired(facade.getRequest().getRemoteAddr())) {
log.error("Adapter requires SSL. Request: " + facade.getRequest().getURI());
return challenge(403, OIDCAuthenticationError.Reason.SSL_REQUIRED, null);
}
这就是错误的来源。
!isRequestSecure返回true,因为在我的SimpleHttpFacade中,secure设置为false。是否找到了解决方案或解决方法?是否存在相同的问题?在我的例子中,问题是因为我的公司使用了自定义的标题字段,而不是x-forwarded-for。因此,如果是,请尝试调试并检查标题字段。您是否找到了解决方案或解决方法?您是否有相同的问题?在我的例子中,问题是因为我的公司使用了自定义的标题字段,而不是x-forwarded-for。因此,如果是,请尝试调试并检查标题字段。
if (!isRequestSecure() && deployment.getSslRequired().isRequired(facade.getRequest().getRemoteAddr())) {
log.error("Adapter requires SSL. Request: " + facade.getRequest().getURI());
return challenge(403, OIDCAuthenticationError.Reason.SSL_REQUIRED, null);
}