Spring源代码解析(九):SpringAcegi框架鉴权的实现

Spring源代码解析(九):SpringAcegi框架鉴权的实现

ID:43325715

大小:205.33 KB

页数:11页

时间:2019-09-30

Spring源代码解析(九):SpringAcegi框架鉴权的实现_第1页
Spring源代码解析(九):SpringAcegi框架鉴权的实现_第2页
Spring源代码解析(九):SpringAcegi框架鉴权的实现_第3页
Spring源代码解析(九):SpringAcegi框架鉴权的实现_第4页
Spring源代码解析(九):SpringAcegi框架鉴权的实现_第5页
资源描述:

《Spring源代码解析(九):SpringAcegi框架鉴权的实现》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、简单分析讣SpringAcegi的源代码实现:Servlet.Filter的实现AuthenticationProcessingFilter启动Web页面的验证过程一在AbstractProcessingFilter定义了整个验证过程的模板:Java代码:L・publicvoiddoFilter(ServletRequestrequest.ServletResponseresponse.FilterChainchain)2・throwslOException,ServletException{3・〃这里檢柴是不是符合ServletRequest/SevletRespo

2、nse的要求a.if(((requestInstanceofHttpServletRequest)){5・thrownewServletException(MCanonlyprocessHttpServletRequest*):6・}7・8.if("(responseInstanceofHttpServletResponse)){9.thrownewServletExceptionf'CanonlyprocessHttpServletResponse**):10-}11.12.HttpServletRequesthttpRequest=(HttpServletRequ

3、est)request;13・HttpServletRespons©httpResponse=(HttpServletResponse)response;14.〃抿据HttpServletRequest和HttpServielResponse來进行15.if(require$Authenticatlon(httpRequest,httpResponse)){16.if(logger.isDebugEnabledO){17・logger.debug(“Requestistoprocessauthentication”);18.}19.〃这里定义Acegi中的Authen

4、tication对妝来持有相关的用户验证倍息28・AuthenticationauthResult;2丄・22.try{23・onPreAuthentication(hllpRequesl・httpResponse);24.〃这里的具体验证过程委托给子类完成,比如AuthenticationProcessingFilter来完成墓于Web页面的用户验证25・authResult=attemptAutbent»cation(httpReque$t);26.}catch(AuthenticationExceptionfailed){27・〃Authenticationfa

5、iled28・unsuccGSsfulAuthentication(httpRequest,httpResponse,failed);29・30.return:31-}32・33・//Authenticationsuccess34.if(continueChainBeforeSuccessfulAuthentication){35.chain.doFilterfrequest,response);36.}37.〃完后的后续工作.比如挑转到相应的页面38・successfulAuth©ntication(hnpRgquest.httpResponse.authResul

6、t);39・40.return;42・43・chain.doFilter(request,response);44・}住.AuthenticationProcessingFilter屮的貝体验证过程是这样的:Java代码1・publicAuthenticationattemptAuthentication(HttpServletRequestrequest)2・throwsAuthenticationException{人〃这里从HttpServtetRequest中斜到用户矗证的用户名和密码4.Stringusername=obtainUsernam©(reques

7、t):5.Stringpassword=obtainPassword(request);6・7.if(username■■null){8・username=9・}11•If(password■■null){12.password-13.}14.〃这里很矗得到的用户名和密码去构适一个Authentication对鞭捉供给AuthenticationManager进行验证•里面包含f用户的用户名和密码佶息15・UsemamePasswordAuthenticationTokenauthRequest=newUsernamePasswordAuthent>

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。