Jboss-Seam Https配置

一、seam工程配置
1、使用https的页面
    在页面描述符page.xml中增加
    <page view-id=”/longin.xhtml” scheme=”https” />
2、其他页面使用http
    <page view-id=”*” scheme=”http” />
    说明:如果没有为某一个视图ID指定scheme,seam会使用前一个请求的Scheme
3、配置端口映射
    先给组件描述符(components.xml)添加 navigation命名空间
    xmlns:navigation= “http://jboss.com/products/seam/navigation”
http://jboss.com/products/seam/navigation http://jboss.com/products/seam/navigation-2.2.xsd
    然后配置端口:
    <navigation:pages http-port="8080" https-port="8443"/>
    注意:此配置应放在如下内容的下面:
    <event type="org.jboss.seam.security.notLoggedIn">
<action execute="#{redirect.captureCurrentView}" />
    </event>
    <event type="org.jboss.seam.security.loginSuccessful">
<action execute="#{redirect.returnToCapturedView}" />
    </event>
    如服务器使用标准端口,即http使用80,https使用443,可不需此配置。
    注:此处可参见seam in action 第11章(中文版387页)
二、准备证书密钥库
    Jboss当前支持JKS、 PKCS11、 PKCS12格式的密钥仓库。 JKS(Java KeyStore)是Java标准格式,可以用JDK keytool命令行工具创建。PKCS12是互联网标准格式,可以使用OpenSSL和微软的Key-Manager管理。PKCS11规范,别名是大小写敏感的,为了避免相关问题,不推荐使用。
    RSA算法是安全算法的首选,这也能保证与其他服务和组件的兼容性。
1、生成keystore
    进入jboss 的server/default/config目录,利用keytool工具生成公钥/私钥对,键入如下命令:
keytool -genkeypair -alias mykey -keyalg RSA -keypass changeit -keystore server.keystore -storepass changeit -dname "CN=SUN OU=HAHA O=HAHA L=BEIJING ST=BEIJING C=CN" -validity 90
    选项说明:
    CN- commonName 人名,一般输入域名,如www.domain.com,也支持通配符,如 *.domain.com。在测试时可输入IP。
    OU-organizationUnit 部门或分公司名
    O-organizationName 组织名称
    L-localityName 城市名称
    ST-stateName 州或省名
    C- country 国家的两字码
    -validity 证书有效天数
    执行后,生成server.keystore密钥库文件。
    注意:-storepass 与 -keypass密码必须相同,如不同,在启动jboss时将会产生如下错误“java.io.IOException: Cannot recover key”。Jboss默认密码为"changeit"。
2、导出证书
    输入命令:
    keytool -exportcert -alias mykey -file server.crt -storepass changeit -keystore server.keystore
    执行后,生成server.crt证书文件。
三、JBOSS配置
    开启https
    修改default\deploy\jboss-web.deployer(v4.2,v5/6为jbossweb.sar)下的server.xm,如下:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               keystoreFile="/conf/server.keystore"
                   keystorePass="password" />
    选项说明
algorithm 证书编码算法。默认是Sun实现(SunX509),IBM JVM应该使用“IbmX509”
clientAuth 在接受连接前,如果想让SSL堆栈从客户端获得一个有效的证书链,应设为”true”。如果需要客户端证书,但如不存在也不会失败,则设为“want”。默认值为“false”,则不需要证书链,除非客户端请求受安全约束保护的资源。
keystoreFile 密钥库路径名,默认值是用户主目录下 ".keystore"文件。
keystorePass 密钥库密码,默认值是"changeit"。
keystoreType 默认值为"JKS"。使用openssl 生成的*.p12文件时,应为“PKCS12”。
sslProtocol SSL协议版本,默认值为 "TLS"。
ciphers 逗号分隔的加密密码列表,如果不指定任何密码都可以使用。
keyAlias 密钥库中服务器证书的别名。如果没有指定,则使用密钥库中的第一项。
truststoreFile 用来验证客户端证书的TrustStore文件。
truststorePass TrustStore密码, 默认为keystorePass的值。
truststoreType 如果使用了与KeyStore不同的格式,需用此属性。

参考文档http://docs.jboss.org/jbossweb/latest/ssl-howto.html
SSL
SSL, or Secure Socket Layer, is a technology which allows web browsers and web servers to communicate over a secured connection. This means that the data being sent is encrypted by one side, transmitted, then decrypted by the other side before processing. This is a two-way process, meaning that both the server AND the browser encrypt all traffic before sending out data.
Another important aspect of the SSL protocol is Authentication. This means that during your initial attempt to communicate with a web server over a secure connection, that server will present your web browser with a set of credentials, in the form of a "Certificate", as proof the site is who and what it claims to be. In certain cases, the server may also request a Certificate from your web browser, asking for proof that you are who you claim to be. This is known as "Client Authentication," although in practice this is used more for business-to-business (B2B) transactions than with individual users. Most SSL-enabled web servers do not request Client Authentication.

猜你喜欢

转载自billben.iteye.com/blog/1560079