Commit 47e334dec858f897d1237de5168992a6c8707d0a

Authored by Tiago Guimarães
1 parent d2753b9401
Exists in DSpace52++

Recaptcha is an "opt-in"

Keys are now in the dspace.cfg
dspace-api/src/main/java/pt/uminho/sdum/utils/VerifyRecaptcha.java
1 1 package pt.uminho.sdum.utils;
2 2  
3 3  
  4 +import org.dspace.core.ConfigurationManager;
  5 +
4 6 import java.io.BufferedReader;
5 7 import java.io.DataOutputStream;
6 8 import java.io.IOException;
... ... @@ -16,10 +18,13 @@ import javax.net.ssl.HttpsURLConnection;
16 18 public class VerifyRecaptcha {
17 19  
18 20 public static final String url = "https://www.google.com/recaptcha/api/siteverify";
19   - private static final String secret = "6LfOliQTAAAAAO3gKRe5J-rNfG7DSHbdua71R57h";
  21 + private static final String secret = ConfigurationManager.getProperty("rcaap.google.recaptcha.secret");
20 22 private final static String USER_AGENT = "Mozilla/5.0";
21 23  
22 24 public static boolean verify(String gRecaptchaResponse) throws IOException {
  25 + if(secret==null || secret.equals(""))
  26 + return true;
  27 +
23 28 if (gRecaptchaResponse == null || "".equals(gRecaptchaResponse)) {
24 29 return false;
25 30 }
... ...
dspace-jspui/src/main/webapp/requestItem/request-form.jsp
... ... @@ -22,6 +22,7 @@
22 22 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
23 23  
24 24 <%@ page import="org.dspace.app.webui.servlet.RequestItemServlet"%>
  25 +<%@ page import="org.dspace.core.ConfigurationManager"%>
25 26 <%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %>
26 27 <script src='https://www.google.com/recaptcha/api.js'></script>
27 28  
... ... @@ -105,7 +106,16 @@
105 106 <input type="hidden" name="handle" value='<%= handle %>' />
106 107 <input type="hidden" name="bitstream-id" value='<%= bitstream_id %>' />
107 108 <input type="hidden" name="step" value="<%=RequestItemServlet.ENTER_FORM_PAGE %>" />
108   - <div align="right" class="g-recaptcha" data-sitekey="6LfOliQTAAAAALClMSQsWexcm9Dr2dgsCytkAePl"></div>
  109 + <%
  110 + String key = ConfigurationManager.getProperty("rcaap.google.recaptcha.sitekey");
  111 + if (key != null && !key.equals(""))
  112 + {
  113 + %>
  114 +
  115 + <div align="right" class="g-recaptcha" data-sitekey="<%=key%>"></div>
  116 + <%
  117 + }
  118 + %>
109 119 <div class="btn btn-group col-md-4 pull-right row">
110 120 <a class="btn btn-default col-md-6" href="<%=request.getContextPath()%>/handle/<%=handle %>"><fmt:message key="jsp.request.item.request-form.cancel" /></a>
111 121 <button type="submit" name="submit" class="btn btn-primary col-md-6" value="true"><fmt:message key="jsp.request.item.request-form.go"/></button>
... ...
dspace/config/dspace.cfg
... ... @@ -2289,3 +2289,7 @@ sharing.degois.class = pt.keep.dspace.sharing.app.DegoisSharing
2289 2289  
2290 2290 ############## RENATES URI
2291 2291 renatesURI = http://renates.dgeec.mec.pt/ws/renatesws.asmx/Tese
  2292 +
  2293 +##############Google Recaptcha
  2294 +rcaap.google.recaptcha.secret =
  2295 +rcaap.google.recaptcha.sitekey =
... ...