jcaptchacn.hxex.order.core.jcaptcha.ImageCaptchaServ" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

spring+ jcaptcha(spring框架下的彩色驗(yàn)證碼)

系統(tǒng) 1939 0
1、從jcaptcha官方網(wǎng)站下載jcaptcha的發(fā)行包,并將其發(fā)行包中的jar文件考貝到本地項(xiàng)目WEB-INF目錄下的lib目錄中。

官方網(wǎng)址 http://jcaptcha.sourceforge.net/

2、在web.xml文件中配置
Java代碼 復(fù)制代碼
  1. <servlet> ??
  2. ?????<servlet-name>jcaptcha</servlet-name> ??
  3. ?????<servlet- class >cn.hxex.order.core.jcaptcha.ImageCaptchaServlet</servlet- class > ??
  4. ?????<load-on-startup> 3 </load-on-startup> ??
  5. ?</servlet> ??
  6. ??
  7. ?<servlet-mapping> ??
  8. ?????<servlet-name>jcaptcha</servlet-name> ??
  9. ?????<url-pattern>/captcha.jpg</url-pattern> ??
  10. ?</servlet-mapping>??


3、jcaptcha在spring中的配置
Java代碼 復(fù)制代碼
  1. ????<bean?id= "channelProcessingFilter" ??
  2. ?????????? class = "org.acegisecurity.securechannel.ChannelProcessingFilter" > ??
  3. ????????<property?name= "channelDecisionManager" > ??
  4. ????????????<ref?local= "channelDecisionManager" />? ??
  5. ????????</property> ??
  6. ????????<property?name= "filterInvocationDefinitionSource" > ??
  7. ????????????<value> ??
  8. ????????????????CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON ??
  9. ????????????????PATTERN_TYPE_APACHE_ANT ??
  10. ????????????????/j_security_check=REQUIRES_CAPTCHA_ONCE_ABOVE_THRESOLD_REQUESTS ??
  11. ????????????</value> ??
  12. ????????</property> ??
  13. ????</bean> ??
  14. ??
  15. ????<bean?id= "channelDecisionManager" ??
  16. ?????????? class = "org.acegisecurity.securechannel.ChannelDecisionManagerImpl" > ??
  17. ????????<property?name= "channelProcessors" >? ??
  18. ????????????<list> ??
  19. ????????????????<ref?local= "testOnceAfterMaxRequestsCaptchaChannelProcessor" /> ??
  20. ????????????????<ref?local= "alwaysTestAfterTimeInMillisCaptchaChannelProcessor" /> ??
  21. ????????????????<ref?local= "alwaysTestAfterMaxRequestsCaptchaChannelProcessor" /> ??
  22. ????????????????<ref?local= "alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor" /> ??
  23. ????????????</list> ??
  24. ????????</property> ??
  25. ????</bean> ??
  26. ??
  27. ????<!--?REQUIRES_CAPTCHA_ONCE_ABOVE_THRESOLD_REQUESTS?--> ??
  28. ????<bean?id= "testOnceAfterMaxRequestsCaptchaChannelProcessor" ??
  29. ?????????? class = "org.acegisecurity.captcha.TestOnceAfterMaxRequestsCaptchaChannelProcessor" > ??
  30. ????????<property?name= "thresold" > ??
  31. ????????????<value> 0 </value> ??
  32. ????????</property> ??
  33. ????????<property?name= "entryPoint" > ??
  34. ????????????<ref?bean= "captchaEntryPoint" /> ??
  35. ????????</property> ??
  36. ????</bean> ??
  37. ??
  38. ????<!--?REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS?--> ??
  39. ????<bean?id= "alwaysTestAfterMaxRequestsCaptchaChannelProcessor" ??
  40. ?????????? class = "org.acegisecurity.captcha.AlwaysTestAfterMaxRequestsCaptchaChannelProcessor" > ??
  41. ????????<property?name= "thresold" > ??
  42. ????????????<value> 5 </value> ??
  43. ????????</property> ??
  44. ????????<property?name= "entryPoint" > ??
  45. ????????????<ref?bean= "captchaEntryPoint" /> ??
  46. ????????</property> ??
  47. ????</bean> ??
  48. ??
  49. ????<!--?REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS?--> ??
  50. ????<bean?id= "alwaysTestAfterTimeInMillisCaptchaChannelProcessor" ??
  51. ?????????? class = "org.acegisecurity.captcha.AlwaysTestAfterTimeInMillisCaptchaChannelProcessor" > ??
  52. ????????<property?name= "thresold" > ??
  53. ????????????<value> 5000 </value> ??
  54. ????????</property> ??
  55. ????????<property?name= "entryPoint" > ??
  56. ????????????<ref?bean= "captchaEntryPoint" /> ??
  57. ????????</property> ??
  58. ????</bean> ??
  59. ??
  60. ????<!--?REQUIRES_CAPTCHA_BELOW_AVERAGE_TIME_IN_MILLIS_REQUESTS?--> ??
  61. ????? ??
  62. ????<bean ??
  63. ????????????id= "alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor" ??
  64. ???????????? class = "org.acegisecurity.captcha.AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor" > ??
  65. ????????<property?name= "thresold" > ??
  66. ????????????<value> 20000 </value> ??
  67. ????????</property> ??
  68. ????????<property?name= "entryPoint" > ??
  69. ????????????<ref?bean= "captchaEntryPoint" /> ??
  70. ????????</property> ??
  71. ????</bean> ??
  72. ??
  73. ????<bean?id= "captchaEntryPoint" ??
  74. ?????????? class = "org.acegisecurity.captcha.CaptchaEntryPoint" > ??
  75. ????????<!--驗(yàn)證碼驗(yàn)證失敗后轉(zhuǎn)向的頁(yè)面!--> ??
  76. ????????<property?name= "captchaFormUrl" > ??
  77. ????????????<value>/admin/login.jsp?login_error=code_error</value> ??
  78. ????????</property> ??
  79. ????????<property?name= "includeOriginalRequest" > ??
  80. ????????????<value> false </value> ??
  81. ????????</property> ??
  82. ????????<property?name= "includeOriginalParameters" > ??
  83. ????????????<value> false </value> ??
  84. ????????</property> ??
  85. ????</bean> ??
  86. ??
  87. ????<bean?id= "captchaValidationProcessingFilter" ??
  88. ?????????? class = "org.acegisecurity.captcha.CaptchaValidationProcessingFilter" > ??
  89. ????????<property?name= "captchaService" > ??
  90. ????????????<ref?bean= "captchaService" /> ??
  91. ????????</property> ??
  92. ????????<property?name= "captchaValidationParameter" ?value= "j_captcha_response" /> ??
  93. ????</bean> ??
  94. ???? ??
  95. ????<!--?imageCaptchaService?is?injected?into?captchaImageCreateController?as?well?as?to?captchaService?beans?--> ??
  96.    <!--自己定義的實(shí)體類(注意路徑!!)--> ??
  97. ????<bean?id= "captchaService" ? class = "cn.hxex.order.core.jcaptcha.JCaptchaServiceProxyImpl" > ??
  98. ????????<property?name= "jcaptchaService" ?ref= "imageCaptchaService" /> ??
  99. ????</bean> ??
  100. ???? ??
  101. ????<bean?id= "imageCaptchaService" ? class = "com.octo.captcha.service.image.DefaultManageableImageCaptchaService" > ??
  102. ????????<constructor-arg?type= "com.octo.captcha.service.captchastore.CaptchaStore" ?index= "0" > ??
  103. ????????????<ref?bean= "fastHashMapCaptchaStore" /> ??
  104. ????????</constructor-arg> ??
  105. ????????<!--?( 1 )?which?captcha?Engine?you?use?--> ??
  106. ????????<constructor-arg?type= "com.octo.captcha.engine.CaptchaEngine" ?index= "1" > ??
  107. ????????????<ref?bean= "captchaEngineEx" /> ??
  108. ????????</constructor-arg> ??
  109. ????????<constructor-arg?index= "2" > ??
  110. ????????????<value> 180 </value> ??
  111. ????????</constructor-arg> ??
  112. ????????<constructor-arg?index= "3" > ??
  113. ????????????<value> 100000 </value> ??
  114. ????????</constructor-arg> ??
  115. ????????<constructor-arg?index= "4" > ??
  116. ????????????<value> 75000 </value> ??
  117. ????????</constructor-arg> ??
  118. ????</bean> ??
  119. ??
  120. ????<bean?id= "fastHashMapCaptchaStore" ? class = "com.octo.captcha.service.captchastore.FastHashMapCaptchaStore" /> ??
  121. ??
  122. ????<!--?( 2 )?you?can?define?more?than?one?captcha?engine?here?--> ??
  123. ????<bean?id= "captchaEngineEx" ??
  124. ?????????? class = "cn.hxex.order.core.jcaptcha.engine.CaptchaEngineEx" >?????? ??
  125. ????</bean> ??
  126. ??
  127. ?????????<bean?id= "filterChainProxy" ??
  128. ???????? class = "org.acegisecurity.util.FilterChainProxy" > ??
  129. ????????<property?name= "filterInvocationDefinitionSource" >? ??
  130. ????????????<value> ??
  131. ????????????????CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON ??
  132. ????????????????PATTERN_TYPE_APACHE_ANT ??
  133. ????????????????/**=httpSessionContextIntegrationFilter,captchaValidationProcessingFilter,channelProcessingFilter,authenticationProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor ??
  134. ????????????</value> ??
  135. ????????</property> ??
  136. ????</bean> ??
  137. ??
  138. ?????????<bean?id= "httpSessionContextIntegrationFilter" ??
  139. ???????? class = "org.acegisecurity.context.HttpSessionContextIntegrationFilter" > ??
  140. ????????<!--?將下面的property注釋掉,驗(yàn)證碼將無(wú)效!!!?--> ??
  141. ????????<property?name= "context" > ??
  142. ????????????<value> ??
  143. ????????????????org.acegisecurity.captcha.CaptchaSecurityContextImpl ??
  144. ????????????</value> ??
  145. ????????</property> ??
  146. ????</bean> ??
  147. ·············省略了一些spring安全框架的bean,自己加去吧??


4、編寫jcaptcha的實(shí)體類

實(shí)體類包的路徑一定要和spring配置文件里的路徑一樣

(1)CaptchaEngine 類
Java代碼 復(fù)制代碼
  1. package ?cn.hxex.order.core.jcaptcha.engine; ??
  2. ??
  3. import ?java.awt.Color; ??
  4. ??
  5. import ?com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator; ??
  6. import ?com.octo.captcha.component.image.backgroundgenerator ??
  7. ??.FunkyBackgroundGenerator; ??
  8. import ?com.octo.captcha.component.image.fontgenerator.FontGenerator; ??
  9. import ?com.octo.captcha.component.image.fontgenerator ??
  10. ??.TwistedAndShearedRandomFontGenerator; ??
  11. import ?com.octo.captcha.component.image.textpaster.RandomTextPaster; ??
  12. import ?com.octo.captcha.component.image.textpaster.TextPaster; ??
  13. import ?com.octo.captcha.component.image.wordtoimage.ComposedWordToImage; ??
  14. import ?com.octo.captcha.component.image.wordtoimage.WordToImage; ??
  15. import ?com.octo.captcha.component.word.wordgenerator.RandomWordGenerator; ??
  16. import ?com.octo.captcha.component.word.wordgenerator.WordGenerator; ??
  17. import ?com.octo.captcha.engine.image.ListImageCaptchaEngine; ??
  18. import ?com.octo.captcha.image.gimpy.GimpyFactory; ??
  19. ??
  20. /** ?
  21. ?*?SpringSide?Custom的認(rèn)證圖片 ?
  22. ?*? ?
  23. ?*?@author?cac ?
  24. ?*/ ??
  25. public ? class ?CaptchaEngine? extends ?ListImageCaptchaEngine?{ ??
  26. ?? /** ?
  27. ???*?@see?ListImageCaptchaEngine ?
  28. ???*/ ??
  29. ?? protected ? void ?buildInitialFactories()?{ ??
  30. ????WordGenerator?wordGenerator? ??
  31. ??????=? new ?RandomWordGenerator( "023456789" ); ??
  32. ???? //?nteger?minAcceptedWordLength,?Integer?maxAcceptedWordLength,Color[] ??
  33. ???? //?textColors ??
  34. ????TextPaster?textPaster?=? new ?RandomTextPaster( 4 , 5 ,?Color.WHITE); ??
  35. ???? //?Integer?width,?Integer?height ??
  36. ????BackgroundGenerator?backgroundGenerator? ??
  37. ??????=? new ?FunkyBackgroundGenerator( 100 , 40 ); ??
  38. ???? //?Integer?minFontSize,?Integer?maxFontSize ??
  39. ????FontGenerator?fontGenerator?=? new ?TwistedAndShearedRandomFontGenerator( 20 ,? 22 ); ??
  40. ????WordToImage?wordToImage?=? new ?ComposedWordToImage(fontGenerator, ??
  41. ????????backgroundGenerator,?textPaster); ??
  42. ????addFactory( new ?GimpyFactory(wordGenerator,?wordToImage)); ??
  43. ??} ??
  44. }??

(2)CaptchaEngineEx 類
Java代碼 復(fù)制代碼
  1. package ?cn.hxex.order.core.jcaptcha.engine; ??
  2. ??
  3. import ?java.awt.Color; ??
  4. ??
  5. import ?com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator; ??
  6. import ?com.octo.captcha.component.image.backgroundgenerator ??
  7. ??.GradientBackgroundGenerator; ??
  8. import ?com.octo.captcha.component.image.color.SingleColorGenerator; ??
  9. import ?com.octo.captcha.component.image.fontgenerator.FontGenerator; ??
  10. import ?com.octo.captcha.component.image.fontgenerator.RandomFontGenerator; ??
  11. import ?com.octo.captcha.component.image.textpaster.DecoratedRandomTextPaster; ??
  12. import ?com.octo.captcha.component.image.textpaster.TextPaster; ??
  13. import ?com.octo.captcha.component.image.textpaster.textdecorator ??
  14. ??.BaffleTextDecorator; ??
  15. import ?com.octo.captcha.component.image.textpaster.textdecorator ??
  16. ??.LineTextDecorator; ??
  17. import ?com.octo.captcha.component.image.textpaster.textdecorator.TextDecorator; ??
  18. import ?com.octo.captcha.component.image.wordtoimage.ComposedWordToImage; ??
  19. import ?com.octo.captcha.component.image.wordtoimage.WordToImage; ??
  20. import ?com.octo.captcha.component.word.wordgenerator.RandomWordGenerator; ??
  21. import ?com.octo.captcha.component.word.wordgenerator.WordGenerator; ??
  22. import ?com.octo.captcha.engine.image.ListImageCaptchaEngine; ??
  23. import ?com.octo.captcha.image.gimpy.GimpyFactory; ??
  24. ??
  25. ??
  26. /** ?
  27. ?*?Captcha增強(qiáng)版本 ?
  28. ?*? ?
  29. ?*?@author?david.turing@gmail.com ?
  30. ?*?@modifyTime?21:01:52 ?
  31. ?*?@description? ?
  32. ?*?<pre> ?
  33. ?*??安裝?Captcha?Instruction?<br> ?
  34. ?*??1.add?captchaValidationProcessingFilter? ?
  35. ?*????to?applicationContext-acegi-security.xml<br> ?
  36. ?*??2.modify?applicationContext-captcha-security.xml ?
  37. ?*????<ul> ?
  38. ?*????<li>?make?sure?that?captchaValidationProcessingFilter?Call?captchaService ?
  39. ??????<li>?config?CaptchaEngine?for?captchaService?(refer?imageCaptchaService)? ?
  40. ??????<li>?write?your?own?CaptchaEngine ?
  41. ??????<li>?config?the?following,?so?that?We?use?CaptchaEngineEx?to?generate?the? ?
  42. ??????????captcha?image.? ?
  43. ??????</ul> ?
  44. ??????????<constructor-arg ?
  45. ?*??????????????type="com.octo.captcha.engine.CaptchaEngine"?index="1">? ?
  46. ?*??????????????<ref?bean="captchaEngineEx"/gt;?</constructor-arg>? ?
  47. ?*?</pre> ?
  48. ?*/ ??
  49. public ? class ?CaptchaEngineEx? extends ?ListImageCaptchaEngine?{ ??
  50. ?? /** ?
  51. ???*?... ?
  52. ???*/ ??
  53. ?? protected ? void ?buildInitialFactories()?{ ??
  54. ???? ??
  55. ????? //Set?Captcha?Word?Length?Limitation?which?should?not?over?6????? ??
  56. ????Integer?minAcceptedWordLength?=? new ?Integer( 4 ); ??
  57. ????Integer?maxAcceptedWordLength?=? new ?Integer( 5 ); ??
  58. ???? //Set?up?Captcha?Image?Size:?Height?and?Width???? ??
  59. ????Integer?imageHeight?=? new ?Integer( 40 ); ??
  60. ????Integer?imageWidth?=? new ?Integer( 100 ); ??
  61. ???? ??
  62. ???? //Set?Captcha?Font?Size???? ??
  63. ????Integer?minFontSize?=? new ?Integer( 20 ); ??
  64. ????Integer?maxFontSize?=? new ?Integer( 22 ); ??
  65. ???? //We?just?generate?digit?for?captcha?source?char?Although?you?can?use ??
  66. ???? //abcdefg......xyz ??
  67. ????WordGenerator?wordGenerator? ??
  68. ??????=? new ?RandomWordGenerator( "023456789" ); ??
  69. ? ??
  70. ????? //cyt?and?unruledboy?proved?that?backgroup?not?a?factor?of?Security.?A ??
  71. ????? //captcha?attacker?won't?affaid?colorful?backgroud,?so?we?just?use?white ??
  72. ????? //color,?like?google?and?hotmail.?? ??
  73. ????BackgroundGenerator?backgroundGenerator?=? new ?GradientBackgroundGenerator( ??
  74. ????????imageWidth,?imageHeight,?Color.white,?Color.white); ??
  75. ?? ??
  76. ????? //font?is?not?helpful?for?security?but?it?really?increase?difficultness?for ??
  77. ????? //attacker????? ??
  78. ????FontGenerator?fontGenerator?=? new ?RandomFontGenerator(minFontSize, ??
  79. ????????maxFontSize);???? ??
  80. ????? //?Note?that?our?captcha?color?is?Blue????? ??
  81. ????SingleColorGenerator?scg?=? new ?SingleColorGenerator(Color.blue); ??
  82. ?? ??
  83. ????? //decorator?is?very?useful?pretend?captcha?attack.?we?use?two?line?text ??
  84. ????? //decorators. ??
  85. ????? ??
  86. ????LineTextDecorator?lineDecorator?=? new ?LineTextDecorator( 1 ,?Color.blue); ??
  87. ???? //?LineTextDecorator?line_decorator2?=?new?LineTextDecorator(1,?Color.blue); ??
  88. ????TextDecorator[]?textdecorators?=? new ?TextDecorator[ 1 ]; ??
  89. ??
  90. ????textdecorators[ 0 ]?=?lineDecorator; ??
  91. ???? //?textdecorators[1]?=?line_decorator2; ??
  92. ??
  93. ????TextPaster?textPaster?=? new ?DecoratedRandomTextPaster( ??
  94. ????????minAcceptedWordLength,?maxAcceptedWordLength,?scg, ??
  95. ???????? new ?TextDecorator[]?{? new ?BaffleTextDecorator( new ?Integer( 1 ), ??
  96. ????????????Color.white)?}); ??
  97. ??
  98. ???? //ok,?generate?the?WordTo

spring+ jcaptcha(spring框架下的彩色驗(yàn)證碼)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 欧美一级毛片免费网站 | 久久乐国产综合亚洲精品 | 国语精品视频在线观看不卡 | 全部在线播放免费毛片 | 黄片一级毛片 | 狠狠躁夜夜躁人人爽天天段 | 国产成人精品一区二三区2022 | 精品久久伦理中文字幕 | 99精品高清视频一区二区 | 91精选在线观看 | 欧美精品一区二区三区在线 | 久草综合在线观看 | 久久制服诱惑 | 九九热国产视频 | 狠狠躁夜夜躁人人爽天天miya | 欧美午夜激情影院 | 奇米777狠狠色噜噜狠狠狠 | www.国产一区二区三区 | 成人在线免费小视频 | 26uuu另类欧美亚洲曰本 | 九九99靖品 | 人妖粗暴刺激videos | 日韩精品国产自在久久现线拍 | 免费a视频在线观看 | 中文字幕欧美日韩久久 | 国产一区二区久久精品 | 成人午夜爱爱爱爱爱 | 欧美日韩午夜视频 | 狠狠躁夜夜躁人人爽天天miya | 日日撸夜夜撸网站 | 久久综合伊人77777 | 在线观看亚洲视频 | 亚洲性生活 | 国产a精品 | 中文字幕在线观看2023 | 国内久久久久久久久久 | 凹凸精品视频分类国产品免费 | 中文字幕精品一区二区精品 | 国产精品久久做爰 | 国产精品美女在线 | 久草亚洲视频 |