Skip to content

Commit

Permalink
for #40: Allow UserGroup services to work for non-local users
Browse files Browse the repository at this point in the history
JIDs on domains other than the local domain can be in groups. This commit adds support for that in the UserGroups endpoints, with the exception of an endpoint that would make the code iterate over all groups in the system.
  • Loading branch information
guusdk committed Jun 22, 2022
1 parent ceaec83 commit 1018146
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ public void deleteRosterItem(String username, String rosterJid) throws SharedGro
*/
public List<String> getUserGroups(String username) throws ServiceException {
log("Get user groups for user: " + username);
if (username.contains("@")) {
throw new ServiceException("This service cannot be used for non-local users.", username, ExceptionType.GROUP_NOT_FOUND, Response.Status.INTERNAL_SERVER_ERROR);
}
User user = getAndCheckUser(username);
Collection<Group> groups = GroupManager.getInstance().getGroups(user);
List<String> groupNames = new ArrayList<String>();
Expand Down Expand Up @@ -438,7 +441,7 @@ public void addUserToGroups(String username, UserGroupsEntity userGroupsEntity)
groups.add(group);
}
for (Group group : groups) {
group.getMembers().add(server.createJID(username, null));
group.getMembers().add(username.contains("@") ? new JID(username) : XMPPServer.getInstance().createJID(username, null));
}
}
}
Expand All @@ -461,7 +464,7 @@ public void addUserToGroup(String username, String groupName) throws ServiceExce
group = GroupController.getInstance().createGroup(new GroupEntity(groupName, ""));
}

group.getMembers().add(server.createJID(username, null));
group.getMembers().add(username.contains("@") ? new JID(username) : XMPPServer.getInstance().createJID(username, null));
}

/**
Expand All @@ -487,7 +490,7 @@ public void deleteUserFromGroups(String username, UserGroupsEntity userGroupsEnt
Response.Status.NOT_FOUND, e);
}
log("Removing user: " + username + " from the group: " + groupName);
group.getMembers().remove(server.createJID(username, null));
group.getMembers().remove(username.contains("@") ? new JID(username) : XMPPServer.getInstance().createJID(username, null));
}
}
}
Expand All @@ -508,7 +511,7 @@ public void deleteUserFromGroup(String username, String groupName) throws Servic
throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND,
Response.Status.NOT_FOUND, e);
}
group.getMembers().remove(server.createJID(username, null));
group.getMembers().remove(username.contains("@") ? new JID(username) : XMPPServer.getInstance().createJID(username, null));
}

/**
Expand Down

0 comments on commit 1018146

Please sign in to comment.