Changeset 32988


Ignore:
Timestamp:
2019-04-05T14:52:41+13:00 (5 years ago)
Author:
kjdon
Message:
  1. added code to match document/HASHxxx/print - goes to a=d&sa=print, for a print version of the doc. 2. added code for humanverify. if humanverify is set for a colleciton, then any links to source docs (and currently any assocfiles - need to fix that) will go via a verify page, where user has to accvept terms and conditions and do a recaptcha
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/URLFilter.java

    r32657 r32988  
    1919import javax.servlet.http.HttpServletRequest;
    2020import javax.servlet.http.HttpServletRequestWrapper;
     21import javax.servlet.http.HttpServletResponse;
    2122
    2223import org.apache.commons.io.FileUtils;
     
    2829import org.greenstone.gsdl3.util.UserContext;
    2930import org.greenstone.gsdl3.util.XMLConverter;
     31import org.greenstone.gsdl3.service.Authentication;
    3032import org.w3c.dom.Document;
    3133import org.w3c.dom.Element;
     
    5254    protected static final String DOCUMENT_PATH = "document";
    5355    protected static final String COLLECTION_PATH = "collection";
    54   protected static final String GROUP_PATH = "group";
     56        protected static final String GROUP_PATH = "group";
    5557    protected static final String PAGE_PATH = "page";
    5658    protected static final String SYSTEM_PATH = "system";
    57   protected static final String BROWSE_PATH = "browse";
    58   protected static final String SEARCH_PATH = "search";
     59        protected static final String BROWSE_PATH = "browse";
     60        protected static final String SEARCH_PATH = "search";
    5961
    6062    protected static final String METADATA_RETRIEVAL_SERVICE = "DocumentMetadataRetrieve";
     
    187189                    Element securityResponse = (Element) GSXML.getChildByTagName(gsRouter.process(securityMessage), GSXML.RESPONSE_ELEM);
    188190                    ArrayList<String> groups = GSXML.getGroupsFromSecurityResponse(securityResponse);
     191                    _logger.debug("security response = "+XMLConverter.getPrettyString(securityResponse));
    189192
    190193                    if (!groups.contains(""))
     
    202205                        if (!found)
    203206                        {
     207                          // this just returns nothing to the browser - get no error or anything, just an empty document
     208                          // can we return an error page??
     209                          String new_url = context.getContextPath()+"/"+ context.getAttribute("LibraryName")+"?a=p&sa=error&c="+collection+"&ec=wrong_group";
     210                          ((HttpServletResponse)response).sendRedirect(new_url);
    204211                            return;
    205212                        }
     213                    }
     214                    // if got here have no groups.
     215                    // do we have human verify thing?
     216                    boolean human_verify = false;
     217                   
     218                    if (!securityResponse.getAttribute("humanVerify").equals("")) {
     219                      // have we already done the test?
     220                      String hmvf_response = gRequest.getParameter("hmvf");
     221                      // hmvf param will be set by form
     222                      if (hmvf_response != null) {
     223                        if (!securityResponse.getAttribute("siteKey").equals("")) {
     224                          String recaptcha_response = gRequest.getParameter("g-recaptcha-response");
     225                          String secret_key = securityResponse.getAttribute("secretKey");
     226                          int result = Authentication.verifyRecaptcha(secret_key, recaptcha_response);
     227                          _logger.debug("recaptcha result code = "+result);
     228                          if (result == Authentication.NO_ERROR) {
     229                        _logger.debug("RECAPTCHA SUCCESS, hopefully going to the document");
     230                       
     231                          } else {
     232                        _logger.error("something went wrong with recaptcha, error="+result);
     233                        _logger.error(Authentication.getErrorKey(result));
     234                        // display error page
     235                        String new_url = context.getContextPath()+"/"+ context.getAttribute("LibraryName")+"?a=p&sa=error&c="+collection+"&ec=recap_fail";
     236                        ((HttpServletResponse)response).sendRedirect(new_url);
     237                       
     238                        return;
     239                          }
     240                        }
     241                       
     242                      } else {
     243                        // hmvf param is not set - we haven't shown them the form yet
     244                        // we need to display the verify page
     245                        String new_url = context.getContextPath()+"/"+ context.getAttribute("LibraryName")+"?a=p&sa=verify&c="+collection+"&url="+url;
     246                        ((HttpServletResponse)response).sendRedirect(new_url);
     247                        return;
     248                      }
    206249                    }
    207250                }
     
    294337                    {
    295338                        gRequest.setParameter(GSParams.DOCUMENT, segments[i + 1]);
    296 
     339                       
    297340                        additionalParameters = new String[] { GSParams.ACTION };
    298341                        defaultParamValues = new String[] { "d" };
     342                        if ((i+2) < segments.length && segments[i+2].equals("print")) {
     343                          gRequest.setParameter(GSParams.SUBACTION, "print");
     344                          gRequest.setParameter("ed", "1");
     345                         
     346                        }
     347                   
    299348                    }
    300349                    //PAGE
Note: See TracChangeset for help on using the changeset viewer.