Commit cf8916c0 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-173] Handle full server JIDs as permission input.

[GATE-148] Throwing javascript error and reflecting unaccepted users/groups in permissions panel now.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6946 b35dd754-fafc-0310-a699-88a17e54d16e
parent 35d2b108
...@@ -25,9 +25,11 @@ import org.jivesoftware.util.JiveGlobals; ...@@ -25,9 +25,11 @@ import org.jivesoftware.util.JiveGlobals;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.Attribute; import org.dom4j.Attribute;
import org.xmpp.packet.JID;
import java.util.HashMap; import java.util.HashMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
* Transport Configuration Manager (for web interface) * Transport Configuration Manager (for web interface)
...@@ -146,22 +148,31 @@ public class ConfigManager { ...@@ -146,22 +148,31 @@ public class ConfigManager {
* @param overallSetting The general "all(1), some(2), or none(3)" setting for the permissions. * @param overallSetting The general "all(1), some(2), or none(3)" setting for the permissions.
* @param users List of specific users that have access. * @param users List of specific users that have access.
* @param groups List of specific groups that have access. * @param groups List of specific groups that have access.
* @return List of usernames and groups (@ preceded) that were rejected.
*/ */
public void savePermissions(String transportName, Integer overallSetting, ArrayList<String> users, ArrayList<String> groups) { public List<String> savePermissions(String transportName, Integer overallSetting, List<String> users, List<String> groups) {
JiveGlobals.setProperty("plugin.gateway."+transportName+".registration", overallSetting.toString()); JiveGlobals.setProperty("plugin.gateway."+transportName+".registration", overallSetting.toString());
PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName)); PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName));
List<String> errorList = new ArrayList<String>();
ArrayList<User> userList = new ArrayList<User>(); ArrayList<User> userList = new ArrayList<User>();
UserManager userManager = UserManager.getInstance(); UserManager userManager = UserManager.getInstance();
for (String username : users) { for (String username : users) {
if (username.matches("\\s+")) { continue; } if (username.matches("\\s*")) { continue; }
try { try {
if (username.contains("@")) {
JID jid = new JID(username);
if (!jid.getDomain().equals(XMPPServer.getInstance().getServerInfo().getName())) {
throw new UserNotFoundException();
}
username = username.substring(0, username.indexOf("@"));
}
User user = userManager.getUser(username); User user = userManager.getUser(username);
if (user == null || user.getUsername() == null) { throw new UserNotFoundException(); } if (user == null || user.getUsername() == null) { throw new UserNotFoundException(); }
userList.add(user); userList.add(user);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
Log.warn("User "+username+" not found while adding access rules."); Log.warn("User "+username+" not found while adding access rules.");
errorList.add(username);
} }
} }
permissionManager.storeUserList(userList); permissionManager.storeUserList(userList);
...@@ -169,7 +180,7 @@ public class ConfigManager { ...@@ -169,7 +180,7 @@ public class ConfigManager {
ArrayList<Group> groupList = new ArrayList<Group>(); ArrayList<Group> groupList = new ArrayList<Group>();
GroupManager groupManager = GroupManager.getInstance(); GroupManager groupManager = GroupManager.getInstance();
for (String grpname : groups) { for (String grpname : groups) {
if (grpname.matches("\\s+")) { continue; } if (grpname.matches("\\s*")) { continue; }
try { try {
Group group = groupManager.getGroup(grpname); Group group = groupManager.getGroup(grpname);
if (group == null || group.getName() == null) { throw new GroupNotFoundException(); } if (group == null || group.getName() == null) { throw new GroupNotFoundException(); }
...@@ -177,9 +188,12 @@ public class ConfigManager { ...@@ -177,9 +188,12 @@ public class ConfigManager {
} }
catch (GroupNotFoundException e) { catch (GroupNotFoundException e) {
Log.warn("Group "+grpname+" not found while adding access rules."); Log.warn("Group "+grpname+" not found while adding access rules.");
errorList.add("@"+grpname);
} }
} }
permissionManager.storeGroupList(groupList); permissionManager.storeGroupList(groupList);
return errorList;
} }
} }
...@@ -439,6 +439,10 @@ ...@@ -439,6 +439,10 @@
Effect.Fade(transportID+"testsresults"); Effect.Fade(transportID+"testsresults");
} }
var lastUserList;
var lastGroupList;
var lastTransportID;
function savePermissions(transportID) { function savePermissions(transportID) {
var userEntry = DWRUtil.getValue(transportID+"userpermentry"); var userEntry = DWRUtil.getValue(transportID+"userpermentry");
var groupEntry = DWRUtil.getValue(transportID+"grouppermentry"); var groupEntry = DWRUtil.getValue(transportID+"grouppermentry");
...@@ -455,9 +459,60 @@ ...@@ -455,9 +459,60 @@
} }
var userList = userEntry.split(/\s+/); var userList = userEntry.split(/\s+/);
var groupList = groupEntry.split(/\s+/); var groupList = groupEntry.split(/\s+/);
ConfigManager.savePermissions(transportID, globalSetting, userList, groupList); lastUserList = userList;
document.getElementById(transportID+"userpermtext").innerHTML = userList.join(" "); lastGroupList = groupList;
document.getElementById(transportID+"grouppermtext").innerHTML = groupList.join(" "); lastTransportID = transportID;
ConfigManager.savePermissions(transportID, globalSetting, userList, groupList, cb_savePermissions);
}
function cb_savePermissions(errorList) {
var userList = lastUserList;
var groupList = lastGroupList;
var transportID = lastTransportID;
if (errorList != null && errorList.length > 0) {
var errUsers = new Array();
var errGroups = new Array();
for (i = 0; i < errorList.length; i++) {
if (errorList[i].charAt(0) == "@") {
var grpName = errorList[i].substr(1, (errorList[i].length-1));
errGroups.push(grpName);
for (j = 0; j < groupList.length; j++) {
if (groupList[j] == grpName) {
groupList.splice(j, 1);
break;
}
}
}
else {
var userName = errorList[i];
errUsers.push(userName);
for (j = 0; j < userList.length; j++) {
if (userList[j] == userName) {
userList.splice(j, 1);
break;
}
}
}
}
var errMsg = "";
if (errUsers.length > 0) {
errMsg = errMsg + "\nThe following users were not valid and were ignored:\n" + errUsers.join("\n") + "\n";
}
if (errGroups.length > 0) {
errMsg = errMsg + "\nThe following groups were not valid and were ignored:\n" + errGroups.join("\n") + "\n";
}
alert(errMsg);
}
for (i = 0; i < userList.length; i++) {
var charPos = userList[i].indexOf("@");
if (charPos >= 0) {
userList[i] = userList[i].substr(0, charPos);
}
}
document.getElementById(transportID+"userpermtext").innerHTML = (userList.length > 0 ? userList.join(" ") : "[none selected]");
document.getElementById(transportID+"userpermentry").value = userList.join(" ");
document.getElementById(transportID+"grouppermtext").innerHTML = (groupList.length > 0 ? groupList.join(" ") : "[none selected]");
document.getElementById(transportID+"grouppermentry").value = groupList.join(" ");
deactivateModifyUsers(transportID); deactivateModifyUsers(transportID);
deactivateModifyGroups(transportID); deactivateModifyGroups(transportID);
document.getElementById(transportID+"permsresults").style.display = ""; document.getElementById(transportID+"permsresults").style.display = "";
......
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