配置tomcat ,结合acegi security 实现SSL
一,先修改TOMCAT的配置文件server.xml ,在其中找到以下内容:
?<!-- Define a SSL HTTP/1.1 Connector on port 443 -->
<!--
??? <Connector port="443" maxHttpHeaderSize="8192"
?????????????? maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
?????????????? enableLookups="false" disableUploadTimeout="true"
?????????????? acceptCount="100" scheme="https" secure="true"
?????????????? clientAuth="false" sslProtocol="TLS" />
-->
??? 去掉注释。
二,到你的JDK的bin目录下,执行下面代码:
%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA? (Unix)
//TOMCAT的初始密码为changit,如果你在生成KEY时修改了密码,则必须在server.xml中的Connector="443"中加上这个属性: keystorePass="你修改的密码"。
此时,启动TOMCAT,就可以访问https://localhost:443
三,在acegi Security中实现SSL,只须修改起配置文件(如:security.xml,一般为这个,或者是其他文件名)中的
<bean id="exceptionTranslationFilter" value="/public/requireLogin.jsp"/>
??????????????? <!--<property name="forceHttps" value="false"/>? -->
??????????????? <!-- in order to enable the https -->
??????????????? <property name="forceHttps" value="true"/>
????????????????
??????????? </bean>
??????? </property>
??? </bean>
//把其中的forceHttps的值改为true,这样就可以对那些需要安全访问的页面自动转为https://形式的URL。
接着,再修改:
?<bean id="channelProcessingFilter" ref="channelDecisionManager"/>
??????? <property name="filterInvocationDefinitionSource">
??????????? <value>
??????????????? PATTERN_TYPE_APACHE_ANT
??????????????? /admin/**=REQUIRES_SECURE_CHANNEL
??????????????? /login*=REQUIRES_SECURE_CHANNEL
??????????????? /j_security_check*=REQUIRES_SECURE_CHANNEL
??????????????? /editProfile.html*=REQUIRES_SECURE_CHANNEL
??????????????? /signup.html*=REQUIRES_SECURE_CHANNEL
??????????????? /saveUser.html*=REQUIRES_SECURE_CHANNEL
??????????????? /secure/**=REQUIRES_SECURE_CHANNEL???????????
??????????????? /**=REQUIRES_INSECURE_CHANNEL???
??????????? </value>
??????? </propert
//在其中加入你想要实现安全访问的页面的URL,/**这个一定要放在最后面。REQUIRES_SECURE_CHANNEL这个表示需要安全通道,REQUIRES_INSECURE_CHANNEL? 这个表示不需要。
最后,再修改web.xml,在其中添加如下的过滤器:
<!-- in order to enable the ssl http -->
??? <filter>
???? ??? <filter-name>Acegi Channel Processing Filter</filter-name>???
???? ??? <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
???? ??? <init-param>
?????? ??? ??? <param-name>targetClass</param-name>
?????? ??? ??? <param-value>org.acegisecurity.securechannel.ChannelProcessingFilter</param-value>
???? ??? </init-param>
?? </filter>
<filter-mapping>
?? ??? ??? <filter-name>Acegi Channel Processing Filter</filter-name>
?? ??? ??? <url-pattern>/*</url-pattern>
???? </filter-mapping>
这样,就可以通过Acegi Security实现SSL访问了。