Changeset 25725


Ignore:
Timestamp:
2012-05-31T13:56:53+12:00 (12 years ago)
Author:
sjm84
Message:

An attempt at fixing the registration problem for systems behind a firewall that does not let them access google services

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java

    r25722 r25725  
    412412            newPassword = hashPassword(newPassword);
    413413
    414             if (_recaptchaPrivateKey != null)
     414            if (_recaptchaPrivateKey != null && _recaptchaPrivateKey.length() > 0)
    415415            {
    416416                ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
    417417                reCaptcha.setPrivateKey(_recaptchaPrivateKey);
    418418
    419                 String challenge = (String) paramMap.get("recaptcha_challenge_field");
    420                 String uResponse = (String) paramMap.get("recaptcha_response_field");
    421 
    422                 if (challenge == null || uResponse == null)
    423                 {
    424                     serviceNode.setAttribute("operation", REGISTER);
    425                     GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_CAPTCHA_MISSING));
    426                     return result;
    427                 }
    428 
    429                 ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), challenge, uResponse);
    430 
    431                 if (!reCaptchaResponse.isValid())
    432                 {
    433                     serviceNode.setAttribute("operation", REGISTER);
    434                     GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_CAPTCHA_DOES_NOT_MATCH));
    435                     return result;
     419                try
     420                {
     421                    //If this line throws an exception then we'll assume the user has problems with their firewall
     422                    reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), "", "");
     423
     424                    String challenge = (String) paramMap.get("recaptcha_challenge_field");
     425                    String uResponse = (String) paramMap.get("recaptcha_response_field");
     426
     427                    if (challenge == null || uResponse == null)
     428                    {
     429                        serviceNode.setAttribute("operation", REGISTER);
     430                        GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_CAPTCHA_MISSING));
     431                        return result;
     432                    }
     433
     434                    ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), challenge, uResponse);
     435
     436                    if (!reCaptchaResponse.isValid())
     437                    {
     438                        serviceNode.setAttribute("operation", REGISTER);
     439                        GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_CAPTCHA_DOES_NOT_MATCH));
     440                        return result;
     441                    }
     442                }
     443                catch (Exception ex)
     444                {
    436445                }
    437446            }
     
    637646        else if (op.equals(REGISTER))
    638647        {
    639             try
    640             {
    641                 ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
    642                 reCaptcha.setPrivateKey(_recaptchaPrivateKey);
    643                 reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), "", "");
    644             }
    645             catch(Exception ex)
    646             {
    647                 return result;
     648            if (_recaptchaPrivateKey != null && _recaptchaPrivateKey.length() > 0)
     649            {
     650                try
     651                {
     652                    ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
     653                    reCaptcha.setPrivateKey(_recaptchaPrivateKey);
     654                    reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), "", "");
     655                }
     656                catch (Exception ex)
     657                {
     658                    return result;
     659                }
    648660            }
    649661
Note: See TracChangeset for help on using the changeset viewer.