use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class UserServicePlugin method createUser.
public void createUser(String username, String password, String name, String email, String groupNames) throws UserAlreadyExistsException, GroupAlreadyExistsException, UserNotFoundException, GroupNotFoundException {
userManager.createUser(username, password, name, email);
userManager.getUser(username);
if (groupNames != null) {
Collection<Group> groups = 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", "");
}
groups.add(group);
}
for (Group group : groups) {
group.getMembers().add(server.createJID(username, null));
}
}
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class UserServicePluginNG method deleteUserFromGroups.
/**
* Delete user from groups.
*
* @param username
* the username
* @param userGroupsEntity
* the user groups entity
* @throws ServiceException
* the service exception
*/
public void deleteUserFromGroups(String username, UserGroupsEntity userGroupsEntity) throws ServiceException {
if (userGroupsEntity != null) {
for (String groupName : userGroupsEntity.getGroupNames()) {
Group group = null;
try {
group = GroupManager.getInstance().getGroup(groupName);
} catch (GroupNotFoundException e) {
throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND, Response.Status.NOT_FOUND, e);
}
group.getMembers().remove(server.createJID(username, null));
}
}
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class UserServicePluginNG method addUserToGroups.
/**
* Adds the user to group.
*
* @param username
* the username
* @param userGroupsEntity
* the user groups entity
* @throws ServiceException
* @throws GroupAlreadyExistsException
* the group already exists exception
*/
public void addUserToGroups(String username, UserGroupsEntity userGroupsEntity) throws ServiceException {
if (userGroupsEntity != null) {
Collection<Group> groups = new ArrayList<Group>();
for (String groupName : userGroupsEntity.getGroupNames()) {
Group group = null;
try {
group = GroupManager.getInstance().getGroup(groupName);
} catch (GroupNotFoundException e) {
// Create this group
group = createGroup(groupName);
}
groups.add(group);
}
for (Group group : groups) {
group.getMembers().add(server.createJID(username, null));
}
}
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class LocalMUCRoom method applyAffiliationChange.
/**
* Evaluate the given JID to determine what the appropriate affiliation should be
* after a change has been made. Each affected user will be granted the highest
* affiliation they now possess, either explicitly or implicitly via membership
* in one or more groups. If the JID is a user, the effective affiliation is
* applied to each presence corresponding to that user. If the given JID is a group,
* each user in the group is evaluated to determine what their new affiliations will
* be. The returned presence updates will be broadcast to the occupants of the room.
*
* @param senderRole Typically the room itself, or an owner/admin
* @param affiliationJID The JID for the user or group that has been changed
* @param reason An optional reason to explain why a user was kicked from the room
* @return List of presence updates to be delivered to the room's occupants
*/
private List<Presence> applyAffiliationChange(MUCRole senderRole, final JID affiliationJID, String reason) {
// Update the presence(s) for the new affiliation and inform all occupants
List<JID> affectedOccupants = new ArrayList<>();
// first, determine which actual (user) JIDs are affected by the affiliation change
if (GroupJID.isGroup(affiliationJID)) {
try {
Group group = GroupManager.getInstance().getGroup(affiliationJID);
// if so, calculate a new affiliation (if any) for the occupant(s)
for (JID groupMember : group.getAll()) {
if (occupantsByBareJID.containsKey(groupMember)) {
affectedOccupants.add(groupMember);
}
}
} catch (GroupNotFoundException gnfe) {
Log.error("Error updating group presences for " + affiliationJID, gnfe);
}
} else {
if (occupantsByBareJID.containsKey(affiliationJID)) {
affectedOccupants.add(affiliationJID);
}
}
// now update each of the affected occupants with a new role/affiliation
MUCRole.Role newRole;
MUCRole.Affiliation newAffiliation;
List<Presence> updatedPresences = new ArrayList<>();
// new role/affiliation may be granted via group membership
for (JID occupantJID : affectedOccupants) {
Log.info("Applying affiliation change for " + occupantJID);
boolean kickMember = false, isOutcast = false;
if (owners.includes(occupantJID)) {
newRole = MUCRole.Role.moderator;
newAffiliation = MUCRole.Affiliation.owner;
} else if (admins.includes(occupantJID)) {
newRole = MUCRole.Role.moderator;
newAffiliation = MUCRole.Affiliation.admin;
} else // outcast trumps member when an affiliation is changed
if (outcasts.includes(occupantJID)) {
newAffiliation = MUCRole.Affiliation.outcast;
newRole = MUCRole.Role.none;
kickMember = true;
isOutcast = true;
} else if (members.includesKey(occupantJID)) {
newRole = MUCRole.Role.participant;
newAffiliation = MUCRole.Affiliation.member;
} else if (isMembersOnly()) {
newRole = MUCRole.Role.none;
newAffiliation = MUCRole.Affiliation.none;
kickMember = true;
} else {
newRole = isModerated() ? MUCRole.Role.visitor : MUCRole.Role.participant;
newAffiliation = MUCRole.Affiliation.none;
}
Log.info("New affiliation: " + newAffiliation);
try {
List<Presence> thisOccupant = changeOccupantAffiliation(senderRole, occupantJID, newAffiliation, newRole);
if (kickMember) {
// a status code of 301 indicates the user was removed as an outcast
for (Presence presence : thisOccupant) {
presence.setType(Presence.Type.unavailable);
presence.setStatus(null);
Element x = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
if (reason != null && reason.trim().length() > 0) {
x.element("item").addElement("reason").setText(reason);
}
x.addElement("status").addAttribute("code", isOutcast ? "301" : "321");
kickPresence(presence, senderRole.getUserAddress(), senderRole.getNickname());
}
}
updatedPresences.addAll(thisOccupant);
} catch (NotAllowedException e) {
Log.error("Error updating presences for " + occupantJID, e);
}
}
return updatedPresences;
}
use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.
the class BookmarkInterceptor method isBookmarkForJID.
/**
* True if the specified bookmark should be appended to the users list of
* bookmarks.
*
* @param jid the jid of the user.
* @param bookmark the bookmark.
* @return true if bookmark should be appended.
*/
private static boolean isBookmarkForJID(JID jid, Bookmark bookmark) {
String username = jid.getNode();
if (bookmark.getUsers().contains(username)) {
return true;
}
Collection<String> groups = bookmark.getGroups();
if (groups != null && !groups.isEmpty()) {
GroupManager groupManager = GroupManager.getInstance();
for (String groupName : groups) {
try {
Group group = groupManager.getGroup(groupName);
if (group.isUser(jid.getNode())) {
return true;
}
} catch (GroupNotFoundException e) {
Log.debug(e.getMessage(), e);
}
}
}
return false;
}
Aggregations