`
sg552
  • 浏览: 611958 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
47437293-94b9-3b04-9152-8971c7580049
白手起家学习使用Flex
浏览量:18393
社区版块
存档分类
最新评论

白手起家搭建CAS

阅读更多


1. 下载,安装。 cas server   (http://www.jasig.org/cas/download )
解压缩后,看到以下文件:

focusbeijing@focusbeijing-desktop:/sg552/cas-server-3.4.11$ ls
assembly.xml                       cas-server-support-radius
cas.log                            cas-server-support-spnego
cas-server-core                    cas-server-support-trusted
cas-server-documentation           cas-server-support-x509
cas-server-integration-berkeleydb  cas-server-uber-webapp
cas-server-integration-jboss       cas-server-webapp
cas-server-integration-memcached   INSTALL.txt
cas-server-integration-restlet     license.txt
cas-server-support-generic         modules
cas-server-support-jdbc            notice.txt
cas-server-support-ldap            perfStats.log
cas-server-support-legacy          pom.xml
cas-server-support-openid          tasks.xml


2. 下载tomcat6,  (保证你安装了JDK6+)解压缩:

focusbeijing@focusbeijing-desktop:/sg552/tomcat6$ ls
bin      conf  LICENSE  NOTICE         RELEASE-NOTES  temp     work
cas.log  lib   logs     perfStats.log  RUNNING.txt    webapps


3. 设置JDK_HOME,  CATALINA_HOME 系统变量: 
export CATALINA_HOME=/sg552/tomcat6

4. 1. copy modules/cas-server-webapp- VERSION.war to Tomcat's webapps/ directory, 
then  start Tomcat by : 
$CATALINA_HOME/bin/startup.sh

focusbeijing@focusbeijing-desktop:/sg552/tomcat6$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE:   /sg552/tomcat6
Using CATALINA_HOME:   /sg552/tomcat6
Using CATALINA_TMPDIR: /sg552/tomcat6/temp
Using JRE_HOME:        /usr/lib/jvm/java-6-openjdk
Using CLASSPATH:       /sg552/tomcat6/bin/bootstrap.jar


5. 访问: 
http://localhost:8080/cas-server-webapp-3.4.11/login  
就可以看到登录页面了。

https://wiki.jasig.org/display/CASUM/JDBC
使用JDBC认证:  https://wiki.jasig.org/display/CASUM/JDBC




6, CAS 支持的9种方式: 

Active Directory: 是面向Windows Standard Server、Windows Enterprise Server以及 Windows Datacenter Server的目录服务。
Generic: 通用醒
JAAS: java 自带的一种东东。
JDBC:  连接到数据库。
LDAP: LDAP协议。用于验证。
Legacy: 未知。。。
RADIUS:远程认证拨号用户系统。
SPNEGO:  SPNEGO(SPNEGO: Simple and Protected GSS-API Negotiation)是微软提供的一种一种使用GSS- API认证机制的安全协议, 用于使Webserver共享Windows Credentials,它扩展了 Kerberos ( 一种网络认证协议)。

Trusted:   不清楚。。。
X.509 Certificates
  X.509被广泛使用的数字证书标准,是由国际电联电信委员会( ITU-T)为单点登录(SSO-Single Sign-on)和授权管理基础设施(PMI- Privilege Management Infrastructure)制定的PKI标准。X. 509定义了(但不仅限于) 公钥证书 、证书吊销清单、 属性证书和证书路径验证算法等证书标准。



7.  开始使用JDBC 进行CAS的认证。

根据CAS INSTALL.TXT 文件的说明:

 access the CAS login page by opening up a web browser and visiting:

 36     http://hostname:8080/cas-server-webapp-VERSION/login   (see note below)
 37 
 38    You should see the CAS login page asking you for your username and
 39    password.  The default authentication plugin accepts NetID=password.
 40    Enter in an identical value for NetID and password and click LOGIN.
 41    If everything is set up correctly, you should see a page stating that
 42    you've successfully logged into CAS.  Congratulations!


这里的NETID 应该就是用户名。 
这个用户名在哪里呢?应该就需要我们先配置JDBC数据库, 然后再把它加进去。

需要用 POM。XML ,来进行MVN生成一个新的APP。。。手动的方式不行, 会产生找不到 generic 验证的错误。

https://wiki.jasig.org/display/CASUM/Best+Practice+-+Setting+Up+CAS+Locally+using+the+Maven2+WAR+Overlay+Method


8.  需要安装 mvn package install   (也可以直接在 module下找到对应的东西)

https://wiki.jasig.org/display/CASUM/Building+and+Deploying

As of CAS 3.1, CAS builds exclusively with the Maven 2 Build Management System. This system provides a common build and directory structure across all projects that use Maven 2 and defines common goals that can be applied to any project type (JAR, WAR, EAR, etc.).

Building CAS

In your CAS_HOME, you can type "mvn package install". This will create all of the jar and war files for the CAS modules. Alternatively, you can enter any of the CAS_HOME/{module} sub directories and execute "mvn package install" to generate just that particular JAR or WAR.

As compilation requires a network connection, if you are behind a http proxy, you have to indicate some extra option to mvn command: "mvn -Dhttp.proxyHost=xxx -Dhttp.proxyPort=xxx package install"



https://wiki.jasig.org/display/CAS/Examples+to+Configure+CAS


对于默认的CAS应用, 使用的是:最简单的验证( SimpleTestUsernamePasswordAuth enticationHandler)。 只要用户输入的用户名和密码相同就可以了。 

见  WEB-INF/deployerConfigContext. xml


分别建立两个 app: 


miaomiaocat:   http://192.168.56.10:332/cats

同时记得下载 ruby cas client (http://code.google.com/p/rubycas-client/

TODO:  编译CAS SERVER  ( $mvn package install ) 

 




下载了。 

$ mvn install  可以。
$ sudo mvn install 不行
$ sudo mvn package install 不行。

不过,话说可以直接在module目录下找到对应的 cas-server-support-jdbc-3.4.11.jar





继续使用 simpleauthenticationhandler.  (用户名和密码一样)

把CAS服务器先跑起来。

然后把 cas-client加在第一个RAILS APP上。 dudufish

0. 在  Gemfile中,加入:

gem 'rubycas-client'
然后 $sudo bundle 


1. environment.rb: 的结尾,加上:
CASClient::Frameworks::Rails::Filter.configure(
  :cas_base_url => "http://192.168.56.10:8080/cas-server-webapp-3.4.11 "
)

2. application_controller.rb
before_filter CASClient::Frameworks::Rails::Filter

3. 进入某个controller :  (例如 fish_controller.rb) , 定义退出的action
def class fish_controller
  def logout
     CASClient::Frameworks::Rails::Filter.logout(self)
  end
end

4. 修改 route.rb ,加入退出的链接:
 Dudufish::Application.routes.draw do
   resources :fish
   match '/logout' => "fish#logout", :as => :logout
end 

5. 修改  application.html.erb 布局文件,增加这个链接。  关键的一点是: 在经典的rails authorization 框架用,都是用 current_user  这个变量取得当前登陆的用户。 在CAS CLIENT中,用的是 session[:cas_user] , 只取得当前用户名,是一个string.  而不是一个model. 

<div style="border: 1px solid green">
  <%= session[:cas_user] %>
</div>
<% if session[:cas_user] %>
   <%= link_to "logout" , logout_path %>
<% end %>

6. 下面,就是演示的截图:

1. 首先,输入:  dudufish这个项目的url:  

2. 回车后,页面会自动跳转到 CAS login 页面。 (见 application_controller.rb中的 before_filter) 



3. 我们输入 用户名和密码都是 Siwei  , 回车,就会看到dudufish的页面。



4.  我们点击 "logout" 链接,就会触发logout action  ( 

     CASClient::Frameworks::Rails::Filter.logout(self)
 ) 





  • 大小: 38.1 KB
  • 大小: 10.3 KB
  • 大小: 19.1 KB
分享到:
评论
1 楼 jieke456 2012-02-28  
  学习单点登录入门 谢谢了

相关推荐

Global site tag (gtag.js) - Google Analytics