fiz
Leonardo Vannucci
2018-09-19 a7fea618a7e5c86beb125b72862822780d2cbb2f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package it.digione.dg1cloud.recaptcha;
 
import org.springframework.beans.factory.annotation.Autowired;
 
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
 
public class ReCaptchaConstraintValidator implements ConstraintValidator<ValidReCaptcha, String> {
 
   @Autowired
   private ReCaptchaService reCaptchaService;
 
   @Override
   public void initialize(ValidReCaptcha constraintAnnotation) {
 
   }
 
   @Override
   public boolean isValid(String reCaptchaResponse, ConstraintValidatorContext context) {
 
       if (reCaptchaResponse == null || reCaptchaResponse.isEmpty()){
           return true;
       }
 
       return reCaptchaService.validate(reCaptchaResponse);
   }
 
}