gpt4 book ai didi

java - 如何在应用程序中为所需页面实现 HTTPS?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:32:39 25 4
gpt4 key购买 nike

我们正在尝试为应用程序中的某些页面实现 HTTPS。因此,我们更改了 tomcat server.xml 以进行 HTTPS 调用,如下所示:

<Connector
port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
acceptCount="100"
maxKeepAliveRequests="15"
SSLEnabled="true"
scheme="https"
secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/webapps/test.bin"
keystorePass="test"/>

在应用程序 web.xml 中:

<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

因此,HTTPS 正在应用于所有页面。如何限制所需页面的 HTTPS。

帮助将不胜感激。

最佳答案

Spring Security Interceptor 有一个参数requires-channel。将此参数设置为 https 以针对与拦截器匹配的 url 模式强制执行它。

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:security="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.4.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<security:http>
<security:intercept-url pattern="/login" access="permitAll"
requires-channel="https"/>
</security:http>

</bean>

关于java - 如何在应用程序中为所需页面实现 HTTPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8165113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com