Package org.ametys.core.captcha
Class CaptchaHelper
java.lang.Object
org.ametys.core.captcha.CaptchaHelper
- All Implemented Interfaces:
Serviceable
Helper for generating image captcha to PNG format
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkAndInvalidate
(String key, String value) Check a captchastatic boolean
checkAndInvalidateJCaptcha
(String key, String value) Check a captchastatic boolean
Check a ReCaptcha valuestatic void
Clean the outdated captchasstatic BufferedImage
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
Retrieve the type of captcha usedstatic void
removeCaptcha
(String key) Remove a captchavoid
service
(ServiceManager manager)
-
Constructor Details
-
CaptchaHelper
public CaptchaHelper()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getCaptchaType
Retrieve the type of captcha used- Returns:
- The type of captcha.
-
checkAndInvalidate
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
Check a captcha- Parameters:
key
- The keyvalue
- The value to check- Returns:
- The image captcha
-
checkAndInvalidateReCaptcha
Check a ReCaptcha value- Parameters:
value
- The value to check- Returns:
- True if the captcha is valid.
-
removeCaptcha
Remove a captcha- Parameters:
key
- the key value
-
cleanOldCaptchas
Clean the outdated captchas -
generateImageCaptcha
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
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
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
-