如何在 Tomcat 6 中从 SSL 恢复为非 SSL?

发布于 2024-10-09 10:37:20 字数 3689 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花易冷人易散 2024-10-16 10:37:20

是的,这是 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.

鹊巢 2024-10-16 10:37:20

如果您在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文