@@ -38,18 +38,17 @@ public static void main(String[] args) throws IOException {
38
38
createAssessment (projectID , recaptchaSiteKey , token , recaptchaAction );
39
39
}
40
40
41
-
42
41
/**
43
42
* Create an assessment to analyze the risk of an UI action.
44
43
*
45
44
* @param projectID : GCloud Project ID
46
45
* @param recaptchaSiteKey : Site key obtained by registering a domain/app to use recaptcha
47
- * services.
46
+ * services.
48
47
* @param token : The token obtained from the client on passing the recaptchaSiteKey.
49
48
* @param recaptchaAction : Action name corresponding to the token.
50
49
*/
51
- public static void createAssessment (String projectID , String recaptchaSiteKey , String token ,
52
- String recaptchaAction )
50
+ public static void createAssessment (
51
+ String projectID , String recaptchaSiteKey , String token , String recaptchaAction )
53
52
throws IOException {
54
53
// Initialize client that will be used to send requests. This client only needs to be created
55
54
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -60,33 +59,36 @@ public static void createAssessment(String projectID, String recaptchaSiteKey, S
60
59
// Specify a name for this assessment.
61
60
String assessmentName = "assessment-name" ;
62
61
// Set the properties of the event to be tracked.
63
- Event event = Event .newBuilder ()
64
- .setSiteKey (recaptchaSiteKey )
65
- .setToken (token )
66
- .build ();
62
+ Event event = Event .newBuilder ().setSiteKey (recaptchaSiteKey ).setToken (token ).build ();
67
63
68
64
// Build the assessment request.
69
- CreateAssessmentRequest createAssessmentRequest = CreateAssessmentRequest .newBuilder ()
70
- .setParent (ProjectName .of (projectID ).toString ())
71
- .setAssessment (Assessment .newBuilder ().setEvent (event ).setName (assessmentName ).build ())
72
- .build ();
65
+ CreateAssessmentRequest createAssessmentRequest =
66
+ CreateAssessmentRequest .newBuilder ()
67
+ .setParent (ProjectName .of (projectID ).toString ())
68
+ .setAssessment (
69
+ Assessment .newBuilder ().setEvent (event ).setName (assessmentName ).build ())
70
+ .build ();
73
71
74
72
Assessment response = client .createAssessment (createAssessmentRequest );
75
73
76
74
// Check if the token is valid.
77
75
if (!response .getTokenProperties ().getValid ()) {
78
- System .out .println ("The CreateAssessment call failed because the token was: " +
79
- response .getTokenProperties ().getInvalidReason ().name ());
76
+ System .out .println (
77
+ "The CreateAssessment call failed because the token was: "
78
+ + response .getTokenProperties ().getInvalidReason ().name ());
80
79
return ;
81
80
}
82
81
83
82
// Check if the expected action was executed.
84
83
if (!response .getTokenProperties ().getAction ().equals (recaptchaAction )) {
85
84
System .out .println (
86
- "The action attribute in reCAPTCHA tag is: " + response .getTokenProperties ()
87
- .getAction ());
88
- System .out .println ("The action attribute in the reCAPTCHA tag " +
89
- "does not match the action (" + recaptchaAction + ") you are expecting to score" );
85
+ "The action attribute in reCAPTCHA tag is: "
86
+ + response .getTokenProperties ().getAction ());
87
+ System .out .println (
88
+ "The action attribute in the reCAPTCHA tag "
89
+ + "does not match the action ("
90
+ + recaptchaAction
91
+ + ") you are expecting to score" );
90
92
return ;
91
93
}
92
94
@@ -102,4 +104,4 @@ public static void createAssessment(String projectID, String recaptchaSiteKey, S
102
104
}
103
105
}
104
106
}
105
- // [END recaptcha_enterprise_create_assessment]
107
+ // [END recaptcha_enterprise_create_assessment]
0 commit comments