cas的service管理

总结

CAS对提供单点登录的服务采用双向控制。第一,cas client端需要指定提供服务的casServer;第二,casClient提供服务service,需要在casServer中进行注册。

服务管理表

REGISTEREDSERVICEIMPL
在这里插入图片描述
expression_type
cas服务匹配支持2种通配规则:正则(regex)和类正则(ant)。
ant用“**”表示通配符。对应的实现类为:RegexRegisteredServiceRegisteredServiceImpl

补充阅读:ANT通配——https://www.cnblogs.com/cyjch/archive/2012/03/28/2421353.html

服务加载

DefaultServicesManagerImpl.java实现ServiceManager接口:

  1. 用来加载数据库中的服务配置信息,项目启动的时候就会获取完成,配置信息存储在内存中;
  2. 借助quartz任务自动进行更新——从数据库重新读取。private void load() 查询数据库获取授权service信息;
    cas-sevlet.xml:
<!-- 服务加载定时任务 -->
<bean id="serviceRegistryReloaderJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
      p:targetObject-ref="servicesManager"
      p:targetMethod="reload"/>
<!-- 服务加载定时任务:默认延时2分钟 -->
<bean id="periodicServiceRegistryReloaderTrigger" 
class="org.springframework.scheduling.quartz.SimpleTriggerBean"
      p:jobDetail-ref="serviceRegistryReloaderJobDetail"
      p:startDelay="${service.registry.quartz.reloader.startDelay:120000}"     	p:repeatInterval="${service.registry.quartz.reloader.repeatInterval:120000}"/>

ApplicationContext.xml:

<bean id="servicesManager" class="org.jasig.cas.services.DefaultServicesManagerImpl"
    c:serviceRegistryDao-ref="serviceRegistryDao" />

日志信息:

2019-04-30 17:29:54,792 DEBUG [org.quartz.core.JobRunShell] - <Calling execute on job DEFAULT.serviceRegistryReloaderJobDetail>
2019-04-30 17:29:54,792 INFO [org.jasig.cas.services.DefaultServicesManagerImpl] - <Reloading registered services.>

授权服务检查

ServiceAuthorizationCheck.java进行授权的检验;检查不通过时报错如下:
在这里插入图片描述

测试环节

service配置距离说明:
1、允许访问百度;
2、不允许访问新浪。
在这里插入图片描述

http://localhost:24588/cas/login?service=http://www.sina.com
查看日志:

2020-06-02 14:45:27,713 WARN [org.jasig.cas.CentralAuthenticationServiceImpl] - <ServiceManagement: Service [http://www.sina.com] is not allowed to use SSO.>

实现原理

    <!-- CentralAuthenticationService -->
    <bean id="centralAuthenticationService" class="org.jasig.cas.CentralAuthenticationServiceImpl">
        <constructor-arg index="0" ref="ticketRegistry"/>
        <constructor-arg index="1">
          <null />
        </constructor-arg>
        <constructor-arg index="2" ref="authenticationManager"/>
        <constructor-arg index="3" ref="ticketGrantingTicketUniqueIdGenerator"/>
        <constructor-arg index="4" ref="uniqueIdGeneratorsMap"/>
        <constructor-arg index="5" ref="grantingTicketExpirationPolicy"/>
        <constructor-arg index="6" ref="serviceTicketExpirationPolicy"/>
        <!-- 服务管理器注入 -->
        <constructor-arg index="7" ref="servicesManager"/>
        <constructor-arg index="8" ref="logoutManager"/>
        <property name="persistentIdGenerator" ref="persistentIdGenerator"/>
    </bean>

猜你喜欢

转载自blog.csdn.net/l714417743/article/details/89714144
Cas