隨筆-10  評論-0  文章-1  trackbacks-0

          一,先修改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" class="org.acegisecurity.ui.ExceptionTranslationFilter">
                  <property name="authenticationEntryPoint">
                      <bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
                          <property name="loginFormUrl" 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" class="org.acegisecurity.securechannel.ChannelProcessingFilter">
                  <property name="channelDecisionManager" 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訪問了。 閱讀全文
          類別:j2ee編程 查看評論
          文章來源:http://hi.baidu.com/ninky/blog/item/6b7d22ddd55045d08c10291c.html
          posted on 2009-11-13 11:38 niuky 閱讀(284) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 长宁区| 崇阳县| 建水县| 禄劝| 怀柔区| 曲水县| 蓬溪县| 河间市| 抚顺市| 阳新县| 江川县| 扶风县| 永靖县| 古浪县| 于田县| 呼和浩特市| 新竹县| 阿勒泰市| 公主岭市| 宜丰县| 土默特左旗| 贺兰县| 德阳市| 民权县| 通城县| 娄烦县| 尼玛县| 普陀区| 卓尼县| 泰顺县| 仁怀市| 大城县| 桂林市| 佛坪县| 枣强县| 龙门县| 青海省| 威宁| 禹州市| 扶沟县| 林州市|