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

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

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

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

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

2、在web.xml文件中配置
Java代碼 復制代碼
  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代碼 復制代碼
  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. ????????<!--驗證碼驗證失敗后轉(zhuǎn)向的頁面!--> ??
  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.    <!--自己定義的實體類(注意路徑!!)--> ??
  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注釋掉,驗證碼將無效!!!?--> ??
  141. ????????<property?name= "context" > ??
  142. ????????????<value> ??
  143. ????????????????org.acegisecurity.captcha.CaptchaSecurityContextImpl ??
  144. ????????????</value> ??
  145. ????????</property> ??
  146. ????</bean> ??
  147. ·············省略了一些spring安全框架的bean,自己加去吧??


4、編寫jcaptcha的實體類

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

(1)CaptchaEngine 類
Java代碼 復制代碼
  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的認證圖片 ?
  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代碼 復制代碼
  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增強版本 ?
  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框架下的彩色驗證碼)


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 在线欧美日韩 | 久草视频福利在线观看 | 久草在线资源视频 | 夜夜操av | 日韩aⅴ一区二区三区 | 亚洲一区二区三区四区 | 精品啪啪| 精品久久久久一区二区国产 | 中文字幕av亚洲精品一部二部 | 国产在线精品成人一区二区三区 | 亚洲欧美中文日韩在线v日本 | 欧美天堂| 色综合色综合网色综合 | 啪啪av| 色综合视频在线 | 国产综合av | 成人 在线 | 91视频免费观看高清观看完整 | 超碰97免费在线 | 日本黄页在线观看免费 | 欧美性受 | 激情小说五月 | 国产视频视频 | av在线大全| 国产免费一级淫片 | 不卡一二区 | 欧美成人精品 | 最全精品自拍视频在线 | 成人18网站 | 大香一本蕉伊线亚洲网 | 91精品国产色综合久久 | 蜜桃网在线观看 | 69pao强力打造免费高清 | 午夜欧美 | 欧美影院久久 | 二区三区不卡不卡视频 | 91精品久久一区二区三区 | 精品久久久久久国产 | 国产欧美日韩在线不卡第一页 | 国产精品岛国久久久久久 | 精品欧美一区二区三区久久久 |