use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class UserServicePlugin method updateUser.
public void updateUser(String username, String password, String name, String email, String groupNames) throws UserNotFoundException, GroupAlreadyExistsException {
User user = getUser(username);
if (password != null)
user.setPassword(password);
if (name != null)
user.setName(name);
if (email != null)
user.setEmail(email);
if (groupNames != null) {
Collection<Group> newGroups = new ArrayList<Group>();
StringTokenizer tkn = new StringTokenizer(groupNames, ",");
while (tkn.hasMoreTokens()) {
String groupName = tkn.nextToken();
Group group = null;
try {
group = GroupManager.getInstance().getGroup(groupName);
} catch (GroupNotFoundException e) {
// Create this group ;
group = GroupManager.getInstance().createGroup(groupName);
group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
group.getProperties().put("sharedRoster.displayName", groupName);
group.getProperties().put("sharedRoster.groupList", "");
}
newGroups.add(group);
}
Collection<Group> existingGroups = GroupManager.getInstance().getGroups(user);
// Get the list of groups to add to the user
Collection<Group> groupsToAdd = new ArrayList<Group>(newGroups);
groupsToAdd.removeAll(existingGroups);
// Get the list of groups to remove from the user
Collection<Group> groupsToDelete = new ArrayList<Group>(existingGroups);
groupsToDelete.removeAll(newGroups);
// Add the user to the new groups
for (Group group : groupsToAdd) {
group.getMembers().add(server.createJID(username, null));
}
// Remove the user from the old groups
for (Group group : groupsToDelete) {
group.getMembers().remove(server.createJID(username, null));
}
}
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class CrowdAdminProvider method getAdmins.
@Override
public List<JID> getAdmins() {
List<JID> results = new ArrayList<>();
GroupProvider provider = GroupManager.getInstance().getProvider();
String groups = JiveGlobals.getProperty(JIVE_AUTHORIZED_GROUPS);
groups = (groups == null || groups.trim().length() == 0) ? "" : groups;
// make sure the property is created
JiveGlobals.setProperty(JIVE_AUTHORIZED_GROUPS, groups);
StringTokenizer tokenizer = new StringTokenizer(groups, ",");
while (tokenizer.hasMoreTokens()) {
String groupName = tokenizer.nextToken().trim().toLowerCase();
if (groupName != null && groupName.length() > 0) {
try {
LOG.info("Adding admin users from group: " + groupName);
Group group = provider.getGroup(groupName);
if (group != null) {
results.addAll(group.getMembers());
}
} catch (GroupNotFoundException gnfe) {
LOG.error("Error when trying to load the members of group:" + String.valueOf(groupName), gnfe);
}
}
}
if (results.isEmpty()) {
// Add default admin account when none was specified
results.add(new JID("admin", XMPPServer.getInstance().getServerInfo().getXMPPDomain(), null, true));
}
if (LOG.isDebugEnabled()) {
LOG.debug("admin users: " + results.toString());
}
return results;
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class CrowdGroupProvider method getGroup.
@Override
public Group getGroup(String name) throws GroupNotFoundException {
try {
Cache<String, org.jivesoftware.openfire.crowd.jaxb.Group> groupCache = CacheFactory.createLocalCache(GROUP_CACHE_NAME);
org.jivesoftware.openfire.crowd.jaxb.Group group = groupCache.get(name);
if (group == null) {
group = manager.getGroup(name);
groupCache.put(name, group);
}
Collection<JID> members = getGroupMembers(name);
Collection<JID> admins = Collections.emptyList();
return new Group(name, group.description, members, admins);
} catch (RemoteException re) {
LOG.error("Failure to load group:" + String.valueOf(name), re);
throw new GroupNotFoundException(re);
}
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class UpdateGroup method addStageInformation.
@Override
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
if (data.getStage() == 0) {
form.setTitle("Update group configuration");
form.addInstruction("Fill out this form to specify the group to update.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
} else {
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Group not found");
return;
}
form.setTitle("Update group configuration");
form.addInstruction("Fill out this form with the new group configuration.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_multi);
field.setLabel("Description");
field.setVariable("desc");
if (group.getDescription() != null) {
field.addValue(group.getDescription());
}
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Shared group visibility");
field.setVariable("showInRoster");
field.addValue("nobody");
field.addOption("Disable sharing group in rosters", "nobody");
field.addOption("Show group in all users' rosters", "everybody");
field.addOption("Show group in group members' rosters", "onlyGroup");
field.addOption("Show group to members' rosters of these groups", "spefgroups");
field.setRequired(true);
String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
if (showInRoster != null) {
if ("onlyGroup".equals(showInRoster) && group.getProperties().get("sharedRoster.groupList").trim().length() > 0) {
// Show shared group to other groups
showInRoster = "spefgroups";
}
field.addValue(showInRoster);
}
field = form.addField();
field.setType(FormField.Type.list_multi);
field.setVariable("groupList");
for (Group otherGroup : GroupManager.getInstance().getGroups()) {
field.addOption(otherGroup.getName(), otherGroup.getName());
}
String groupList = group.getProperties().get("sharedRoster.groupList");
if (groupList != null) {
Collection<String> groups = new ArrayList<>();
StringTokenizer tokenizer = new StringTokenizer(groupList, ",\t\n\r\f");
while (tokenizer.hasMoreTokens()) {
String tok = tokenizer.nextToken().trim();
groups.add(tok.trim());
}
for (String othergroup : groups) {
field.addValue(othergroup);
}
}
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Display Name");
field.setVariable("displayName");
String displayName = group.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
field.addValue(displayName);
}
}
// Add the form to the command
command.add(form.getElement());
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class GetListGroupUsers method execute.
@Override
public void execute(SessionData data, Element command) {
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
DataForm form = new DataForm(DataForm.Type.result);
form.addReportedField("jid", "User", FormField.Type.jid_single);
form.addReportedField("admin", "Description", FormField.Type.boolean_type);
// Add group members the result
for (JID memberJID : group.getMembers()) {
Map<String, Object> fields = new HashMap<>();
fields.put("jid", memberJID.toString());
fields.put("admin", false);
form.addItemFields(fields);
}
// Add group admins the result
for (JID memberJID : group.getAdmins()) {
Map<String, Object> fields = new HashMap<>();
fields.put("jid", memberJID.toString());
fields.put("admin", true);
form.addItemFields(fields);
}
command.add(form.getElement());
}
Aggregations