Jboss中的HTTPS配置

时间:2010-08-19 01:19:35

标签: java tomcat ssl jboss https

我正在使用JBoss 4.2。我希望通过HTTPS访问某个URL模式。 我使用了自我认证的密钥库文件,问题是:一旦访问了HTTPS网址, 网站上的所有其他网址都通过HTTPS,有什么问题?

更新:我发现了问题。我使用相对路径来引用资源,所以一旦url更改为HTTPS,所有后续链接都是用HTTPS启动的,那么我是否必须在HTTPS网页中使用绝对路径?

我的配置是这样的: 在web.xml中:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>artists.jsp</web-resource-name>
        <url-pattern>/artists.*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

在server.xml中:

<Connector port="8443" 
   scheme="https"     
   secure="true"    
   clientAuth="false"  
   keystoreFile="${jboss.server.home.dir}/conf/server.keystore"  
   keystorePass="changeit"  
   sslProtocol = "TLS" /> 

1 个答案:

答案 0 :(得分:1)

不幸的是,由于URL以协议(http,https)开头,因此您需要在它们之间切换的绝对路径。

我的建议是:编写一个静态方法,对您的URL进行格式化,并引入一些名称约定,例如以i.g开头的所有页面。 _sec旨在与https一起使用。

伪代码(未经测试只是为了说明基本思想):

public static String fmtURL(String relpath) {
    String url = relparth.startsWith( "_sec" ) ? "https://":"http://";
    url += hostname;                        // from a configfile
    if ( relparth.startsWith( "_sec" ) {
        url += ":443";
    }
    url += relpath;
    return url;
}