Skip to content

Commit

Permalink
Check existing user-group association before attempting this call, to…
Browse files Browse the repository at this point in the history
… avoid SQL duplicate key violations (for JDBC user/group service)
  • Loading branch information
Peter Smythe authored and github-actions[bot] committed Jul 17, 2024
1 parent e8ad6df commit a46f6c7
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package org.geoserver.rest.security;

import java.io.IOException;
import java.util.SortedSet;
import javax.servlet.http.HttpServletResponse;
import org.geoserver.rest.RestBaseController;
import org.geoserver.rest.RestException;
import org.geoserver.rest.catalog.SequentialExecutionController;
import org.geoserver.rest.security.xml.JaxbGroupList;
import org.geoserver.rest.security.xml.JaxbUser;
Expand Down Expand Up @@ -236,6 +238,17 @@ public JaxbGroupList getGroupsFromUser(
@PathVariable("group") String groupName)
throws IOException {
GeoServerUserGroupStore store = getStore(serviceName);
GeoServerUserGroupService service = getService(serviceName);
SortedSet<GeoServerUserGroup> groupsForUser =
service.getGroupsForUser(
getUser(service, userName)); // There should be fewer groups than users
for (GeoServerUserGroup group : groupsForUser) {
if (groupName.equals(group.getGroupname())) {
throw new RestException(
"Username already associated with this groupname",
HttpStatus.OK); // In the future 409 Conflict?
}
}
try {
store.associateUserToGroup(getUser(store, userName), getGroup(store, groupName));
} finally {
Expand Down

0 comments on commit a46f6c7

Please sign in to comment.