Commit 8e178247 authored by dwd's avatar dwd

Merge pull request #21 from meneo/master

Plugin: user service - add new request type: grouplist & usergrouplist 
parents 40eb0f27 29a52dea
...@@ -43,6 +43,10 @@ ...@@ -43,6 +43,10 @@
<h1> <h1>
User Service Plugin Changelog User Service Plugin Changelog
</h1> </h1>
<p><b>1.4.4</b> -- May 5th, 2014</p>
<ul>
<li>Added new requests grouplist and usergrouplist</li>
</ul>
<p><b>1.4.3</b> -- May 5th, 2014</p> <p><b>1.4.3</b> -- May 5th, 2014</p>
<ul> <ul>
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<name>User Service</name> <name>User Service</name>
<description>Allows administration of users via HTTP requests.</description> <description>Allows administration of users via HTTP requests.</description>
<author>Justin Hunt</author> <author>Justin Hunt</author>
<version>1.4.3</version> <version>1.4.4</version>
<date>05/05/2014</date> <date>26/05/2014</date>
<minServerVersion>3.9.0</minServerVersion> <minServerVersion>3.9.0</minServerVersion>
<adminconsole> <adminconsole>
......
...@@ -95,7 +95,7 @@ The following parameters can be passed into the request:<p> ...@@ -95,7 +95,7 @@ The following parameters can be passed into the request:<p>
</tr> </tr>
<tr> <tr>
<td class="name">type</td><td>Required</td><td>The admin service required. <td class="name">type</td><td>Required</td><td>The admin service required.
Possible values are 'add', 'delete', 'update', 'enable', 'disable', 'add_roster', 'update_roster', 'delete_roster'.</td> Possible values are 'add', 'delete', 'update', 'enable', 'disable', 'add_roster', 'update_roster', 'delete_roster', 'grouplist', 'usergrouplist'.</td>
</tr> </tr>
<tr> <tr>
<td class="name">secret</td><td>Required</td> <td class="name">secret</td><td>Required</td>
...@@ -240,6 +240,37 @@ http://example.com:9090/plugins/userService/userservice?type=delete_roster&secre ...@@ -240,6 +240,37 @@ http://example.com:9090/plugins/userService/userservice?type=delete_roster&secre
</form> </form>
</ul> </ul>
The following example gets all groups
<ul>
<form>
<textarea cols=65 rows=6 wrap=virtual>
http://example.com:9090/plugins/userService/userservice?type=grouplist&secret=bigsecret
Which replies an XML group list formatted like this:
<result>
<groupname>group1</groupname>
<groupname>group2</groupname>
</result>
</textarea>
</form>
</ul>
The following example gets all groups for a specific user
<ul>
<form>
<textarea cols=65 rows=6 wrap=virtual>
http://example.com:9090/plugins/userService/userservice?type=usergrouplist&secret=bigsecret&username=kafka
Which replies an XML group list formatted like this:
<result>
<groupname>usergroup1</groupname>
<groupname>usergroup2</groupname>
</result>
</textarea>
</form>
</ul>
<br><br> <br><br>
* When sending double characters (Chinese/Japanese/Korean etc) you should URLEncode the string as utf8.<br> * When sending double characters (Chinese/Japanese/Korean etc) you should URLEncode the string as utf8.<br>
In Java this is done like this<br> In Java this is done like this<br>
...@@ -250,7 +281,7 @@ URLEncoder.encode(username, "UTF-8")); ...@@ -250,7 +281,7 @@ URLEncoder.encode(username, "UTF-8"));
<h2>Server Reply</h2> <h2>Server Reply</h2>
The server will reply to all User Service requests with an XML result page. The server will reply to all User Service requests with an XML result page.
If the request was processed successfully the return will be a "result" element with a text body of "OK". If the request was processed successfully the return will be a "result" element with a text body of "OK", or an XML grouplist formatted like in the example for "grouplist" and "usergrouplist" above.
If the request was unsuccessful, the return will be an "error" element with a text body of one of the following error strings. If the request was unsuccessful, the return will be an "error" element with a text body of one of the following error strings.
<p> <p>
......
...@@ -328,6 +328,35 @@ public class UserServicePlugin implements Plugin, PropertyEventListener { ...@@ -328,6 +328,35 @@ public class UserServicePlugin implements Plugin, PropertyEventListener {
return userManager.getUser(targetJID.getNode()); return userManager.getUser(targetJID.getNode());
} }
/**
* Returns all group names or an empty collection.
*
*/
public Collection<String> getAllGroups(){
Collection<Group> groups = GroupManager.getInstance().getGroups();
Collection<String> groupNames = new ArrayList<String>();
for(Group group : groups)
{
groupNames.add(group.getName());
}
return groupNames;
}
/**
* Returns all group names or an empty collection for specific user
*
*/
public Collection<String> getUserGroups(String username) throws UserNotFoundException{
User user = getUser(username);
Collection<Group> groups = GroupManager.getInstance().getGroups(user);
Collection<String> groupNames = new ArrayList<String>();
for(Group group : groups)
{
groupNames.add(group.getName());
}
return groupNames;
}
/** /**
* Returns the secret key that only valid requests should know. * Returns the secret key that only valid requests should know.
* *
......
...@@ -120,7 +120,7 @@ public class UserServiceServlet extends HttpServlet { ...@@ -120,7 +120,7 @@ public class UserServiceServlet extends HttpServlet {
} }
// Some checking is required on the username // Some checking is required on the username
if (username == null){ if (username == null && !"grouplist".equals(type)){
replyError("IllegalArgumentException",response, out); replyError("IllegalArgumentException",response, out);
return; return;
} }
...@@ -134,47 +134,66 @@ public class UserServiceServlet extends HttpServlet { ...@@ -134,47 +134,66 @@ public class UserServiceServlet extends HttpServlet {
// Check the request type and process accordingly // Check the request type and process accordingly
try { try {
username = username.trim().toLowerCase(); if ("grouplist".equals(type)){
username = JID.escapeNode(username); String message = "";
username = Stringprep.nodeprep(username); for(String groupname : plugin.getAllGroups())
if ("add".equals(type)) { {
plugin.createUser(username, password, name, email, groupNames); message += "<groupname>"+groupname+"</groupname>";
replyMessage("ok",response, out); }
//imageProvider.sendInfo(request, response, presence); replyMessage(message, response, out);
}
else if ("delete".equals(type)) {
plugin.deleteUser(username);
replyMessage("ok",response,out);
//xmlProvider.sendInfo(request, response, presence);
}
else if ("enable".equals(type)) {
plugin.enableUser(username);
replyMessage("ok",response,out);
}
else if ("disable".equals(type)) {
plugin.disableUser(username);
replyMessage("ok",response,out);
}
else if ("update".equals(type)) {
plugin.updateUser(username, password,name,email, groupNames);
replyMessage("ok",response,out);
//xmlProvider.sendInfo(request, response, presence);
}
else if ("add_roster".equals(type)) {
plugin.addRosterItem(username, item_jid, name, sub, groupNames);
replyMessage("ok",response, out);
}
else if ("update_roster".equals(type)) {
plugin.updateRosterItem(username, item_jid, name, sub, groupNames);
replyMessage("ok",response, out);
}
else if ("delete_roster".equals(type)) {
plugin.deleteRosterItem(username, item_jid);
replyMessage("ok",response, out);
} }
else { else
Log.warn("The userService servlet received an invalid request of type: " + type); {
// TODO Do something username = username.trim().toLowerCase();
username = JID.escapeNode(username);
username = Stringprep.nodeprep(username);
if ("add".equals(type)) {
plugin.createUser(username, password, name, email, groupNames);
replyMessage("ok",response, out);
//imageProvider.sendInfo(request, response, presence);
}
else if ("delete".equals(type)) {
plugin.deleteUser(username);
replyMessage("ok",response,out);
//xmlProvider.sendInfo(request, response, presence);
}
else if ("enable".equals(type)) {
plugin.enableUser(username);
replyMessage("ok",response,out);
}
else if ("disable".equals(type)) {
plugin.disableUser(username);
replyMessage("ok",response,out);
}
else if ("update".equals(type)) {
plugin.updateUser(username, password,name,email, groupNames);
replyMessage("ok",response,out);
//xmlProvider.sendInfo(request, response, presence);
}
else if ("add_roster".equals(type)) {
plugin.addRosterItem(username, item_jid, name, sub, groupNames);
replyMessage("ok",response, out);
}
else if ("update_roster".equals(type)) {
plugin.updateRosterItem(username, item_jid, name, sub, groupNames);
replyMessage("ok",response, out);
}
else if ("delete_roster".equals(type)) {
plugin.deleteRosterItem(username, item_jid);
replyMessage("ok",response, out);
}
if ("usergrouplist".equals(type)){
String message = "";
for(String groupname : plugin.getUserGroups(username))
{
message += "<groupname>"+groupname+"</groupname>";
}
replyMessage(message, response, out);
}
else {
Log.warn("The userService servlet received an invalid request of type: " + type);
// TODO Do something
}
} }
} }
catch (UserAlreadyExistsException e) { catch (UserAlreadyExistsException e) {
......
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