Code Monkey home page Code Monkey logo

cas-server-integration-redis's Introduction

实现cas ticket基于redis的集群

目的

克服cas单点故障,将cas认证请求分发到多台cas服务器上,降低负载。

实现思路:

采用统一的ticket存取策略,所有ticket的操作都从**缓存redis中存取。
采用session共享,session的存取都从**缓存redis中存取。

前提:

这里只讲解如何实现cas ticket的共享,关于session的共享请移步:

实现步骤:

1. 进入 添加相关依赖

2. 替换默认的ticket存取策略

cas 4.1.x 以前版本

修改文件 WEB-INF\spring-configuration\ticketRegistry.xml

<bean id="ticketRegistry" class="org.jasig.cas.ticket.registry.DefaultTicketRegistry" />

替换为

<bean id="ticketRegistry" class="ren.boot.cas.ticket.registry.RedisTicketRegistry">
    <constructor-arg index="0" ref="redisTemplate" />

    <!-- TGT timeout in seconds -->
    <constructor-arg index="1" value="1800" />

    <!-- ST timeout in seconds -->
    <constructor-arg index="2" value="300" />
</bean>
<!-- redis连接池 -->
<bean id="jedisConnFactory"
      class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
      p:hostName="192.168.1.89"
      p:database="0"
      p:usePool="true"/>
<bean id="redisTemplate" class="org.jasig.cas.ticket.registry.TicketRedisTemplate"
      p:connectionFactory-ref="jedisConnFactory"/>

注意: 里面的 jedisConnFactory链接信息 修改为自己的连接串,这里选择database 0 为存放cas票据的数据库

cas 4.2.x :

在spring 上下文中声明如下即可:

<!-- 票据保存方式及有效期设置 -->
<alias name="redisTicketRegistry" alias="ticketRegistry" />
<bean id="redisTicketRegistry" class="ren.boot.cas.ticket.registry.RedisTicketRegistry"
    p:client-ref="ticketRedisTemplate"
    p:tgtTimeout="28800"
    p:stTimeout="10"/>
<!-- redis连接池 -->
<bean id="jedisConnFactory"
      class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
      p:hostName="localhost"
      p:database="0"
      p:usePool="true"/>
<bean id="ticketRedisTemplate" class="ren.boot.cas.ticket.registry.TicketRedisTemplate"
      p:connectionFactory-ref="jedisConnFactory"/>

cas-server-integration-redis's People

Contributors

izerui avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.