国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
CAS及客戶端Acegi的安裝配置指南
作者:龍智 (Dragon)
時間:2006-07-09
         CASCentral Authentication Service)是耶魯大學(xué)開發(fā)的一個開源的SSOsingle sign on,單點登錄)系統(tǒng)。它提供了豐富的客戶端庫,如Java, .NET, PHP, Perl等版本,使用這些庫用戶可以方便地給自己的應(yīng)用程序加上CAS支持。Acegi security system for SpringSpring的一個子項目,它為Java EE開發(fā)者提供了一個易于使用的提供認證和授權(quán)服務(wù)的安全框架。Acegi支持CAS,也可看作是CAS的一個Java版的Client
    以下詳細介紹如何配置CAS以及應(yīng)用程序,使其利用AcegiCAS進行用戶的登錄和認證。我將以acegi-security-1.0.1發(fā)布包中附帶的acegi-security-sample-tutorial應(yīng)用為例,它使用DaoAuthenticationProvider對用戶進行認證,用戶賬號和權(quán)限信息保存在一個properties文件中,我將對其進行改造,改造之后,acegi-security-sample-tutorial使用CAS進行用戶認證,授權(quán)信息仍從該properties文件讀取,因為CAS只負責(zé)認證,不負責(zé)授權(quán),所以授權(quán)工作交由客戶端Acegi來完成,CAS的用戶源配置為數(shù)據(jù)庫,利用JDBC進行讀取。本文需要讀者對SSOAcegi有一定的了解。

       一.準(zhǔn)備工作

   二.安裝CAS

   解壓縮cas-server-3.0.5-rc2.zip,拷貝target目錄中的cas.war%CATALINA_HOME%/webapps下即可。運行Tomcat,訪問http://localhost:8080/cas應(yīng)可看到CAS登錄界面。
        

       三.配置Tomcat支持SSL

       由于CAS要求使用https和客戶端進行通信,所以需要配置Tomcat支持SSL,首先介紹如何制作自簽名證書以及將其導(dǎo)入到證書庫。
1. keytool -keystore keystore -alias acegisecurity -genkey -keyalg RSA -validity 9999 -storepass password -keypass password
What is your first and last name?
  [Unknown]:  localhost
其他隨便填寫即可。
2. keytool -export -v -rfc -alias acegisecurity -file acegisecurity.txt -keystore keystore -storepass password
3. copy acegisecurity.txt %JAVA_HOME%\jre\lib\security  
4. copy keystore %CATALINA_HOME %
5. cd %JAVA_HOME%\jre\lib\security
6. keytool -import -v -file acegisecurity.txt -keypass password -keystore cacerts -storepass changeit -alias acegisecurity
       接下來,用編輯器打開%CATALINA_HOME%/conf/server.xml,找到
    <Connector port="8443" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" disableUploadTimeout="true"
               acceptCount="100" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
       這一行默認是被注釋掉的,取消注釋,并加入keystoreFile="keystore" keystorePass="password"這兩個屬性,注意keystoreFile屬性可以使用keystore文件的絕對路徑,也可使用基于%CATALINA_HOME%環(huán)境變量的相對路徑,keystorePass是訪問keystore的密碼,應(yīng)和上面制作證書時設(shè)定的密碼保持一致。
       訪問https://localhost:8443,應(yīng)彈出一個對話框,告知用戶正要訪問的站點的證書不安全,是否接受,確認接受,應(yīng)可看到那只熟悉可愛的小貓。

   四.改造acegi-security-sample-tutorial

       解壓縮acegi-security-1.0.1.zip,拷貝acegi-security-sample-tutorial.war%CATALINA_HOME%/webapps目錄下,重啟tomcatacegi-security-sample-tutorial即已發(fā)布?,F(xiàn)在我們將其改造為使用CAS進行用戶的登錄和認證。
    用編輯器打開WEB-INF/applicationContext-acegi-security.xml,找到
       <bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
                  <property name="authenticationManager" ref="authenticationManager"/>
                  <property name="authenticationFailureUrl" value="/acegilogin.jsp?login_error=1"/>
              <property name="defaultTargetUrl" value="/"/>
              <property name="filterProcessesUrl" value="/j_acegi_security_check"/>
              <property name="rememberMeServices" ref="rememberMeServices"/>
       </bean>
將其替換為:
       <bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.cas.CasProcessingFilter">
              <property name="authenticationManager" ref="authenticationManager"/>
              <property name="authenticationFailureUrl" value="/acegilogin.jsp?login_error=1"/>
              <property name="defaultTargetUrl" value="/"/>
              <property name="filterProcessesUrl" value="/j_acegi_cas_security_check"/>
              <property name="rememberMeServices" ref="rememberMeServices"/>
       </bean>
其中,authenticationFailureUrl是認證失敗時顯示的頁面,acegi-security-sample-tutorial登錄失敗時會在登錄頁(acegilogin.jsp)顯示失敗原因,現(xiàn)改為使用CAS之后,acegi-security-sample-tutorial使用CAS的登錄頁面,故acegilogin.jsp可去掉。接下來,找到
              <bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
                     <property name="loginFormUrl" value="/acegilogin.jsp"/>
                     <property name="forceHttps" value="false"/>
              </bean>
替換為:
              <bean class="org.acegisecurity.ui.cas.CasProcessingFilterEntryPoint">
                     <property name="loginUrl">
                            <value>https://localhost:8443/cas/login</value>
                     </property>
                     <property name="serviceProperties">
                            <ref bean="serviceProperties"/>
                     </property>
              </bean>
再接下來,找到
       <bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
              <property name="providers">
                     <list>
                            <ref local="daoAuthenticationProvider"/>
                            <bean class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
                                   <property name="key" value="changeThis"/>
                            </bean>
                            <bean class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider">
                                   <property name="key" value="changeThis"/>
                            </bean>
                     </list>
              </property>
       </bean>
<ref local="daoAuthenticationProvider"/>修改為<ref local="casAuthenticationProvider"/>,并添加以下bean
       <bean id="casAuthenticationProvider" class="org.acegisecurity.providers.cas.CasAuthenticationProvider">
              <property name="ticketValidator">
                     <ref bean="ticketValidator"/>
              </property>
              <property name="casProxyDecider">
                     <ref bean="casProxyDecider"/>
              </property>
              <property name="statelessTicketCache">
                     <ref bean="statelessTicketCache"/>
              </property>
              <property name="casAuthoritiesPopulator">
                     <ref bean="casAuthritiesPopulator"/>
              </property>
              <property name="key">
                     <value>some_unique_key</value>
              </property>
       </bean>
    
       <bean id="ticketValidator" class="org.acegisecurity.providers.cas.ticketvalidator.CasProxyTicketValidator">
              <property name="casValidate">
                     <value>https://localhost:8443/cas/proxyValidate</value>
              </property>
              <property name="serviceProperties">
                     <ref bean="serviceProperties"/>
              </property>
       </bean>
    
       <bean id="serviceProperties" class="org.acegisecurity.ui.cas.ServiceProperties">
              <property name="service">
                     <value>https://localhost:8443/acegi-security-sample-tutorial/j_acegi_cas_security_check</value>
              </property>  
       </bean>
    
       <bean id="casProxyDecider" class="org.acegisecurity.providers.cas.proxy.RejectProxyTickets"/>
    
       <bean id="statelessTicketCache" class="org.acegisecurity.providers.cas.cache.EhCacheBasedTicketCache">
              <property name="cache">
                     <bean class="org.springframework.cache.ehcache.EhCacheFactoryBean">
                            <property name="cacheManager">
                                   <bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>
                            </property>
                            <property name="cacheName" value="userCache"/>
                     </bean>
              </property>
       </bean>
    
       <bean id="casAuthritiesPopulator" class="org.acegisecurity.providers.cas.populator.DaoCasAuthoritiesPopulator">
              <property name="userDetailsService">
                     <ref bean="userDetailsService"/>
              </property>
       </bean>
改造完畢!
 

    五.配置CAS使用JDBC數(shù)據(jù)源進行用戶認證

       CAS默認設(shè)置為只要用戶名和密碼相同,即可進行登錄,這在現(xiàn)實使用中是不允許的。我們修改為使用MySQLtest數(shù)據(jù)庫中的app_user表作為用戶數(shù)據(jù)源。首先,我們在test庫中創(chuàng)建一個表:
CREATE TABLE `app_user` (
  `username` varchar(30) NOT NULL default ‘‘,
  `password` varchar(45) NOT NULL default ‘‘,
  PRIMARY KEY  (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
并添加如下用戶:
INSERT INTO `app_user` (`username`,`password`) VALUES
 (‘dianne‘,‘emu‘),
 (‘marissa‘,‘koala‘),
 (‘peter‘,‘opal‘),
 (‘scott‘,‘wombat‘);
用編輯器打開%CATALINA_HOME%/webapps/cas/WEB-INF/deployerConfigContext.xml,找到
    <bean class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />
注釋掉該行,在其下加入:
<bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
                            <property name="sql" value="select password from app_user where username=?" />
                            <property name="dataSource" ref="dataSource" />
                     </bean>
并添加一個bean
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
       <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
       <property name="url"><value>jdbc:mysql://localhost:3306/test</value></property>
       <property name="username"><value>test</value></property>
       <property name="password"><value>test</value></property>
    </bean>
拷貝cas-server-jdbc-3.0.5-rc2.jarmysql-connector-java-3.1.12-bin.jar%CATALINA_HOME%/webapps/cas/WEB-INF/lib下。
 
    重新啟動tomcat,在瀏覽器中輸入http://localhost:8080/acegi-security-sample-tutorial,你會發(fā)現(xiàn),一旦你訪問了受保護的頁面,請求就會被重定向到CAS的登錄頁面,登錄成功之后請求會被再被定向到最初訪問的頁面,如果有多個系統(tǒng),在這些系統(tǒng)之間進行切換將不會要求用戶重新登錄,這就達到了單點登錄的目的.

 

參考文獻:

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
用Acegi為你的Spring應(yīng)用加把鎖!
Acegi安全系統(tǒng)的配置(轉(zhuǎn)) - Junky‘s IT Notebook - BlogJ...
WIKI IREMIA: DWRandAcegi
Spring Acegi Tutorial
理解基于Acegi的權(quán)限控制系統(tǒng)(圖)
Acegi ACL使用說明
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服