@ Nonnull public static ESuccess check ( @ Nonnull @ Nonempty final String sServerSideKey , @ Nullable final String sReCaptchaResponse ) { ValueEnforcer . notEmpty ( sServerSideKey , "ServerSideKey" ) ; if ( StringHelper . hasNoText ( sReCaptchaResponse ) ) return ESuccess . SUCCESS ; final HttpClientFactory aHCFactory = new HttpClientFactory ( ) ; // For proxy etc aHCFactory . setUseSystemProperties ( true ) ; try ( HttpClientManager aMgr = new HttpClientManager ( aHCFactory ) ) { final HttpPost aPost = new HttpPost ( new SimpleURL ( "https://www.google.com/recaptcha/api/siteverify" ) . add ( "secret" , sServerSideKey ) . add ( "response" , sReCaptchaResponse ) . getAsURI ( ) ) ; final ResponseHandlerJson aRH = new ResponseHandlerJson ( ) ; final IJson aJson = aMgr . execute ( aPost , aRH ) ; if ( aJson != null && aJson . isObject ( ) ) { final boolean bSuccess = aJson . getAsObject ( ) . getAsBoolean ( "success" , false ) ; if ( GlobalDebug . isDebugMode ( ) ) LOGGER . info ( "ReCpatcha Response for '" + sReCaptchaResponse + "': " + aJson . getAsJsonString ( ) ) ; return ESuccess . valueOf ( bSuccess ) ; } } catch ( final IOException ex ) { LOGGER . warn ( "Error checking ReCaptcha response" , ex ) ; } return ESuccess . FAILURE ; }
Check if the response of a RecCaptcha is valid or not .