fix
Leonardo Vannucci
2018-09-18 2bda9e785a1016eedd31b104ce72226fdce05e71
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package it.digione.dg1cloud.recaptcha;
 
import com.fasterxml.jackson.annotation.*;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({
       "success",
       "challenge_ts",
       "hostname",
       "error-codes"
})
public class ReCaptchaResponse {
 
   @JsonProperty("success")
   private boolean success;
 
   @JsonProperty("challenge_ts")
   private Date challengeTs;
 
   @JsonProperty("hostname")
   private String hostname;
 
   @JsonProperty("error-codes")
   private ErrorCode[] errorCodes;
 
   @JsonIgnore
   public boolean hasClientError() {
       ErrorCode[] errors = getErrorCodes();
       if(errors == null) {
           return false;
       }
       for(ErrorCode error : errors) {
           switch(error) {
               case InvalidResponse:
               case MissingResponse:
                   return true;
           case InvalidSecret:
               break;
           case MissingSecret:
               break;
           default:
               break;
           }
       }
       return false;
   }
 
   static enum ErrorCode {
       MissingSecret,     InvalidSecret,
       MissingResponse,   InvalidResponse;
 
       private static Map<String, ErrorCode> errorsMap = new HashMap<>(4);
 
       static {
           errorsMap.put("missing-input-secret",   MissingSecret);
           errorsMap.put("invalid-input-secret",   InvalidSecret);
           errorsMap.put("missing-input-response", MissingResponse);
           errorsMap.put("invalid-input-response", InvalidResponse);
       }
 
       @JsonCreator
       public static ErrorCode forValue(String value) {
           return errorsMap.get(value.toLowerCase());
       }
   }
 
   public boolean isSuccess() {
       return success;
   }
 
   public void setSuccess(boolean success) {
       this.success = success;
   }
 
   public Date getChallengeTs() {
       return challengeTs;
   }
 
   public void setChallengeTs(Date challengeTs) {
       this.challengeTs = challengeTs;
   }
 
   public String getHostname() {
       return hostname;
   }
 
   public void setHostname(String hostname) {
       this.hostname = hostname;
   }
 
   public ErrorCode[] getErrorCodes() {
       return errorCodes;
   }
 
   public void setErrorCodes(ErrorCode[] errorCodes) {
       this.errorCodes = errorCodes;
   }
}