验证码跟ehcash整合

简介: 基于spring做验证码跟chcash整合,初步的源码分析,关注点是怎么让chcash来缓存验证码,而不在于验证码的生成。

1.所有配置文件如下:

`

    <bean class="com.mocent.shiro.captcha.DreamCaptcha">
    <property name="cacheManager" ref="shiroSpringCacheManager"/>
        <!-- 复用半小时缓存 -->
        <property name="cacheName" value="halfHour"/>
    </bean>

`
`

    <bean id="shiroSpringCacheManager" class="com.mocent.shiro.cash.ShiroSpringCacheManager">
        <property name="cacheManager" ref="cacheManager"/>
</bean>

`
`
3.

    <property name="cacheManager" ref="ehcacheManager"/>
    <property name="transactionAware" value="true"/>
</bean>

`
`

<bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:cash/ehcache.xml"/>
</bean>`

`5.

    <cache name="halfHour" 
    maxElementsInMemory="10000"
    maxElementsOnDisk="100000" 
    eternal="false" 
    timeToIdleSeconds="1800"
    timeToLiveSeconds="1800"
    overflowToDisk="false"
    diskPersistent="false" />

`

2. 类图

image

image
这个bean将要被IOC实例化,通过get set的方式传参数进去,被赋值的属性是cacheManager和cacheName。cacheName是直接赋值为halfHour字符串,而cacheManager属性来自
image
ShiroSpringCacheManager的属性以及方法如下
image
也是使用get set的方式设置值被设值的属性是cacheManager,cacheManager来自
image
image
经过一系列的传递后发现最终的验证码的缓存管理类是EhCacheCacheManager,它实现了org.springframework.cache.CacheManager接口可以被com.mocent.shiro.captcha.DreamCaptcha使用
继续往下看
image
org.springframework.cache.CacheManager的cacheManager参数是来自org.springframework.cache.ehcache.EhCacheManagerFactoryBean他是EhCacheCacheManager的工厂类,生成EhCacheCacheManager的配置文件是
cash/ehcache.xml里面有一个名为halfHour的缓存配置
image
这也是验证码生成类com.mocent.shiro.captcha.DreamCaptcha的另外一个属性的来源

目录
相关文章
|
26天前
生成验证码
生成验证码
12 0
|
8月前
|
缓存 前端开发 NoSQL
南南的文章-验证码还能这样生成?
南南的文章-验证码还能这样生成?
59 0
南南的文章-验证码还能这样生成?
|
10月前
|
缓存 JavaScript 安全
|
机器学习/深度学习 人工智能 前端开发
关于验证码,你不知道的一些问题!
关于验证码,大家也许会有很多疑问,下面我总结了一些常见问题。
关于验证码,你不知道的一些问题!
|
前端开发 C# 数据安全/隐私保护
C#验证码
验证码通常是为了区分用户是人还是计算机,也可以防止破解密码、刷票等恶意行为,而客户端上多数会用在关键操作上,比如购买、登录、注册等场景。现在验证码的种类样式也特别多,今天教大家如何用C#做出滑动拼图验证码吧~
C#验证码
|
C# 图形学 索引
|
Web App开发 Java

热门文章

最新文章