diff --git a/README.md b/README.md index e923894..96a53e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kaptcha Spring Boot Starter -Kaptcha Spring Boot Starter will help you use Google Kaptcha with Spring Boot. +Kaptcha Spring Boot Starter can help you use [Google Kaptcha](http://code.google.com/p/kaptcha/) with [Spring Boot](https://github.com/spring-projects/spring-boot) easier. ## Usage @@ -10,7 +10,7 @@ Declare `kaptcha-spring-boot-starter` dependency in your `pom.xml` file. com.oopsguy.kaptcha kaptcha-spring-boot-starter - 1.0.0-beta + 1.0.0-beta-2 ``` @@ -108,7 +108,7 @@ Then browse [http://localhost:8080/home/capthca](http://localhost:8080/home/capt ### Java Code -You can also inject `Producer` Bean directly by annotation to generate captcha. +You can also inject a `Producer` bean directly by annotation to generate captcha. ```java @Controller diff --git a/kapcha-spring-boot-autoconfigure/.gitignore b/kaptcha-spring-boot-autoconfigure/.gitignore similarity index 100% rename from kapcha-spring-boot-autoconfigure/.gitignore rename to kaptcha-spring-boot-autoconfigure/.gitignore diff --git a/kapcha-spring-boot-autoconfigure/mvnw.cmd b/kaptcha-spring-boot-autoconfigure/mvnw.cmd similarity index 100% rename from kapcha-spring-boot-autoconfigure/mvnw.cmd rename to kaptcha-spring-boot-autoconfigure/mvnw.cmd diff --git a/kapcha-spring-boot-autoconfigure/pom.xml b/kaptcha-spring-boot-autoconfigure/pom.xml similarity index 81% rename from kapcha-spring-boot-autoconfigure/pom.xml rename to kaptcha-spring-boot-autoconfigure/pom.xml index 3a7838c..db0a6d9 100644 --- a/kapcha-spring-boot-autoconfigure/pom.xml +++ b/kaptcha-spring-boot-autoconfigure/pom.xml @@ -5,12 +5,12 @@ com.oopsguy.kaptcha kaptcha-spring-boot-parent - 1.0.0-beta + 1.0.0-beta-2 ../kaptcha-spring-boot-parent jar - kapcha-spring-boot-autoconfigure - kapcha-spring-boot-autoconfigure + kaptcha-spring-boot-autoconfigure + kaptcha-spring-boot-autoconfigure https://github.com/12software/kaptcha-spring-boot Kaptcha Spring Boot AutoConfigurer @@ -19,6 +19,11 @@ org.springframework.boot spring-boot-autoconfigure + + org.springframework.boot + spring-boot-autoconfigure-processor + true + org.springframework.boot spring-boot-configuration-processor @@ -29,14 +34,14 @@ kaptcha ${project.version} - - javax.servlet - javax.servlet-api - javax.annotation javax.annotation-api + + javax.servlet + javax.servlet-api + diff --git a/kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/BaseProperties.java b/kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/BaseProperties.java similarity index 100% rename from kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/BaseProperties.java rename to kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/BaseProperties.java diff --git a/kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaAutoConfigure.java b/kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaAutoConfigure.java similarity index 100% rename from kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaAutoConfigure.java rename to kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaAutoConfigure.java diff --git a/kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaProperties.java b/kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaProperties.java similarity index 100% rename from kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaProperties.java rename to kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/KaptchaProperties.java diff --git a/kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/ServletRegisterInitializer.java b/kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/ServletRegisterInitializer.java similarity index 100% rename from kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/ServletRegisterInitializer.java rename to kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/ServletRegisterInitializer.java diff --git a/kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/constant/KaptchaConst.java b/kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/constant/KaptchaConst.java similarity index 100% rename from kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/constant/KaptchaConst.java rename to kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/constant/KaptchaConst.java diff --git a/kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/util/ConfigUtils.java b/kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/util/ConfigUtils.java similarity index 100% rename from kapcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/util/ConfigUtils.java rename to kaptcha-spring-boot-autoconfigure/src/main/java/com/oopsguy/kaptcha/autoconfigure/util/ConfigUtils.java diff --git a/kapcha-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/kaptcha-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories similarity index 100% rename from kapcha-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories rename to kaptcha-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories diff --git a/kaptcha-spring-boot-parent/pom.xml b/kaptcha-spring-boot-parent/pom.xml index 07fa851..94ee00a 100644 --- a/kaptcha-spring-boot-parent/pom.xml +++ b/kaptcha-spring-boot-parent/pom.xml @@ -5,7 +5,7 @@ kaptcha-spring-boot com.oopsguy.kaptcha - 1.0.0-beta + 1.0.0-beta-2 ../ 4.0.0 @@ -17,7 +17,7 @@ ../kaptcha - ../kapcha-spring-boot-autoconfigure + ../kaptcha-spring-boot-autoconfigure ../kaptcha-spring-boot-starter ../kaptcha-spring-boot-starter-example diff --git a/kaptcha-spring-boot-starter-example/pom.xml b/kaptcha-spring-boot-starter-example/pom.xml index 78e4658..e9af9dd 100644 --- a/kaptcha-spring-boot-starter-example/pom.xml +++ b/kaptcha-spring-boot-starter-example/pom.xml @@ -5,7 +5,7 @@ com.oopsguy.kaptcha kaptcha-spring-boot-parent - 1.0.0-beta + 1.0.0-beta-2 ../kaptcha-spring-boot-parent kaptcha-spring-boot-starter-example diff --git a/kaptcha-spring-boot-starter-example/src/main/java/com/oopsguy/kaptcha/example/KaptchaController.java b/kaptcha-spring-boot-starter-example/src/main/java/com/oopsguy/kaptcha/example/KaptchaController.java index 18d1077..5390bb4 100644 --- a/kaptcha-spring-boot-starter-example/src/main/java/com/oopsguy/kaptcha/example/KaptchaController.java +++ b/kaptcha-spring-boot-starter-example/src/main/java/com/oopsguy/kaptcha/example/KaptchaController.java @@ -13,12 +13,20 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; +import java.util.Date; @Controller public class KaptchaController { private final static String HOME_CAPTCHA_SESSION_KEY = "homeCaptcha"; + private final static String HOME_CAPTCHA_SESSION_DATE = "homeCaptchaDate"; + + /** + * captcha expire time, millis + */ + private final static long VALID_MILLIS_TIME = 10 * 1000; + @Resource private Producer captchaProducer; @@ -44,7 +52,12 @@ public String checkHomeCaptcha(HttpServletRequest req) { return "empty captcha"; } String savedCaptcha = (String) req.getSession().getAttribute(HOME_CAPTCHA_SESSION_KEY); + Date sessionDate = (Date) req.getSession().getAttribute(HOME_CAPTCHA_SESSION_DATE); if (captcha.equalsIgnoreCase(savedCaptcha)) { + if (sessionDate == null + || System.currentTimeMillis() - sessionDate.getTime() > VALID_MILLIS_TIME) { + return "expired"; + } return "valid!"; } return "invalid"; diff --git a/kaptcha-spring-boot-starter-example/src/main/resources/application.yml b/kaptcha-spring-boot-starter-example/src/main/resources/application.yml index 6b0ce1f..6e6f5e2 100644 --- a/kaptcha-spring-boot-starter-example/src/main/resources/application.yml +++ b/kaptcha-spring-boot-starter-example/src/main/resources/application.yml @@ -47,6 +47,7 @@ kaptcha: path: /home/captcha session: key: homeCaptcha + date: homeCaptchaDate background: color-from: '255,255,255' color-to: '255,255,255' diff --git a/kaptcha-spring-boot-starter/pom.xml b/kaptcha-spring-boot-starter/pom.xml index 405786c..7a6c94d 100644 --- a/kaptcha-spring-boot-starter/pom.xml +++ b/kaptcha-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.oopsguy.kaptcha kaptcha-spring-boot-parent - 1.0.0-beta + 1.0.0-beta-2 ../kaptcha-spring-boot-parent jar @@ -17,7 +17,7 @@ com.oopsguy.kaptcha - kapcha-spring-boot-autoconfigure + kaptcha-spring-boot-autoconfigure ${project.version} diff --git a/kaptcha/pom.xml b/kaptcha/pom.xml index e58d743..29e482c 100644 --- a/kaptcha/pom.xml +++ b/kaptcha/pom.xml @@ -5,7 +5,7 @@ kaptcha-spring-boot-parent com.oopsguy.kaptcha - 1.0.0-beta + 1.0.0-beta-2 ../kaptcha-spring-boot-parent diff --git a/pom.xml b/pom.xml index 8bf720c..137fce1 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.oopsguy.kaptcha kaptcha-spring-boot pom - 1.0.0-beta + 1.0.0-beta-2 kaptcha-spring-boot https://github.com/12software/kaptcha-spring-boot