因为tomcat 6.0.35中默认使用了Apr Connector,所以在配置ssl的时候需要指定jssl的Connector,可选的jssl连接器有
org.apache.coyote.http11.Http11Protocol和org.apache.coyote.http11.Http11NioProtocol,顾名思义,一个是阻塞的,一个是不阻塞的。
要覆盖默认的Apr,必须指定这两个connector中的一个
<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="8443" minSpareThreads="5" maxSpareThreads="75" enableLookups="true" disableUploadTimeout="true" acceptCount="100" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" clientAuth="false" sslProtocol="TLS" keystoreFile="d:\server.key" keystorePass="admins"/>
server.key可以用jdk自带的工具生成,下面是apache网站上面的方法Windows:
%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA \ -keystore \path\to\my\keystoreUnix:
我在生成key文件的时候发现,其中填写的keystore密码和tomcat主密码必须相同,否则启动tomcat的时候会报错 如下
$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA \ -keystore /path/to/my/keystore java.security.UnrecoverableKeyException: Cannot recover key
有待高人指点。-----------------------------------------------------------------------------------------------如果要在使用Apr Connector的同时配置SSL,会麻烦一点。首先下载openssl,将openssl的bin目录配置到环境变量,然后生成私钥,生成证书。生成私钥:openssl genrsa -out rsa-private-key.pem 1024
生成证书:openssl req -new -x509 -nodes -sha1 -days 365 -key rsa-private-key.pem -out self-signed-cert.pem
然后在tomcat的server.xml中配置Connector:<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLSv1" SSLCertificateKeyFile="d:\zqiangliu\ca-key.perm" SSLCertificateFile="d:\zqiangliu\self-signed-cert.perm"/>
--------------------------------------------------------------------------------------------------------------------完成后启动tomcat,访问https://localhost:8443会提示安装证书。访问spring security中配置的https资源也会自动转发到8443安全连接端口<security:intercept-url pattern="/jsp/admin/**" requires-channel="https" access="hasRole('ROLE_ADMIN')"/>当然如果你连接到其他资源后,如果你没有指定requires-channel="http",会继续以https方式访问<security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" requires-channel="http"/>
点 任然继续