Package org.ametys.core.captcha
Class CaptchaHelper
- java.lang.Object
-
- org.ametys.core.captcha.CaptchaHelper
-
- All Implemented Interfaces:
Serviceable
public final class CaptchaHelper extends Object implements Serviceable
Helper for generating image captcha to PNG format
-
-
Constructor Summary
Constructors Constructor Description CaptchaHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
checkAndInvalidate(String key, String value)
Check a captchastatic boolean
checkAndInvalidateJCaptcha(String key, String value)
Check a captchastatic boolean
checkAndInvalidateReCaptcha(String value)
Check a ReCaptcha valuestatic void
cleanOldCaptchas()
Clean the outdated captchasstatic 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 usedstatic void
removeCaptcha(String key)
Remove a captchavoid
service(ServiceManager manager)
-
-
-
Constructor Detail
-
CaptchaHelper
public CaptchaHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getCaptchaType
public static String getCaptchaType()
Retrieve the type of captcha used- Returns:
- The type of captcha.
-
checkAndInvalidate
public static boolean checkAndInvalidate(String key, String value)
Check a captcha- Parameters:
key
- The captcha key. Can be empty or null when using reCaptcha.value
- The value to check- Returns:
true
if the captcha is valid, false otherwise.
-
checkAndInvalidateJCaptcha
public static boolean checkAndInvalidateJCaptcha(String key, String value)
Check a captcha- Parameters:
key
- The keyvalue
- The value to check- Returns:
- The image captcha
-
checkAndInvalidateReCaptcha
public static boolean checkAndInvalidateReCaptcha(String value)
Check a ReCaptcha value- Parameters:
value
- The value to check- Returns:
- True if the captcha is valid.
-
removeCaptcha
public static void removeCaptcha(String key)
Remove a captcha- Parameters:
key
- the key value
-
cleanOldCaptchas
public static void cleanOldCaptchas()
Clean the outdated captchas
-
generateImageCaptcha
public static BufferedImage generateImageCaptcha(String key)
Generate an image captcha to PNG format. The key has to be unique. If you can not give a unique id use generateImageCaptch without the key argument : but this is less secure.- Parameters:
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).- Returns:
- The corresponding image
-
generateImageCaptcha
public static BufferedImage generateImageCaptcha(String key, boolean addNoise, boolean fisheye)
Generate an image captcha to PNG format. The key has to be unique. If you can not give a unique id use generateImageCaptch without the key argument : but this is less secure.- Parameters:
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 image- Returns:
- The corresponding image
-
generateImageCaptcha
public static BufferedImage generateImageCaptcha(String key, Integer color)
Generate an image captcha to PNG format. The key has to be unique, if you cannot generate a key use the other form of the method.- Parameters:
key
- the wanted key. Can not be null. You can use RandomStringUtils.randomAlphanumeric(10) to generates onecolor
- The color for font- Returns:
- The corresponding image
-
generateImageCaptcha
public static BufferedImage generateImageCaptcha(String key, Integer color, boolean addNoise, boolean fisheye)
Generate an image captcha to PNG format. The key has to be unique, if you cannot generate a key use the other form of the method.- Parameters:
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 image- Returns:
- The corresponding image
-
generateImageCaptcha
public static BufferedImage generateImageCaptcha(String key, Integer color, boolean addNoise, boolean fisheye, int width, int height)
Generate an image captcha to PNG format. The key has to be unique, if you cannot generate a key use the other form of the method.- Parameters:
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 height- Returns:
- The corresponding image
-
-