public final class CaptchaHelper extends Object implements Serviceable
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
CaptchaHelper.CaptchaType |
(package private) static class |
CaptchaHelper.ValidableCaptcha
Bean for a captcha and a validity date
|
| Modifier and Type | Field and Description |
|---|---|
private static JSONUtils |
_jsonUtils |
private static Logger |
_logger |
private static Map<String,CaptchaHelper.ValidableCaptcha> |
_mapDynamicCaptcha |
private static Map<String,List<CaptchaHelper.ValidableCaptcha>> |
_mapStaticCaptcha |
private static String |
CAPTCHA_TYPE_KEY |
private static String |
DYNAMIC_PREFIX_KEY |
private static String |
RECAPTCHA_SECRET_KEY |
private static String |
STATIC_PREFIX_KEY |
| Constructor and Description |
|---|
CaptchaHelper() |
| Modifier and Type | Method and Description |
|---|---|
private static void |
_cleanOldDynamicCaptchas() |
private static void |
_cleanOldStaticCaptchas() |
private static Captcha |
_generateImageCaptcha(Integer color,
boolean addNoise,
boolean fisheye,
int width,
int height) |
static boolean |
checkAndInvalidate(String key,
String value)
Check a captcha
|
static boolean |
checkAndInvalidateJCaptcha(String key,
String value)
Check a captcha
|
static boolean |
checkAndInvalidateReCaptcha(String value)
Check a ReCaptcha value
|
static void |
cleanOldCaptchas()
Clean the outdated captchas
|
static BufferedImage |
generateImageCaptcha(String key)
Generate an image captcha to PNG format.
|
static BufferedImage |
generateImageCaptcha(String key,
boolean addNoise,
boolean fisheye)
Generate an image captcha to PNG format.
|
static BufferedImage |
generateImageCaptcha(String key,
Integer color)
Generate an image captcha to PNG format.
|
static BufferedImage |
generateImageCaptcha(String key,
Integer color,
boolean addNoise,
boolean fisheye)
Generate an image captcha to PNG format.
|
static BufferedImage |
generateImageCaptcha(String key,
Integer color,
boolean addNoise,
boolean fisheye,
int width,
int height)
Generate an image captcha to PNG format.
|
static String |
getCaptchaType()
Retrieve the type of captcha used
|
static void |
removeCaptcha(String key)
Remove a captcha
|
void |
service(ServiceManager manager) |
private static final String CAPTCHA_TYPE_KEY
private static final String RECAPTCHA_SECRET_KEY
private static final String STATIC_PREFIX_KEY
private static final String DYNAMIC_PREFIX_KEY
private static Map<String,List<CaptchaHelper.ValidableCaptcha>> _mapStaticCaptcha
private static Map<String,CaptchaHelper.ValidableCaptcha> _mapDynamicCaptcha
private static JSONUtils _jsonUtils
public CaptchaHelper()
public void service(ServiceManager manager) throws ServiceException
service in interface ServiceableServiceExceptionpublic static String getCaptchaType()
public static boolean checkAndInvalidate(String key, String value)
key - The captcha key. Can be empty or null when using reCaptcha.value - The value to checktrue if the captcha is valid, false otherwise.public static boolean checkAndInvalidateJCaptcha(String key, String value)
key - The keyvalue - The value to checkpublic static boolean checkAndInvalidateReCaptcha(String value)
value - The value to checkpublic static void removeCaptcha(String key)
key - the key valuepublic static void cleanOldCaptchas()
private static void _cleanOldDynamicCaptchas()
private static void _cleanOldStaticCaptchas()
public static BufferedImage generateImageCaptcha(String key)
key - the wanted key. Can be not null. MUST START with "STATIC-" or "DYNAMIC-". If the key starts with 'STATIC-' this key may be used several times (e.g. for a cached page with a unique id for several display), if the key starts with 'DYNAMIC-' the key will unique (removing an existing captcha with the same key).public static BufferedImage generateImageCaptcha(String key, boolean addNoise, boolean fisheye)
key - the wanted key. Can be not null. MUST START with "STATIC-" or "DYNAMIC-". If the key starts with 'STATIC-' this key may be used several times (e.g. for a cached page with a unique id for several display), if the key starts with 'DYNAMIC-' the key will unique (removing an existing captcha with the same key).addNoise - true to add noise to captcha imagefisheye - true to add fish eye background to captcha imagepublic static BufferedImage generateImageCaptcha(String key, Integer color)
key - the wanted key. Can not be null. You can use RandomStringUtils.randomAlphanumeric(10) to generates onecolor - The color for fontpublic static BufferedImage generateImageCaptcha(String key, Integer color, boolean addNoise, boolean fisheye)
key - the wanted key. Can not be null. You can use RandomStringUtils.randomAlphanumeric(10) to generates onecolor - The color for fontaddNoise - true to add noise to captcha imagefisheye - true to add fish eye background to captcha imagepublic static BufferedImage generateImageCaptcha(String key, Integer color, boolean addNoise, boolean fisheye, int width, int height)
key - the wanted key. Can not be null. You can use RandomStringUtils.randomAlphanumeric(10) to generates onecolor - The color for fontaddNoise - true to add noise to captcha imagefisheye - true to add fish eye background to captcha imagewidth - The image widthheight - The image heightprivate static Captcha _generateImageCaptcha(Integer color, boolean addNoise, boolean fisheye, int width, int height)