`

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的源代码就明白了!
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

  • 大小: 97.1 KB
  • 大小: 131.5 KB
  • 大小: 162.5 KB
  • 大小: 72 KB
  • 大小: 33.1 KB
  • 大小: 83.8 KB
  • 大小: 13.9 KB
  • 大小: 63 KB
  • 大小: 38.3 KB
  • 大小: 38.3 KB
  • 大小: 39.6 KB
11
0
分享到:
评论
1 楼 xiaoxin5230 2010-08-11  
通过图形化的文字浅显易懂。。。。

相关推荐

Global site tag (gtag.js) - Google Analytics