Commit 99c8a6aa authored by Günther Niess's avatar Günther Niess Committed by niess

OF-43: Add reCAPTCHA check for registration via web

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11482 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0e0bf90f
......@@ -47,6 +47,7 @@ Registration Plugin Changelog
<p><b>1.5.0</b> -- December 2, 2009</p>
<ul>
<li>Now requires Openfire 3.6.5.</li>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-43'>OF-43</a>] - Add reCAPTCHA check for registration via web.</li>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-53'>OF-53</a>] - Replace custom logging implementation with a third party library.</li>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-78'>OF-78</a>] - Replaced custom Stringprep with LibIDN.</li>
</ul>
......
......@@ -11,6 +11,10 @@ registration.props.form.enable_email_notification=Enable email registration noti
registration.props.form.enable_welcome_msg=Enable welcome message.
registration.props.form.enable_add_user_to_group=Enable automatically adding of new users to a group.
registration.props.form.enable_web_registration=Enable users to register via a web page at
registration.props.form.enable_recaptcha=Enable reCAPTCHA human check for web page at
registration.props.form.recaptcha_noscript=Enable reCAPTCHA NoScript section for a better compatibility.
registration.props.form.recaptcha_public_key=Public key for reCAPTCHA:
registration.props.form.recaptcha_private_key=Private key for reCAPTCHA:
registration.props.form.save_settings=Save Settings
registration.props.form.registration_contacts=Registration Notification Contacts
registration.props.form.registration_contacts_details=Add or remove contacts to be alerted when a new user registers.
......@@ -54,6 +58,7 @@ registration.sign.up.invalid_email=Invalid email.
registration.sign.up.invalid_password=Invalid password.
registration.sign.up.invalid_match_password=Passwords don't match.
registration.sign.up.invalid_password_confirm=Invalid password confirmation.
registration.sign.up.recaptcha_fail=Invalid reCAPTCHA check.
registration.sign.up.success=New account successfully created.
registration.sign.up.create_account=Create Account
registration.sign.up.username=Username
......
......@@ -49,9 +49,9 @@ import org.xmpp.packet.Message;
* @author Ryan Graham.
*/
public class RegistrationPlugin implements Plugin {
private static final Logger Log = LoggerFactory.getLogger(RegistrationPlugin.class);
private static final Logger Log = LoggerFactory.getLogger(RegistrationPlugin.class);
private static final String URL = "registration/sign-up.jsp";
/**
......@@ -84,6 +84,27 @@ public class RegistrationPlugin implements Plugin {
*/
private static final String WEB_ENABLED = "registration.web.enabled";
/**
* The expected value is a boolean, if true any users will be need to verify its a human at the
* following url http://[SERVER_NAME}:9090/plugins/registration/sign-up.jsp
*/
private static final String RECAPTCHA_ENABLED = "registration.recaptcha.enabled";
/**
* The expected value is a boolean, if true recaptcha uses the noscript tag.
*/
private static final String RECAPTCHA_NOSCRIPT = "registration.recaptcha.noscript";
/**
* The expected value is a String that contains the public key for the recaptcha login.
*/
private static final String RECAPTCHA_PUBLIC_KEY = "registration.recaptcha.key.public";
/**
* The expected value is a String that contains the private key for the recaptcha login.
*/
private static final String RECAPTCHA_PRIVATE_KEY = "registration.recaptcha.key.private";
/**
* The expected value is a comma separated String of usernames who will receive a instant
* message when a new user registers if the property #IM_NOTIFICATION_ENABLED is set to true.
......@@ -254,6 +275,38 @@ public class RegistrationPlugin implements Plugin {
+ JiveGlobals.getXMLProperty("adminConsole.port") + "/plugins/" + URL;
}
public void setReCaptchaEnabled(boolean enable) {
JiveGlobals.setProperty(RECAPTCHA_ENABLED, enable ? "true" : "false");
}
public boolean reCaptchaEnabled() {
return JiveGlobals.getBooleanProperty(RECAPTCHA_ENABLED, false);
}
public void setReCaptchaNoScript(boolean enable) {
JiveGlobals.setProperty(RECAPTCHA_NOSCRIPT, enable ? "true" : "false");
}
public boolean reCaptchaNoScript() {
return JiveGlobals.getBooleanProperty(RECAPTCHA_NOSCRIPT, true);
}
public void setReCaptchaPublicKey(String publicKey) {
JiveGlobals.setProperty(RECAPTCHA_PUBLIC_KEY, publicKey);
}
public String getReCaptchaPublicKey() {
return JiveGlobals.getProperty(RECAPTCHA_PUBLIC_KEY);
}
public void setReCaptchaPrivateKey(String privateKey) {
JiveGlobals.setProperty(RECAPTCHA_PRIVATE_KEY, privateKey);
}
public String getReCaptchaPrivateKey() {
return JiveGlobals.getProperty(RECAPTCHA_PRIVATE_KEY);
}
public void setGroup(String group) {
JiveGlobals.setProperty(REGISTRAION_GROUP, group);
}
......@@ -289,7 +342,7 @@ public class RegistrationPlugin implements Plugin {
}
}
public void userDeleting(User user, Map<String, Object> params) {
public void userDeleting(User user, Map<String, Object> params) {
}
public void userModified(User user, Map<String, Object> params) {
......@@ -370,4 +423,4 @@ public class RegistrationPlugin implements Plugin {
// Must at least match x@x.xx.
return address.matches(".{1,}[@].{1,}[.].{2,}");
}
}
\ No newline at end of file
}
......@@ -32,6 +32,11 @@
boolean groupEnabled = ParamUtils.getBooleanParameter(request, "groupenabled", false);
boolean webEnabled = ParamUtils.getBooleanParameter(request, "webenabled", false);
boolean reCaptchaEnabled = ParamUtils.getBooleanParameter(request, "recaptcha", false);
boolean reCaptchaNoScript = ParamUtils.getBooleanParameter(request, "recaptchanoscript", false);
String reCaptchaPublicKey = ParamUtils.getParameter(request, "recaptchapublickey");
String reCaptchaPrivateKey = ParamUtils.getParameter(request, "recaptchaprivatekey");
String contactIM = ParamUtils.getParameter(request, "contactIM");
boolean addIM = ParamUtils.getBooleanParameter(request, "addIM");
boolean deleteIM = ParamUtils.getBooleanParameter(request, "deleteIM");
......@@ -108,6 +113,10 @@
plugin.setEmailNotificationEnabled(emailEnabled);
plugin.setWelcomeEnabled(welcomeEnabled);
plugin.setWebEnabled(webEnabled);
plugin.setReCaptchaEnabled(reCaptchaEnabled);
plugin.setReCaptchaNoScript(reCaptchaNoScript);
plugin.setReCaptchaPublicKey(reCaptchaPublicKey);
plugin.setReCaptchaPrivateKey(reCaptchaPrivateKey);
if (groupEnabled) {
group = plugin.getGroup();
......@@ -184,6 +193,10 @@
welcomeMessage = plugin.getWelcomeMessage();
group = plugin.getGroup();
header = plugin.getHeader();
reCaptchaEnabled = plugin.reCaptchaEnabled();
reCaptchaNoScript = plugin.reCaptchaNoScript();
reCaptchaPublicKey = plugin.getReCaptchaPublicKey();
reCaptchaPrivateKey = plugin.getReCaptchaPrivateKey();
%>
<html>
......@@ -249,23 +262,41 @@ function addEmailContact() {
<tbody>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="imenabled" <%=(imEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left"><fmt:message key="registration.props.form.enable_im_notification" /></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_im_notification" /></td>
</tr>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="emailenabled" <%=(emailEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left"><fmt:message key="registration.props.form.enable_email_notification" /></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_email_notification" /></td>
</tr>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="welcomeenabled" <%=(welcomeEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left"><fmt:message key="registration.props.form.enable_welcome_msg" /></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_welcome_msg" /></td>
</tr>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="groupenabled" <%=(groupEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left"><fmt:message key="registration.props.form.enable_add_user_to_group" /></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_add_user_to_group" /></td
</tr>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="webenabled" <%=(webEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left"><fmt:message key="registration.props.form.enable_web_registration" /> <%=plugin.webRegistrationAddress() %></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_web_registration" /> <%=plugin.webRegistrationAddress() %></td>
</tr>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="recaptcha" <%=(reCaptchaEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_recaptcha" /> <%=plugin.webRegistrationAddress() %></td>
</tr>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="recaptchanoscript" <%=(reCaptchaNoScript) ? "checked" : "" %>></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.recaptcha_noscript" /></td>
</tr>
<tr>
<td width="1%" align="center" nowrap>&nbsp;</td>
<td width="24%" align="left"><fmt:message key="registration.props.form.recaptcha_public_key" /></td>
<td width="75%" align="left"><input type="text" name="recaptchapublickey" size="40" maxlength="100" value="<%= (reCaptchaPublicKey != null ? reCaptchaPublicKey : "") %>"/></td>
</tr>
<tr>
<td width="1%" align="center" nowrap>&nbsp;</td>
<td width="24%" align="left"><fmt:message key="registration.props.form.recaptcha_private_key" /></td>
<td width="75%" align="left"><input type="text" name="recaptchaprivatekey" size="40" maxlength="100" value="<%= (reCaptchaPrivateKey != null ? reCaptchaPrivateKey : "") %>"/></td>
</tr>
</tbody>
</table>
......
......@@ -11,7 +11,8 @@
org.jivesoftware.util.*,
gnu.inet.encoding.Stringprep,
gnu.inet.encoding.StringprepException,
org.xmpp.packet.JID"
org.xmpp.packet.JID,
net.tanesha.recaptcha.*"
%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
......@@ -31,17 +32,28 @@
</style>
<meta name="decorator" content="none"/>
</head>
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<jsp:useBean id="errors" class="java.util.HashMap" />
<% webManager.init(request, response, session, application, out);
boolean create = request.getParameter("create") != null;
String username = ParamUtils.getParameter(request,"username");
String name = ParamUtils.getParameter(request,"name");
String email = ParamUtils.getParameter(request,"email");
String password = ParamUtils.getParameter(request,"password");
String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm");
String reCaptchaChallenge = ParamUtils.getParameter(request,"recaptcha_challenge_field");
String reCaptchaResponse = ParamUtils.getParameter(request,"recaptcha_response_field");
RegistrationPlugin plugin = (RegistrationPlugin) webManager.getXMPPServer().getPluginManager().getPlugin("registration");
ReCaptcha reCaptcha = null;
if (plugin.reCaptchaEnabled()) {
reCaptcha = ReCaptchaFactory.newReCaptcha(
plugin.getReCaptchaPublicKey(),
plugin.getReCaptchaPrivateKey(),
plugin.reCaptchaNoScript());
}
// Handle a request to create a user:
if (create) {
......@@ -68,6 +80,20 @@
if (password != null && passwordConfirm != null && !password.equals(passwordConfirm)) {
errors.put("passwordMatch","");
}
if (plugin.reCaptchaEnabled()) {
ReCaptchaResponse captchaResponse = null;
try {
captchaResponse = reCaptcha.checkAnswer(
request.getRemoteAddr(),
reCaptchaChallenge,
reCaptchaResponse);
}
catch (Exception e) {
}
if (captchaResponse == null || !captchaResponse.isValid()) {
errors.put("reCaptchaFail","");
}
}
// do a create if there were no errors
if (errors.size() == 0) {
......@@ -86,8 +112,6 @@
}
}
}
RegistrationPlugin plugin = (RegistrationPlugin) webManager.getXMPPServer().getPluginManager().getPlugin("registration");
%>
<body>
......@@ -138,6 +162,8 @@
<fmt:message key="registration.sign.up.invalid_match_password" />
<% } else if (errors.get("passwordConfirm") != null) { %>
<fmt:message key="registration.sign.up.invalid_password_confirm" />
<% } else if (errors.get("reCaptchaFail") != null) { %>
<fmt:message key="registration.sign.up.recaptcha_fail" />
<% } %>
</td>
</tr>
......@@ -219,7 +245,11 @@
</div>
</div>
<% if (reCaptcha != null) { %>
<%= reCaptcha.createRecaptchaHtml(null, null, 0) %>
<% } %>
<input type="submit" name="create" value="<fmt:message key="registration.sign.up.create_account" />">
</form>
<script language="JavaScript" type="text/javascript">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment