Jasig CAS使用手札——一、瞭解Jasig CAS,簡單運行!

SSO : 單點登錄(Single Sign On , 簡稱 SSO )
CAS : CAS(Central Authentication Service)是一款不錯的針對 Web 應用的單點登錄框架

有關CAS、SSO的詳細信息我就不在這裏羅嗦了,其實都是很簡單理論,如果日後有時間,補充幾張圖,大家就很明白了~
今天要討論的是瞭解Jasig CAS這個成熟的系統,並讓它能夠運行。當然,如果要讓它正式投入使用,還是需要一點時間的!
首先,下載cas_server當前版本爲3.4.2.1。

然後,我們來了解下這個壓縮包!
打開這個壓縮包,真是物產豐富。

我們先不關注其它內容,單看這個modules,單看modules中的cas-server-webapp-3.4.2.1.war

我們從這裏入手!

把cas-server-webapp-3.4.2.1.war當作是一般的應用就好,我們把它導入eclipse,當作是一個簡單的應用!

這裏衆多的xml令人眼花繚亂,我們不必驚慌,除了web.xml外這裏能起作用的只有cas-servlet.xmldeployerConfigContext.xml!
我們需要做點什麼?Nothing!即使我們不對這個系統進行任何改動,它仍舊可以運行!

輸入用戶名、密碼試試登錄試試?!不知道用戶名?!沒關係,就用最常用的admin:admin(用戶名:密碼)登錄試試!

點擊登錄,看結果!

成功!!! 難道真的內置了這樣的用戶,正好被我蒙對了?!我可沒有那麼神奇!!!
再來個admin:manage試試!!!

注意控制檯日誌!
登錄成功:
引用
2010-08-10 13:04:45,542 INFO [org.jasig.cas.authentication.AuthenticationManagerImpl] - <AuthenticationHandler: org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler successfully authenticated the user which provided the following credentials: [username: admin]>

登錄失敗:
引用
2010-08-10 13:08:38,333 INFO [org.jasig.cas.authentication.AuthenticationManagerImpl] - <AuthenticationHandler: org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler failed to authenticate the user which provided the following credentials: [username: admin]>


這個SimpleTestUsernamePasswordAuthenticationHandler.java默認實現了用戶名與密碼一致時,成功登錄!
看看SimpleTestUsernamePasswordAuthenticationHandler.java的源代碼就明白了!
Java代碼  收藏代碼
  1. public final class SimpleTestUsernamePasswordAuthenticationHandler extends  
  2.     AbstractUsernamePasswordAuthenticationHandler {  
  3.   
  4.     public SimpleTestUsernamePasswordAuthenticationHandler() {  
  5.         log  
  6.             .warn(this.getClass().getName()  
  7.                 + " is only to be used in a testing environment.  NEVER enable this in a production environment.");  
  8.     }  
  9.   
  10.     public boolean authenticateUsernamePasswordInternal(final UsernamePasswordCredentials credentials) {  
  11.         final String username = credentials.getUsername();  
  12.         final String password = credentials.getPassword();  
  13.   
  14.         if (StringUtils.hasText(username) && StringUtils.hasText(password)  
  15.             && username.equals(getPasswordEncoder().encode(password))) {  
  16.             log.debug("User [" + username + "] was successfully authenticated.");  
  17.             return true;  
  18.         }  
  19.   
  20.         log.debug("User [" + username + "] failed authentication");  
  21.   
  22.         return false;  
  23.     }  
  24. }  

這裏
Java代碼  收藏代碼
  1. StringUtils.hasText(username) && StringUtils.hasText(password)  
  2.             && username.equals(getPasswordEncoder().encode(password))  

就是關鍵! 這個類是用於演示的!
打開deployerConfigContext.xml
Xml代碼  收藏代碼
  1. <!--  
  2.     | This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS   
  3.     | into production.  The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials  
  4.     | where the username equals the password.  You will need to replace this with an AuthenticationHandler that implements your  
  5.     | local authentication strategy.  You might accomplish this by coding a new such handler and declaring  
  6.     | edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules.  
  7.     +-->  
  8. <bean  
  9.     class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />  

如果我們想讓他具有真正意義的作用,就需要使用以下這些包:


最常用的莫過於使用JDBC的方式,也就是使用cas-server-support-jdbc-3.4.2.1.jar這個包來完成操作!
今天先到這裏,時間有限,文檔不齊,一時半會吃不透!就不在這裏獻醜了!
參考資料
http://www.ja-sig.org/products/cas/
http://www.ja-sig.org/wiki/display/CASUM/Home
http://static.springframework.org/spring-security/site/index.html
發佈了0 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章