org.weborganic.bastille.recaptcha
Class ReCaptcha

java.lang.Object
  extended by org.weborganic.bastille.recaptcha.ReCaptcha

public final class ReCaptcha
extends Object

A simple object encapsulating the ReCaptcha configuration.


Field Summary
static String DEFAULT_HTTP_SERVER
          The default URL to connect to.
static String DEFAULT_HTTPS_SERVER
          The default secure URL to connect to.
static String VERIFY_URL
          The verify URL to use.
 
Method Summary
static ReCaptcha newReCaptcha()
          Creates a new ReCaptcha instance from the Bastille properties.
 String privateKey()
          Returns the private key to connect to the ReCapatcha server.
 String publicKey()
          Returns the public key to connect to the ReCapatcha server..
 String server()
          Returns the URL of the reCaptcha server.
 void toXHTMLForm(XMLWriter xml, String message)
          Writes the form to display the captcha as XHTML.
static ReCaptchaResult verify(ContentRequest req)
          Automatically create a ReCaptcha instance and verify the standard parameters send.
 ReCaptchaResult verify(String remoteAddr, String challenge, String response)
          Invoke the reCaptcha Verify API to check whether the challenge has been passed by the user.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HTTP_SERVER

public static final String DEFAULT_HTTP_SERVER
The default URL to connect to.

See Also:
Constant Field Values

DEFAULT_HTTPS_SERVER

public static final String DEFAULT_HTTPS_SERVER
The default secure URL to connect to.

See Also:
Constant Field Values

VERIFY_URL

public static final String VERIFY_URL
The verify URL to use.

See Also:
Constant Field Values
Method Detail

publicKey

public String publicKey()
Returns the public key to connect to the ReCapatcha server..

Returns:
the public key to connect to the ReCapatcha server..

privateKey

public String privateKey()
Returns the private key to connect to the ReCapatcha server.

Returns:
the private key to connect to the ReCapatcha server..

server

public String server()
Returns the URL of the reCaptcha server.

Returns:
the URL of the reCaptcha server

verify

public ReCaptchaResult verify(String remoteAddr,
                              String challenge,
                              String response)
                       throws ReCaptchaException
Invoke the reCaptcha Verify API to check whether the challenge has been passed by the user.

All three parameters are required by the ReCaptcha server.

Parameters:
remoteAddr - The remote address
challenge - the challenge (supplied by the original ReCaptcha form)
response - The response to the challenge (from the user)
Returns:
The results of the reCaptcha challenge
Throws:
ReCaptchaException - if either argument is null

toXHTMLForm

public void toXHTMLForm(XMLWriter xml,
                        String message)
                 throws IOException
Writes the form to display the captcha as XHTML.

Parameters:
xml - The XML output
message - the error message from the server (may be null)
Throws:
IOException - if thrown while writing the XML

newReCaptcha

public static ReCaptcha newReCaptcha()
                              throws ReCaptchaException
Creates a new ReCaptcha instance from the Bastille properties.

Returns:
a new ReCaptcha instance
Throws:
ReCaptchaException - If the server has not been configured properly

verify

public static ReCaptchaResult verify(ContentRequest req)
                              throws ReCaptchaException
Automatically create a ReCaptcha instance and verify the standard parameters send.

Parameters:
req - The content request.
Returns:
a new ReCaptcha instance
Throws:
ReCaptchaException - If the server has not been configured properly