您的位置:首页 > 编程语言 > Java开发

sso-cas全攻略(java版)------cas如何加验证码功能

2011-01-10 11:47 465 查看
加个验证码在一定程度上可以防止robot不停访问猜测用户名密码

如何在cas server端加验证码呢?

以典型的cas server端为例,

我们来实际操作下

验证码一般来说,是放在session中

session又是从request中拿来的

我们的用户名,密码验证是在哪儿做的呢?

在SimpleTestUsernamePasswordAuthenticationHandler这个类中

OK

只要把请求的request拿到

set到SimpleTestUsernamePasswordAuthenticationHandler中就OK了

先做准备工作

在以下interface中加void setHttpServletRequest(HttpServletRequest request);

方法并在其所有实现中添加private变量httpservletrequest

同时,所有实现中也要实现这个方法

CentralAuthenticationService

AuthenticationHandler

在AuthenticationViaFormAction中

的submit方法中添加以下两行

final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
this.centralAuthenticationService.setHttpServletRequest(request);

在CentralAuthenticationServiceImpl中的适当若干位置

this.authenticationManager.setHttpServletRequest(request);

OK

SimpleTestUsernamePasswordAuthenticationHandler中的request就传递进来了

可以用了

同时呢

casloginview.jsp中要加入验证码输入框

同时你自己的Credentials中也要加验证码的变量及get set字段

login-webflow中也有要相应的bind逻辑才行

前提是有产生验证码的相关类并在request的session中写了验证码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: