diff --git a/recaptcha_enterprise/demosite/src/main/java/app/MainController.java b/recaptcha_enterprise/demosite/src/main/java/app/MainController.java index 565ca563ef1..a514483475f 100644 --- a/recaptcha_enterprise/demosite/src/main/java/app/MainController.java +++ b/recaptcha_enterprise/demosite/src/main/java/app/MainController.java @@ -119,9 +119,8 @@ public static ModelAndView home() { try { // assessmentResponse = CreateAssessment.createAssessment( - CONTEXT.get("project_id"), - CONTEXT.get("site_key"), - jsonData.get("token")); + CONTEXT.get("project_id"), CONTEXT.get("site_key"), + jsonData.get("token"), recaptchaAction); // Check if the token is valid, score is above threshold score and the action equals expected. // Take action based on the result (BAD / NOT_BAD). @@ -172,9 +171,8 @@ public static ModelAndView signup() { try { // assessmentResponse = CreateAssessment.createAssessment( - CONTEXT.get("project_id"), - CONTEXT.get("site_key"), - jsonData.get("token").toString()); + CONTEXT.get("project_id"), CONTEXT.get("site_key"), + jsonData.get("token").toString(), recaptchaAction); // Check if the token is valid, score is above threshold score and the action equals expected. // Take action based on the result (BAD / NOT_BAD). @@ -227,9 +225,8 @@ public static ModelAndView login() { try { // assessmentResponse = CreateAssessment.createAssessment( - CONTEXT.get("project_id"), - CONTEXT.get("site_key"), - jsonData.get("token")); + CONTEXT.get("project_id"), CONTEXT.get("site_key"), + jsonData.get("token"), recaptchaAction); // Check if the token is valid, score is above threshold score and the action equals expected. // Take action based on the result (BAD / NOT_BAD). @@ -282,9 +279,8 @@ public static ModelAndView store() { try { // assessmentResponse = CreateAssessment.createAssessment( - CONTEXT.get("project_id"), - CONTEXT.get("site_key"), - jsonData.get("token").toString()); + CONTEXT.get("project_id"), CONTEXT.get("site_key"), + jsonData.get("token").toString(), recaptchaAction); // Check if the token is valid, score is above threshold score and the action equals expected. // Take action based on the result (BAD / NOT_BAD). @@ -336,9 +332,8 @@ public static ModelAndView comment() { try { // assessmentResponse = CreateAssessment.createAssessment( - CONTEXT.get("project_id"), - CONTEXT.get("site_key"), - jsonData.get("token")); + CONTEXT.get("project_id"), CONTEXT.get("site_key"), + jsonData.get("token"), recaptchaAction); // Check if the token is valid, score is above threshold score and the action equals expected. // Take action based on the result (BAD / NOT_BAD). diff --git a/recaptcha_enterprise/demosite/src/main/java/recaptcha/CreateAssessment.java b/recaptcha_enterprise/demosite/src/main/java/recaptcha/CreateAssessment.java index ae86e88af56..9c6c6720406 100644 --- a/recaptcha_enterprise/demosite/src/main/java/recaptcha/CreateAssessment.java +++ b/recaptcha_enterprise/demosite/src/main/java/recaptcha/CreateAssessment.java @@ -28,22 +28,26 @@ public class CreateAssessment { * Create an assessment to analyze the risk of a UI action. * * @param projectID : Google Cloud Project ID - * @param recaptchaSiteKey : Site key obtained by registering a domain/app to use recaptcha - * services. (score/ checkbox type) - * @param token : The token obtained from the client on passing the recaptchaSiteKey. + * @param recaptchaSiteKey : Site key obtained by registering a domain/app to + * use recaptcha services. (score/ checkbox type) + * @param token : The token obtained from the client on passing the + * recaptchaSiteKey. + * @param expectedAction : The expected action for this type of event. * @return Assessment response. */ - public static Assessment createAssessment( - String projectID, String recaptchaSiteKey, String token) + public static Assessment createAssessment(String projectID, + String recaptchaSiteKey, + String token, String expectedAction) throws Exception { // try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) { // Set the properties of the event to be tracked. Event event = Event.newBuilder() - .setSiteKey(recaptchaSiteKey) - .setToken(token) - .build(); + .setSiteKey(recaptchaSiteKey) + .setToken(token) + .setExpectedAction(expectedAction) + .build(); // Build the assessment request. CreateAssessmentRequest createAssessmentRequest =