Class ReCaptchaConfig

java.lang.Object
com.oorian.recaptcha.ReCaptchaConfig

public class ReCaptchaConfig extends Object
Global configuration for Google reCAPTCHA integration.

This class holds the site key, secret key, and version used by all reCAPTCHA components and verification calls in the application. Configure these values once during application startup, typically in your Application.initialize() method.

Usage:


 // In Application.initialize():
 ReCaptchaConfig.setSiteKey("your-site-key");
 ReCaptchaConfig.setSecretKey("your-secret-key");

 // In createHead():
 ReCaptchaConfig.addScript(head);
 
Since:
1.0
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ReCaptchaConfig

      public ReCaptchaConfig()
  • Method Details

    • setSiteKey

      public static void setSiteKey(String siteKey)
      Sets the reCAPTCHA site key (public key).

      The site key is used in the browser to generate verification tokens. Obtain this from the reCAPTCHA admin console.

      Parameters:
      siteKey - the reCAPTCHA v3 site key
    • setSecretKey

      public static void setSecretKey(String secretKey)
      Sets the reCAPTCHA secret key (private key).

      The secret key is used server-side to verify tokens with Google's API. Obtain this from the reCAPTCHA admin console. This key must be kept confidential and never exposed to the client.

      Parameters:
      secretKey - the reCAPTCHA v3 secret key
    • setVersion

      public static void setVersion(ReCaptchaVersion version)
      Sets the reCAPTCHA version to use.

      Defaults to ReCaptchaVersion.V3. Currently only v3 is supported by this library. Setting a deprecated version will have no effect on the script URL.

      Parameters:
      version - the reCAPTCHA version
    • getSiteKey

      public static String getSiteKey()
      Returns the configured site key.
      Returns:
      the reCAPTCHA site key
    • getSecretKey

      public static String getSecretKey()
      Returns the configured secret key.
      Returns:
      the reCAPTCHA secret key
    • getVersion

      public static ReCaptchaVersion getVersion()
      Returns the configured reCAPTCHA version.
      Returns:
      the reCAPTCHA version
    • addScript

      public static void addScript(com.oorian.html.elements.Head head)
      Adds the Google reCAPTCHA script to the page head.

      This method must be called in createHead() for any page that uses the ReCaptcha component. It loads the Google reCAPTCHA JavaScript API with the configured site key.

      Parameters:
      head - the page head element