use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class ConfigManager method savePermissions.
/**
* Saves permissions settings from web interface.
*
* We validate all of the groups before actually adding them.
*
* @param transportName Name of the transport to have it's options saved (type of transport)
* @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 groups List of specific groups that have access.
* @param strict Strict permissions associted with setting.
* @return List of usernames and groups (@ preceded) that were rejected.
*/
public List<String> savePermissions(String transportName, Integer overallSetting, List<String> users, List<String> groups, Boolean strict) {
JiveGlobals.setProperty("plugin.gateway." + transportName + ".registration", overallSetting.toString());
JiveGlobals.setProperty("plugin.gateway." + transportName + ".registrationstrict", strict ? "true" : "false");
PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName));
List<String> errorList = new ArrayList<String>();
ArrayList<User> userList = new ArrayList<User>();
UserManager userManager = UserManager.getInstance();
for (String username : users) {
if (username.matches("\\s*")) {
continue;
}
try {
if (username.contains("@")) {
JID jid = new JID(username);
if (!jid.getDomain().equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
throw new UserNotFoundException();
}
username = username.substring(0, username.indexOf("@"));
}
User user = userManager.getUser(username);
if (user == null || user.getUsername() == null) {
throw new UserNotFoundException();
}
userList.add(user);
} catch (UserNotFoundException e) {
Log.warn("User " + username + " not found while adding access rules.");
errorList.add(username);
}
}
permissionManager.storeUserList(userList);
ArrayList<Group> groupList = new ArrayList<Group>();
GroupManager groupManager = GroupManager.getInstance();
for (String grpname : groups) {
if (grpname.matches("\\s*")) {
continue;
}
try {
Group group = groupManager.getGroup(grpname);
if (group == null || group.getName() == null) {
throw new GroupNotFoundException();
}
groupList.add(group);
} catch (GroupNotFoundException e) {
Log.warn("Group " + grpname + " not found while adding access rules.");
errorList.add("@" + grpname);
}
}
permissionManager.storeGroupList(groupList);
return errorList;
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class RuleGroupEventListener method groupModified.
@Override
public void groupModified(Group group, Map params) {
String keyChanged = (String) params.get("propertyKey");
String originalValue = (String) params.get("originalValue");
Log.debug("Group: " + group.getName() + " params: " + params + " originalValue:" + originalValue);
if ("sharedRoster.groupList".equals(keyChanged)) {
String currentValue = group.getProperties().get("sharedRoster.groupList");
if (currentValue != null && !"".equals(currentValue)) {
deleteAllAutoCreatedRules(group);
Collection<Group> groupList = parseGroups(currentValue);
createPassRule(group.getName(), group.getName(), group.getName());
for (Group tmpGroup : groupList) {
createPassRule(tmpGroup.getName(), group.getName(), group.getName());
createPassRule(group.getName(), tmpGroup.getName(), group.getName());
}
}
} else if ("sharedRoster.showInRoster".equals(keyChanged)) {
String currentValue = group.getProperties().get("sharedRoster.showInRoster");
if ("onlyGroup".equals(currentValue)) {
deleteAllAutoCreatedRules(group);
createPassRule(group.getName(), group.getName(), group.getName());
} else if ("everybody".equals(currentValue)) {
deleteAllAutoCreatedRules(group);
createPassRule(PacketFilterConstants.ANY_GROUP, group.getName(), group.getName());
createPassRule(group.getName(), PacketFilterConstants.ANY_GROUP, group.getName());
} else if ("nobody".equals(currentValue)) {
deleteAllAutoCreatedRules(group);
}
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class PacketFilter method packetToFromGroup.
private boolean packetToFromGroup(String rulegroup, JID packetToFrom) {
Group group = null;
boolean result = false;
try {
group = GroupManager.getInstance().getGroup(rulegroup);
} catch (GroupNotFoundException e) {
if (PacketFilterConstants.ANY_GROUP.equals(rulegroup)) {
if (!GroupManager.getInstance().getGroups(packetToFrom).isEmpty()) {
result = true;
}
} else {
e.printStackTrace();
}
}
if (group != null) {
if (group.isUser(packetToFrom)) {
result = true;
}
}
return result;
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class GetListGroups method execute.
@Override
public void execute(SessionData data, Element command) {
String start = data.getData().get("start").get(0);
String max_items = data.getData().get("max_items").get(0);
int nStart = 0;
if (start != null) {
try {
nStart = Integer.parseInt(start);
} catch (NumberFormatException e) {
// Do nothing. Assume default value
}
}
int maxItems = 100000;
if (max_items != null && !"none".equals(max_items)) {
try {
maxItems = Integer.parseInt(max_items);
} catch (NumberFormatException e) {
// Do nothing. Assume that all users are being requested
}
}
DataForm form = new DataForm(DataForm.Type.result);
form.addReportedField("name", "Name", FormField.Type.text_single);
form.addReportedField("desc", "Description", FormField.Type.text_multi);
form.addReportedField("count", "User Count", FormField.Type.text_single);
form.addReportedField("shared", "Shared group?", FormField.Type.boolean_type);
form.addReportedField("display", "Display Name", FormField.Type.text_single);
form.addReportedField("visibility", "Visibility", FormField.Type.text_single);
form.addReportedField("groups", "Show group to members' rosters of these groups", FormField.Type.text_multi);
// Add groups to the result
for (Group group : GroupManager.getInstance().getGroups(nStart, maxItems)) {
boolean isSharedGroup = RosterManager.isSharedGroup(group);
Map<String, String> properties = group.getProperties();
Map<String, Object> fields = new HashMap<>();
fields.put("name", group.getName());
fields.put("desc", group.getDescription());
fields.put("count", group.getMembers().size() + group.getAdmins().size());
fields.put("shared", isSharedGroup);
fields.put("display", (isSharedGroup ? properties.get("sharedRoster.displayName") : ""));
String showInRoster = (isSharedGroup ? properties.get("sharedRoster.showInRoster") : "");
if ("onlyGroup".equals(showInRoster) && properties.get("sharedRoster.groupList").trim().length() > 0) {
// Show shared group to other groups
showInRoster = "spefgroups";
}
fields.put("visibility", showInRoster);
fields.put("groups", (isSharedGroup ? properties.get("sharedRoster.groupList") : ""));
form.addItemFields(fields);
}
command.add(form.getElement());
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class UpdateGroup method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group not found");
return;
}
List<String> desc = data.getData().get("desc");
if (desc != null) {
group.setDescription(desc.get(0));
}
String showInRoster = data.getData().get("showInRoster").get(0);
if ("nobody".equals(showInRoster)) {
// New group is not a shared group
group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("sharedRoster.displayName", " ");
group.getProperties().put("sharedRoster.groupList", " ");
} else {
// New group is configured as a shared group
if ("spefgroups".equals(showInRoster)) {
// Show shared group to other groups
showInRoster = "onlyGroup";
}
List<String> displayName = data.getData().get("displayName");
List<String> groupList = data.getData().get("groupList");
if (displayName != null) {
group.getProperties().put("sharedRoster.showInRoster", showInRoster);
group.getProperties().put("sharedRoster.displayName", displayName.get(0));
if (groupList != null) {
StringBuilder buf = new StringBuilder();
String sep = "";
for (String groupName : groupList) {
buf.append(sep).append(groupName);
sep = ",";
}
group.getProperties().put("sharedRoster.groupList", buf.toString());
}
}
}
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
Aggregations