Search in sources :

Example 6 with RecaptchaEnterpriseServiceClient

use of com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient in project java-recaptchaenterprise by googleapis.

the class CreateSiteKey method createSiteKey.

/**
 * Create reCAPTCHA Site key which binds a domain name to a unique key.
 *
 * @param projectID : GCloud Project ID.
 * @param domainName : Specify the domain name in which the reCAPTCHA should be activated.
 */
public static String createSiteKey(String projectID, String domainName) throws IOException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Set the type of reCAPTCHA to be displayed.
        // For different types, see: https://cloud.google.com/recaptcha-enterprise/docs/keys
        Key scoreKey = Key.newBuilder().setDisplayName("any_descriptive_name_for_the_key").setWebSettings(WebKeySettings.newBuilder().addAllowedDomains(domainName).setAllowAmpTraffic(false).setIntegrationType(IntegrationType.SCORE).build()).build();
        CreateKeyRequest createKeyRequest = CreateKeyRequest.newBuilder().setParent(ProjectName.of(projectID).toString()).setKey(scoreKey).build();
        // Get the name of the created reCAPTCHA site key.
        Key response = client.createKey(createKeyRequest);
        String keyName = response.getName();
        String recaptchaSiteKey = keyName.substring(keyName.lastIndexOf("/") + 1);
        System.out.println("reCAPTCHA Site key created successfully. Site Key: " + recaptchaSiteKey);
        return recaptchaSiteKey;
    }
}
Also used : CreateKeyRequest(com.google.recaptchaenterprise.v1.CreateKeyRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 7 with RecaptchaEnterpriseServiceClient

use of com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient in project java-recaptchaenterprise by googleapis.

the class DeleteSiteKey method deleteSiteKey.

/**
 * Delete the given reCAPTCHA site key present under the project ID.
 *
 * @param projectID: GCloud Project ID.
 * @param recaptchaSiteKey: Specify the site key to be deleted.
 */
public static void deleteSiteKey(String projectID, String recaptchaSiteKey) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Set the project ID and reCAPTCHA site key.
        DeleteKeyRequest deleteKeyRequest = DeleteKeyRequest.newBuilder().setName(KeyName.of(projectID, recaptchaSiteKey).toString()).build();
        client.deleteKeyCallable().futureCall(deleteKeyRequest).get(5, TimeUnit.SECONDS);
        System.out.println("reCAPTCHA Site key successfully deleted !");
    }
}
Also used : DeleteKeyRequest(com.google.recaptchaenterprise.v1.DeleteKeyRequest) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 8 with RecaptchaEnterpriseServiceClient

use of com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient in project java-recaptchaenterprise by googleapis.

the class GetSiteKey method getSiteKey.

/**
 * Get the reCAPTCHA site key present under the project ID.
 *
 * @param projectID: GCloud Project ID.
 * @param recaptchaSiteKey: Specify the site key to get the details.
 */
public static void getSiteKey(String projectID, String recaptchaSiteKey) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Construct the "GetSiteKey" request.
        GetKeyRequest getKeyRequest = GetKeyRequest.newBuilder().setName(KeyName.of(projectID, recaptchaSiteKey).toString()).build();
        // Wait for the operation to complete.
        ApiFuture<Key> futureCall = client.getKeyCallable().futureCall(getKeyRequest);
        Key key = futureCall.get(5, TimeUnit.SECONDS);
        System.out.println("Successfully obtained the key !" + key.getName());
    }
}
Also used : GetKeyRequest(com.google.recaptchaenterprise.v1.GetKeyRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 9 with RecaptchaEnterpriseServiceClient

use of com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient in project java-recaptchaenterprise by googleapis.

the class ListSiteKeys method listSiteKeys.

/**
 * List all keys present under the given project ID.
 *
 * @param projectID : GCloud Project ID.
 */
public static ListKeysPagedResponse listSiteKeys(String projectID) throws IOException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Set the project ID to list the keys present in it.
        ListKeysRequest listKeysRequest = ListKeysRequest.newBuilder().setParent(ProjectName.of(projectID).toString()).build();
        ListKeysPagedResponse response = client.listKeys(listKeysRequest);
        System.out.println("Listing reCAPTCHA site keys: ");
        for (Key key : response.iterateAll()) {
            System.out.println(key.getName());
        }
        return response;
    }
}
Also used : ListKeysPagedResponse(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse) ListKeysRequest(com.google.recaptchaenterprise.v1.ListKeysRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Aggregations

RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)9 Key (com.google.recaptchaenterprise.v1.Key)5 GetKeyRequest (com.google.recaptchaenterprise.v1.GetKeyRequest)2 ListKeysPagedResponse (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse)1 AnnotateAssessmentRequest (com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest)1 AnnotateAssessmentResponse (com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse)1 Assessment (com.google.recaptchaenterprise.v1.Assessment)1 CreateAssessmentRequest (com.google.recaptchaenterprise.v1.CreateAssessmentRequest)1 CreateKeyRequest (com.google.recaptchaenterprise.v1.CreateKeyRequest)1 DeleteKeyRequest (com.google.recaptchaenterprise.v1.DeleteKeyRequest)1 Event (com.google.recaptchaenterprise.v1.Event)1 GetMetricsRequest (com.google.recaptchaenterprise.v1.GetMetricsRequest)1 ListKeysRequest (com.google.recaptchaenterprise.v1.ListKeysRequest)1 Metrics (com.google.recaptchaenterprise.v1.Metrics)1 MigrateKeyRequest (com.google.recaptchaenterprise.v1.MigrateKeyRequest)1 ClassificationReason (com.google.recaptchaenterprise.v1.RiskAnalysis.ClassificationReason)1 ScoreMetrics (com.google.recaptchaenterprise.v1.ScoreMetrics)1 UpdateKeyRequest (com.google.recaptchaenterprise.v1.UpdateKeyRequest)1