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.xml和deployerConfigContext.xml!
我們需要做點什麼?Nothing!即使我們不對這個系統進行任何改動,它仍舊可以運行!
輸入用戶名、密碼試試登錄試試?!不知道用戶名?!沒關係,就用最常用的admin:admin(用戶名:密碼)登錄試試!
點擊登錄,看結果!
成功!!! 難道真的內置了這樣的用戶,正好被我蒙對了?!我可沒有那麼神奇!!!
再來個admin:manage試試!!!
注意控制檯日誌!
登錄成功:
登錄失敗:
這個SimpleTestUsernamePasswordAuthenticationHandler.java默認實現了用戶名與密碼一致時,成功登錄!
看看SimpleTestUsernamePasswordAuthenticationHandler.java的源代碼就明白了!
- public final class SimpleTestUsernamePasswordAuthenticationHandler extends
- AbstractUsernamePasswordAuthenticationHandler {
- public SimpleTestUsernamePasswordAuthenticationHandler() {
- log
- .warn(this.getClass().getName()
- + " is only to be used in a testing environment. NEVER enable this in a production environment.");
- }
- public boolean authenticateUsernamePasswordInternal(final UsernamePasswordCredentials credentials) {
- final String username = credentials.getUsername();
- final String password = credentials.getPassword();
- if (StringUtils.hasText(username) && StringUtils.hasText(password)
- && username.equals(getPasswordEncoder().encode(password))) {
- log.debug("User [" + username + "] was successfully authenticated.");
- return true;
- }
- log.debug("User [" + username + "] failed authentication");
- return false;
- }
- }
這裏
- StringUtils.hasText(username) && StringUtils.hasText(password)
- && username.equals(getPasswordEncoder().encode(password))
就是關鍵! 這個類是用於演示的!
打開deployerConfigContext.xml
- <!--
- | This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS
- | into production. The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials
- | where the username equals the password. You will need to replace this with an AuthenticationHandler that implements your
- | local authentication strategy. You might accomplish this by coding a new such handler and declaring
- | edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules.
- +-->
- <bean
- 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