CAS

CAS (中央认证服务)

CAS是Central Authentication Service的缩写,中央认证服务,一种独立开放指令协议。CAS 是 Yale 大学发起的一个开源项目,旨在为 Web 应用系统提供一种可靠的单点登录方法,CAS 在 2004 年 12 月正式成为 JA-SIG 的一个项目。

特点

1、开源的企业级单点登录解决方案。
2、CAS Server 为需要独立部署的 Web 应用。
3、CAS Client 支持非常多的客户端(这里指单点登录系统中的各个 Web 应用),包括 Java, .Net, PHP, Perl, Apache, uPortal, Ruby 等。
4、CAS属于Apache 2.0许可证,允许代码修改,再发布(作为开源或商业软件)。

CAS是什么?

CAS使用一个中央认证的服务
中央认证呢? 简单的说 多个不同的系统可以使用他同一个认证中心、这个认证中心就称为中央认证中心
说白了 CAS就是为了完成单点登陆的框架
单点登陆:多个不同的子系统可以使用同一个认证中心-----单点登陆

百度的所有产品使用了一个登陆系统
千锋的后台的管理系统

前端:有会员登陆
后台有管理员登陆

CAS能干什么?

CAS简单的说,可以实现多个不同的系统的统一的认证
CAS就是SSO的一个框架而已

CAS的部署

1:在官网去下载个源码 然后进行打包
2:将打包好的war文件放到 tomcat的webapp目录下去
3:启动tomcat
4:访问地址 http://localhost:8888/cas 如果跳转到了登陆的页面那么说明cas就安装成功了
5:输入用户名:casuser 密码:Mellon 如果能够正常的认证成功那么 说明你安装的系统就没有任何问题了

单点登陆的配置

   1>:去网上下载CAS的源码

   2>:将这个源码打包成一个war包  源码先创建成MAVEN工程  ---->maven install

   3>:准备Tomcat的配置

   4>:将webapps目录下所有文件清空

   5>:将war文件放进去

   6>;启动Tomcat

   7>:测试:127.0.0.1:8888/cas/login  出现登陆页面  

      默认的用户名:casuser

      默认的密码:Mellon


    8>:登陆页面要更改成中文
    
      在webapp/cas/WEB-INF/cas.properties文件中添加如下内容

      locale.default=zh_CN


    9>:删除页面的数据  添加自己的登陆页面


          修改页面的话  修改的地方

          G:\CAS Tomcat\apache-tomcat-7.0.84\webapps\cas\WEB-INF\view\jsp\default\ui\casLogoutView  更改中间的那一部分

          G:\CAS Tomcat\apache-tomcat-7.0.84\webapps\cas\WEB-INF\view\jsp\default\ui\includes\top.jsp  修改顶部

          G:\CAS Tomcat\apache-tomcat-7.0.84\webapps\cas\WEB-INF\view\jsp\default\ui\includes\bottom.jsp 修改的尾部

3>:SpringBoot整合CAS实现单点登陆

1>:创建MAVEN工程

         <!--导入cas的包-->
        <dependency>
          <groupId>net.unicon.cas</groupId>
          <artifactId>cas-client-autoconfig-support</artifactId>
          <version>1.4.0-GA</version>
        </dependency>


                 2>:编写application.properties文件

                  ## CAS 配置
                  cas.validation-type = CAS
                  cas.server-url-prefix = http://127.0.0.1:8888/cas         //配置的是cas服务器的前缀
                  cas.server-login-url = http://127.0.0.1:8888/cas/login    //这个配置的是 cas登陆的页面
                  cas-server-logout-url = http://127.0.0.1:8888/cas/logout  //配置的是cas的退出功能的路径
                  cas.client-host-url = http://localhost:8080               //当前SpringBoot程序的主机和端口


                 3>:准备首页的URL地址

                    在工程的template 目录下创建一个html文件  


                          xbb.html


                 4>:编写Controll来接受前端的请求

  @Controller
 public class UserControll {


@RequestMapping("/xiaobobo")
public String list(){

    System.out.println("我是控制器我执行了....");

    return "xbb";
}
@RequestMapping("/bobo")
public String bobo(){

    System.out.println("我是控制器波波我执行了....");

    return "bb";
}

}

                  5>:配置apache-tomcat-7.0.84\webapps\cas\WEB-INF目录下的                                 deployerConfigContext.xml文件  详情见配置

                  6>:配置cas.properties文件
                       cas.jdbc.authn.query.sql=select password from t_user where userName=?

                      #将下面的用户名和密码直接给注释
                       #accept.authn.users=casuser::Mellon

                  7>:让当前环境支持HTTP

                        G:\CAS Tomcat\apache-tomcat-7.0.84\webapps\cas\WEB-INF\classes\services\HTTPSandIMAPS-10000001.json文件
                        "@class" : "org.jasig.cas.services.RegexRegisteredService",

“serviceId” : “^(https|imaps|http) : //.*”,注意删除空格

                 8:导包

                 9:在SpringBoot上的启动文件上  添加如下的注解
                 @EnableCasClient

                 10:测试


                    

                deployeeConfigContext.xml


                   <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:c="http://www.springframework.org/schema/c"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:sec="http://www.springframework.org/schema/security"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
   http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

 <util:map id="authenticationHandlersResolvers">
    <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
    <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
</util:map>

<util:list id="authenticationMetadataPopulators">
    <ref bean="successfulHandlerMetaDataPopulator" />
    <ref bean="rememberMeAuthenticationMetaDataPopulator" />
</util:list>

<bean id="attributeRepository" class="org.jasig.services.persondir.support.NamedStubPersonAttributeDao"
      p:backingMap-ref="attrRepoBackingMap" />

<!-- <alias name="acceptUsersAuthenticationHandler" alias="primaryAuthenticationHandler" /> -->
<alias name="personDirectoryPrincipalResolver" alias="primaryPrincipalResolver" />

<!--begin  从数据库中的用户表中密码读取出来出来之后要进行散列 -->
<bean id="MD5PasswordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder" autowire="byName">    
	<constructor-arg value="MD5"/>
</bean>

 <bean id = "queryDatabaseAuthenticationHandler" name="primaryAuthenticationHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">	
	<property name="passwordEncoder" ref="MD5PasswordEncoder"/> 
</bean>

<alias name="dataSource" alias="queryDatabaseDataSource" />
<bean id="dataSource"
  class="com.mchange.v2.c3p0.ComboPooledDataSource"
  p:driverClass="com.mysql.jdbc.Driver"
  p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/casdb"
  p:user="root"
  p:password="root"
  p:initialPoolSize="6"
  p:minPoolSize="6"
  p:maxPoolSize="18"
  p:maxIdleTimeExcessConnections="120"
  p:checkoutTimeout="10000"
  p:acquireIncrement="6"
  p:acquireRetryAttempts="5"
  p:acquireRetryDelay="2000"
  p:idleConnectionTestPeriod="30"
  p:preferredTestQuery="select 1" />
<!--end  从数据库中的用户表中读取 -->

<util:map id="attrRepoBackingMap">
    <entry key="uid" value="uid" />
    <entry key="eduPersonAffiliation" value="eduPersonAffiliation" />
    <entry key="groupMembership" value="groupMembership" />
    <entry>
        <key><value>memberOf</value></key>
        <list>
            <value>faculty</value>
            <value>staff</value>
            <value>org</value>
        </list>
    </entry>
</util:map>

<alias name="serviceThemeResolver" alias="themeResolver" />

<alias name="jsonServiceRegistryDao" alias="serviceRegistryDao" />

<alias name="defaultTicketRegistry" alias="ticketRegistry" />

<alias name="ticketGrantingTicketExpirationPolicy" alias="grantingTicketExpirationPolicy" />
<alias name="multiTimeUseOrTimeoutExpirationPolicy" alias="serviceTicketExpirationPolicy" />

<alias name="anyAuthenticationPolicy" alias="authenticationPolicy" />
<alias name="acceptAnyAuthenticationPolicyFactory" alias="authenticationPolicyFactory" />

<bean id="auditTrailManager"
      class="org.jasig.inspektr.audit.support.Slf4jLoggingAuditTrailManager"
      p:entrySeparator="${cas.audit.singleline.separator:|}"
      p:useSingleLine="${cas.audit.singleline:false}"/>

<alias name="neverThrottle" alias="authenticationThrottle" />

<util:list id="monitorsList">
    <ref bean="memoryMonitor" />
    <ref bean="sessionMonitor" />
</util:list>

<alias name="defaultPrincipalFactory" alias="principalFactory" />
<alias name="defaultAuthenticationTransactionManager" alias="authenticationTransactionManager" />
<alias name="defaultPrincipalElectionStrategy" alias="principalElectionStrategy" />
<alias name="tgcCipherExecutor" alias="defaultCookieCipherExecutor" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值