如何在 Tomcat 6 中从 SSL 恢复为非 SSL?
我正在使用 jsf 2 + jaas + ssl + tomcat 6.0.26
我的网站中有 2 个路径:
/faces/protected/* 使用 SSL
/faces/unprotected/* 不使用 SSL。
我已将其放入我的 web.xml 中:
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/faces/login.jsp</form-login-page>
<form-error-page>/faces/error.jsp</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Resource</web-resource-name>
<description/>
<url-pattern>/faces/unprotected/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>C</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Resource</web-resource-name>
<description />
<url-pattern>/faces/protected/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>C</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-role>
<description> Role Client </description>
<role-name>C</role-name>
</security-role>
这是我的 server.xml:
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="400"
maxKeepAliveRequests="1"
acceptCount="100"
connectionTimeout="3000"
redirectPort="8443"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/javascript,text/css,text/html, text/xml,text/plain,application/x-javascript,application/javascript,application/xhtml+xml" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" SSLEnabled="true"
maxThreads="400" scheme="https" secure="true"
clientAuth="optional" sslProtocol="TLS"
SSLCertificateFile="path/to/crt"
SSLCertificateKeyFile="path/to/pem"/>
当我进入受保护的路径时,它会切换到 HTTPS(端口 8443),但是当我进入路径 /faces/unprotected/something...它仍然使用 HTTPS。
我想要的是,当我进入不受保护的路径时,它会恢复到非 SSL 通信(否则,当我在浏览器中设置确切的地址时,我必须再次重新登录)。
我的配置有什么问题吗?
有没有办法让我可以做这样的事情?
是否可以使用调用该页面而无需再次请求身份验证?
I'm using jsf 2 + jaas + ssl + tomcat 6.0.26
I have in my web site 2 paths:
/faces/protected/* which uses SSL
/faces/unprotected/* which don't uses SSL.
I've put this in my web.xml:
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/faces/login.jsp</form-login-page>
<form-error-page>/faces/error.jsp</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Resource</web-resource-name>
<description/>
<url-pattern>/faces/unprotected/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>C</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Resource</web-resource-name>
<description />
<url-pattern>/faces/protected/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>C</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-role>
<description> Role Client </description>
<role-name>C</role-name>
</security-role>
and this is my server.xml:
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="400"
maxKeepAliveRequests="1"
acceptCount="100"
connectionTimeout="3000"
redirectPort="8443"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/javascript,text/css,text/html, text/xml,text/plain,application/x-javascript,application/javascript,application/xhtml+xml" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" SSLEnabled="true"
maxThreads="400" scheme="https" secure="true"
clientAuth="optional" sslProtocol="TLS"
SSLCertificateFile="path/to/crt"
SSLCertificateKeyFile="path/to/pem"/>
when i enter to protected paths, it switches to HTTPS (port 8443), but when i enter to path /faces/unprotected/somthing... it stays using HTTPS.
what i want is when i enter to unprotected paths, it revert-back to non-SSL communications ( otherwise, i have to re-login again when i set the exact adress in my browser).
What's wrong with my configurations ?
Is there a way so i can do such a thing ?
Is it possible to call the page using without asking for authentification second time ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是 Tomcat 上的正常行为。
一旦转入 https,它就不会将其他 URL 重定向回 http,除非该 URL 明确用于 http。
如果你确实需要,你必须编写
过滤
以检查 URL 是否不属于安全模式的一部分,然后重定向回 http。Yes, that is the normal behaviour on Tomcat.
Once it moves into https, it will not redirect other URLs back into http, unless the URL explicitly is for http.
If you really need to, you would have to write a
Filter
to check if the URL is not part of the secured pattern, then redirect back to http.如果您在 HTTPS 下登录,然后返回到 HTTP,则会将经过身份验证的 cookie 暴露给中间人攻击。这很糟糕。
在会话经过身份验证的整个过程中,您应该保持 HTTPS。
与您的应用程序所做的工作相比,执行 SSL 所需的计算完全微不足道。坚持使用 SSL 即可。
If you log in under HTTPS and then move back to HTTP, you are exposing an authenticated cookie to a man-in-the-middle attack. This is bad.
You should remain in HTTPS for the entire time your session is authenticated.
The compute required to perform SSL is, in comparison to the work your app does, completely trivial. Just stick with SSL.