Commit b1064ce4 authored by Gugli's avatar Gugli Committed by Guus der Kinderen

Now able to set a default privacy list at user creation. (#701)

parent 66eb733e
......@@ -44,6 +44,10 @@
Registration Plugin Changelog
</h1>
<p><b>1.7.1</b> -- December 12, 2016</p>
<ul>
<li>Add default Privacy List for new users.</li>
</ul>
<p><b>1.7.0</b> -- October 12, 2015</p>
<ul>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-953'>OF-953</a>] - Updated JSP libraries.</li>
......
......@@ -5,8 +5,8 @@
<name>Registration</name>
<description>Performs various actions whenever a new user account is created.</description>
<author>Ryan Graham</author>
<version>1.7.0</version>
<date>10/12/2015</date>
<version>1.7.1</version>
<date>12/12/2016</date>
<minServerVersion>4.0.0</minServerVersion>
<adminconsole>
......
......@@ -67,7 +67,22 @@ The registration plugin has three items that can be configured:
notify them whenever a new user registers.</li>
<li>Welcome Message - A message that will be sent to a user when they first register.</li>
<li>Default Group - A group that all users will be added to when they first register.</li>
<li>Web Page Registration - Allows users to create accounts via a web page.
<li>Web Page Registration - Allows users to create accounts via a web page.</li>
<li>Default Privacy List - A privacy list added and set as default for all users when they register.</li>
<h2>Default Privacy List</h2>
<p>The format used is an XML that should look like :
<pre><code>&lt;list&gt;
&lt;item action="deny" order="100" type="subscription" value="none"&gt;
&lt;message/&gt;
&lt;presence-in/&gt;
&lt;presence-out/&gt;
&lt;/item&gt;
&lt;/list&gt;
</code></pre>
The enclosing list tag is needed, but none of its attributes are read. Inside it you can have multiple items.
</p>
</li>
<h2>Using the Plugin</h2>
<p>
......
......@@ -10,6 +10,7 @@ registration.props.form.enable_im_notification=Enable instant message registrati
registration.props.form.enable_email_notification=Enable email registration notification.
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_default_privacy_list=Enable automatically setting default Privacy List to new users
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.
......@@ -46,6 +47,12 @@ registration.props.form.sign_up_details=Enter the text that will be displayed at
registration.props.form.sign_up_saved=Header saved successfully.
registration.props.form.sign_up_missing=Please enter a header.
registration.props.form.sign_up_save=Save Header
registration.props.form.privacy_list=Default Privacy List
registration.props.form.privacy_list_details=Enter the Privacy List that will be used as a default for all new users.
registration.props.form.privacy_list_saved=Default Privacy List saved successfully.
registration.props.form.privacy_list_name_invalid=Invalid Privacy List name
registration.props.form.privacy_list_invalid=Invalid Privacy List
registration.props.form.default_privacy_list_save=Save Default Privacy List
registration.sign.up.title=Jive Openfire Web Registration
registration.sign.up.unavailable=This service is currently unavailable.
......
......@@ -25,6 +25,10 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.jivesoftware.admin.AuthCheckFilter;
import org.jivesoftware.openfire.MessageRouter;
import org.jivesoftware.openfire.XMPPServer;
......@@ -36,6 +40,8 @@ import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.privacy.PrivacyList;
import org.jivesoftware.openfire.privacy.PrivacyListManager;
import org.jivesoftware.util.EmailService;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
......@@ -78,6 +84,12 @@ public class RegistrationPlugin implements Plugin {
*/
private static final String GROUP_ENABLED = "registration.group.enabled";
/**
* The expected value is a boolean, if true any user who registers will have a Default
* privacy list specified in the property #REGISTRAION_PRIVACYLIST. The default value is false.
*/
private static final String PRIVACYLIST_ENABLED = "registration.privacylist.enabled";
/**
* The expected value is a boolean, if true any users will be able to register at the following
* url http://[SERVER_NAME}:9090/plugins/registration/sign-up.jsp
......@@ -129,6 +141,18 @@ public class RegistrationPlugin implements Plugin {
*/
private static final String REGISTRAION_GROUP = "registration.group";
/**
* The expected value is a String that contains the XML contents of the default
* privacy list, if the property #PRIVACYLIST_ENABLED is set to true.
*/
private static final String REGISTRAION_PRIVACYLIST = "registration.privacylist";
/**
* The expected value is a String that contains the name of the default
* privacy list, if the property #PRIVACYLIST_ENABLED is set to true.
*/
private static final String REGISTRAION_PRIVACYLIST_NAME = "registration.privacylist.name";
/**
* The expected value is a String that contains the text that will be displayed in the header
* of the sign-up.jsp, if the property #WEB_ENABLED is set to true.
......@@ -140,6 +164,8 @@ public class RegistrationPlugin implements Plugin {
private String serverName;
private JID serverAddress;
private MessageRouter router;
private boolean privacyListCacheIsSet = false;
private Element privacyListCache = null;
private List<String> imContacts = new ArrayList<String>();
private List<String> emailContacts = new ArrayList<String>();
......@@ -261,6 +287,13 @@ public class RegistrationPlugin implements Plugin {
public boolean groupEnabled() {
return JiveGlobals.getBooleanProperty(GROUP_ENABLED, false);
}
public void setPrivacyListEnabled(boolean enable) {
JiveGlobals.setProperty(PRIVACYLIST_ENABLED, enable ? "true" : "false");
}
public boolean privacyListEnabled() {
return JiveGlobals.getBooleanProperty(PRIVACYLIST_ENABLED, false);
}
public void setWebEnabled(boolean enable) {
JiveGlobals.setProperty(WEB_ENABLED, enable ? "true" : "false");
......@@ -315,6 +348,23 @@ public class RegistrationPlugin implements Plugin {
return JiveGlobals.getProperty(REGISTRAION_GROUP);
}
public void setPrivacyList(String privacyList) {
JiveGlobals.setProperty(REGISTRAION_PRIVACYLIST, privacyList);
privacyListCacheIsSet = false;
}
public String getPrivacyList() {
return JiveGlobals.getProperty(REGISTRAION_PRIVACYLIST);
}
public void setPrivacyListName(String privacyListName) {
JiveGlobals.setProperty(REGISTRAION_PRIVACYLIST_NAME, privacyListName);
}
public String getPrivacyListName() {
return JiveGlobals.getProperty(REGISTRAION_PRIVACYLIST_NAME);
}
public void setHeader(String message) {
JiveGlobals.setProperty(HEADER, message);
}
......@@ -325,6 +375,11 @@ public class RegistrationPlugin implements Plugin {
private class RegistrationUserEventListener implements UserEventListener {
public void userCreated(User user, Map<String, Object> params) {
if (Log.isDebugEnabled()) {
Log.debug("Registration plugin : registering new user");
}
if (imNotificationEnabled()) {
sendIMNotificatonMessage(user);
}
......@@ -340,6 +395,10 @@ public class RegistrationPlugin implements Plugin {
if (groupEnabled()) {
addUserToGroup(user);
}
if (privacyListEnabled()) {
addDefaultPrivacyList(user);
}
}
public void userDeleting(User user, Map<String, Object> params) {
......@@ -399,6 +458,34 @@ public class RegistrationPlugin implements Plugin {
Log.error(e.getMessage(), e);
}
}
private void addDefaultPrivacyList(User user) {
if (Log.isDebugEnabled()) {
Log.debug("Registration plugin : adding default privacy list.");
Log.debug("\tName = "+getPrivacyListName());
Log.debug("\tContent = "+getPrivacyList());
}
if(!privacyListCacheIsSet) {
privacyListCacheIsSet = true;
try {
Document document = DocumentHelper.parseText(getPrivacyList());
privacyListCache = document.getRootElement();
}
catch (DocumentException e) {
Log.error(e.getMessage(), e);
}
if(privacyListCache == null) {
Log.error("registration.privacylist can not be parsed into a valid privacy list");
}
}
if(privacyListCache != null) {
PrivacyListManager privacyListManager = PrivacyListManager.getInstance();
PrivacyList newPrivacyList = privacyListManager.createPrivacyList(user.getUsername(), getPrivacyListName(), privacyListCache);
privacyListManager.changeDefaultList(user.getUsername(), newPrivacyList, null);
}
}
}
private String propPrep(Collection<String> props) {
......
......@@ -33,6 +33,7 @@
boolean saveWelcome = request.getParameter("savemessage") != null;
boolean saveGroup = request.getParameter("savegroup") != null;
boolean saveHeader = request.getParameter("saveheader") != null;
boolean savePrivacyList = request.getParameter("saveprivacylist") != null;
boolean imEnabled = ParamUtils.getBooleanParameter(request, "imenabled", false);
boolean emailEnabled = ParamUtils.getBooleanParameter(request, "emailenabled", false);
......@@ -57,7 +58,11 @@
String group = ParamUtils.getParameter(request, "groupname");
String header = ParamUtils.getParameter(request, "header");
boolean privacyListEnabled = ParamUtils.getBooleanParameter(request, "privacylistenabled", false);
String privacyList = ParamUtils.getParameter(request, "privacylist");
String privacyListName = ParamUtils.getParameter(request, "privacylistname");
RegistrationPlugin plugin = (RegistrationPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("registration");
Map<String, String> errors = new HashMap<String, String>();
......@@ -125,6 +130,7 @@
plugin.setReCaptchaNoScript(reCaptchaNoScript);
plugin.setReCaptchaPublicKey(reCaptchaPublicKey);
plugin.setReCaptchaPrivateKey(reCaptchaPrivateKey);
plugin.setPrivacyListEnabled(privacyListEnabled);
if (groupEnabled) {
group = plugin.getGroup();
......@@ -192,15 +198,31 @@
}
}
if (savePrivacyList) {
if (privacyList == null || privacyList.trim().length() < 1) {
errors.put("invalidPrivacyList", "invalidPrivacyList");
} else if (privacyListName == null || privacyListName.trim().length() < 1) {
errors.put("invalidPrivacyListName", "invalidPrivacyListName");
} else {
plugin.setPrivacyListName(privacyListName);
plugin.setPrivacyList(privacyList);
response.sendRedirect("registration-props-form.jsp?privacyListSaved=true");
return;
}
}
imEnabled = plugin.imNotificationEnabled();
emailEnabled = plugin.emailNotificationEnabled();
welcomeEnabled = plugin.welcomeEnabled();
groupEnabled = plugin.groupEnabled();
webEnabled = plugin.webEnabled();
privacyListEnabled = plugin.privacyListEnabled();
welcomeMessage = plugin.getWelcomeMessage();
group = plugin.getGroup();
header = plugin.getHeader();
privacyListName = plugin.getPrivacyListName();
privacyList = plugin.getPrivacyList();
reCaptchaEnabled = plugin.reCaptchaEnabled();
reCaptchaNoScript = plugin.reCaptchaNoScript();
reCaptchaPublicKey = plugin.getReCaptchaPublicKey();
......@@ -284,6 +306,10 @@ function addEmailContact() {
<td width="1%" align="center" nowrap><input type="checkbox" name="groupenabled" <%=(groupEnabled) ? "checked" : "" %>></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="privacylistenabled" <%=(privacyListEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_default_privacy_list" /></td>
</tr>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="webenabled" <%=(webEnabled) ? "checked" : "" %>></td>
<td width="99%" align="left" colspan="2"><fmt:message key="registration.props.form.enable_web_registration" /> <%=plugin.webRegistrationAddress() %></td>
......@@ -554,6 +580,7 @@ function addEmailContact() {
<% if (errors.containsKey("groupNotFound")) { %>
<span class="jive-error-text"><br><fmt:message key="registration.props.form.default_group_invalid" /></span>
<% } %>
</td>
</tr>
</tbody>
</table>
......@@ -562,6 +589,53 @@ function addEmailContact() {
<input type="submit" value="<fmt:message key="registration.props.form.default_group_save" />"/>
</div>
</form>
<br>
<form action="registration-props-form.jsp?saveprivacylist=true" method="post">
<div class="jive-contentBoxHeader"><fmt:message key="registration.props.form.privacy_list" /></div>
<div class="jive-contentBox">
<p><fmt:message key="registration.props.form.privacy_list_details" /></p>
<% if (ParamUtils.getBooleanParameter(request, "privacyListSaved")) { %>
<div class="jive-success">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0"></td>
<td class="jive-icon-label"><fmt:message key="registration.props.form.privacy_list_saved" /></td>
</tr>
</tbody>
</table>
</div>
<% } %>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="15%" valign="top">Default Privacy List Name:</td>
<td width="85%"><input type="text" name="privacylistname" size="30" maxlength="100" value="<%= (privacyListName != null ? privacyListName : "") %>"/>
<% if (errors.containsKey("invalidPrivacyListName")) { %>
<span class="jive-error-text"><br><fmt:message key="registration.props.form.privacy_list_name_invalid" /></span>
<% } %>
</td>
</tr>
<tr>
<td width="15%" valign="top">Default Privacy List:</td>
<td width="85%"><textarea cols="45" rows="5" wrap="virtual" name="privacylist"><%= (privacyList != null ? privacyList : "") %></textarea>
<% if (errors.containsKey("invalidPrivacyList")) { %>
<span class="jive-error-text"><br><fmt:message key="registration.props.form.privacy_list_invalid" /></span>
<% } %>
</td>
</tr>
</tbody>
</table>
<br>
<input type="submit" value="<fmt:message key="registration.props.form.default_privacy_list_save" />"/>
</div>
</form>
<br>
......
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