在OC4J中轻松快速配置SSL
作者:yuliming5219
日期:2008-4-16
在发布某些web应用有的时候需要ssl 。为了获得一些证书校验功能往往需要花费大量的时间和精力。特别是当有一些问题需要处理的时候。这篇文章就描述了一种容易的方式来利用SUN 的 keytool 生成证书文件 并且配置它在 OC4J中使用。这些在
Oracle Application Server Containers for J2ee Stand Alone User’s Guide 中有一些涉及
。在开始之前我我假设你已经成功安装了JDK1.3 或者以上版本。确定你已经设置了JDK到你的PATH 环境变量中。
1. 建立证书
打开命令行窗口到你的OC4J 的config目录下 输入下列命令:
keytool -genkey -keyalg "RSA" -keystore sslfile -storepass simanoel -validity 365
解释:
keystore
:设置证书文件名
storepass
:设置证书文件密码
validity
:设置证书失效天数
设置完以上参数执行keytool后会提示输入一些问题。按照你的实际情况输入一些值。然后证书文件将生成在了你的当前文件夹下了。
2. 配置OC4J
如果在oc4j config目录下面不存在 secure-web-site.xml 文件,那么,拷贝一个
http- web-site.xml 文件并且重命名为
secure-web-site.xml 。然后,编辑secure-web-site.xml文件。在
website元素下 增加
secure=”true” 属性。在website 元素里加入 创建证书文件时需要的 文件名和密码设置的语句。端口需要实际可用的端口。Ssl默认的端口号是443,但是你不得不以一个超级管理员身份来用它。我经常将它设置成 4443 。保存所有的修改,设置后的文件如下:
secure-web-site.xml文件配置:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE web-site PUBLIC "OracleAS XML Web-site" "http://xmlns.oracle.com/ias/dtds/web-site-9_04.dtd">
<web-site port="4443" display-name="OC4J 10g (10.0.2) HTTP Web Site" secure="true">
<ssl-config keystore="sslfile" keystore-password="simanoel"/>
<default-web-app application="default" name="defaultWebApp"/>
<web-app application="default" name="dms0" root="/dms0" access-log="false" />
<web-app application="default" name="dms0" root="/dmsoc4j" access-log="false" />
<web-app application="default" name="admin_web" root="/adminoc4j"/>
<web-app application="default" name="pgagentweb" root="/pgagentweb" load-on-startup="true" />
<access-log path="../log/http-web-access.log"/>
</web-site>
上面的配置我配置了一个我们自己的工程 代理商平台 (pgagentweb)下面的配置也以代理商平台的设置为准。
Server.xml 文件的设置
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE application-server PUBLIC "Orion Application Server Config" "http://xmlns.oracle.com/ias/dtds/application-server-9_04.dtd">
<application-server application-directory="../applications" deployment-directory="../application-deployments" connector-directory="../connectors">
<rmi-config path="./rmi.xml"/>
<!-- JMS-server config link, uncomment to activate the JMS service -->
<jms-config path="./jms.xml"/>
<j2ee-logging-config path="./j2ee-logging.xml" />
<log>
<file path="../log/server.log"/>
</log>
<global-application name="default" path="application.xml"/>
<global-web-app-config path="global-web-application.xml"/>
<web-site path="./http-web-site.xml"/>
<web-site path="./secure-web-site.xml"/>
</application-server>
Application.xml 文件设置
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE orion-application PUBLIC "-//Evermind//DTD J2EE Application runtime 1.2//EN" "http://xmlns.oracle.com/ias/dtds/orion-application-9_04.dtd">
<!-- The global application config that is the parent of all the other
applications in this server. -->
<orion-application autocreate-tables="true" default-data-source="jdbc/OracleDS">
<web-module id="defaultWebApp" path="../../home/default-web-app"/>
<web-module id="dms0" path="../../home/applications/dms0.war"/>
<web-module id="pgagentweb" path="../../home/applications/pgagentweb.war"/>
<commit-coordinator>
<commit-class class="com.evermind.server.OracleTwoPhaseCommitDriver"/>
<property name="datasource" value="jdbc/OracleDS"/>
<!-- Username and password are the optional properties
replace with your commit_co-ordinator_super_user
<property name="username"
value="system" />
<property name="password"
value="->pwForSystem" />
-->
</commit-coordinator>
<persistence path="../persistence"/>
<!-- Path to the libraries that are installed on this server.
These will accesible for the servlets, EJBs etc -->
<library path="../applib"/>
<library path="../../../sqlj/lib"/>
<library path="../../../lib/xsu12.jar"/>
<library path="../../../lib/dsv2.jar"/>
<!-- Path to the taglib directory that is shared
among different applications. -->
<library path="../jsp/lib/taglib"/>
<!-- Comment out the jazn element to use principals.
When both jazn and principals are present jazn is used -->
<principals path="./principals.xml"/>
<log>
<file path="../log/global-application.log"/>
</log>
<jazn provider="XML" location="./jazn-data.xml"/>
<data-sources path="data-sources.xml"/>
<connectors path="./oc4j-connectors.xml"/>
<namespace-access>
<read-access>
<namespace-resource root="">
<security-role-mapping>
<group name="administrators"/>
</security-role-mapping>
</namespace-resource>
</read-access>
<write-access>
<namespace-resource root="">
<security-role-mapping>
<group name="administrators"/>
</security-role-mapping>
</namespace-resource>
</write-access>
</namespace-access>
</orion-application>
以上文件配置好以后 重起OC4J 。OC4J现在就可以监听所有的https 请求(port 4443)和非 https请求(port 8888)了。在我配置的代理商平台的例子里面可以通过下面的地址访问应用了。
http://localhost:8888/pgagentweb/
https://localhost:4443/pgagentweb/