CAS通过用户名与ip限制密码输入错误次数(转)

之前自己通过修改源码实现了以用户名为单位限制其密码输入次数,但这样做不是很合理,如果是同一ip不同用户名呢?于是就想把也通过ip限制的功能加上。今天无意逛官网时竟然发现CAS里面有类似的功能,可以通过用户名或ip来做登录限制。没有仔细查看文档的结果就是做了一点无用功。下面介绍下开启cas限制密码输入次数的功能。有两种方法:一是把状态保存到内存中,二是通过Inspektr来管理。下面主要介绍保存到内存的方法(使用3.4.10版本的cas):

在WEB-INF\spring-configuration下创建throttleInterceptorTrigger.xml配置文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="throttleInterceptor"
class="org.jasig.cas.web.support.InMemoryThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapter"
p:failureRangeInSeconds="120"
p:failureThreshold="2" />

<bean id="throttleInterceptorJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
p:targetObject-ref="throttleInterceptor" p:targetMethod="decrementCounts" />

<bean id="periodicThrottleCleanerTrigger"
class="org.springframework.scheduling.quartz.SimpleTriggerBean"
p:jobDetail-ref="throttleInterceptorJobDetail" p:startDelay="0"
p:repeatInterval="20000" />
</beans>

其中failureThreshold为同一ip或同一用户允许错误次数

到cas-servlet.xml配置文件修改FlowHandlerMappingbean,如下:

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping" p:flowRegistry-ref="flowRegistry" p:order="2">
<property name="interceptors">
<list>
<ref local="localeChangeInterceptor" />
<ref bean="throttleInterceptor" />
</list>
</property>
</bean>完成
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值