@Override public ShortGroup get(String name) throws NotFoundRestEx, InternalErrorRestEx { try { UserGroup ret = userGroupAdminService.get(name); return new ShortGroup(ret); } catch (NotFoundServiceEx ex) { LOGGER.warn("Role not found: " + name); throw new NotFoundRestEx("Role not found: " + name); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
@Override public Response insert(RESTInputGroup userGroup) throws NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { // check that no group with same name exists boolean exists; try { userGroupAdminService.get(userGroup.getName()); exists = true; } catch (NotFoundServiceEx ex) { // well, ok, usergroup does not exist exists = false; } catch (Exception ex) { // something went wrong LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if(exists) throw new ConflictRestEx("Role '"+userGroup.getName()+"' already exists"); // ok: insert it try { ShortGroup insert = new ShortGroup(); insert.setEnabled(userGroup.isEnabled()); insert.setExtId(userGroup.getExtId()); insert.setName(userGroup.getName()); Long id = userGroupAdminService.insert(insert); return Response.status(Status.CREATED).tag(id.toString()).entity(id).build(); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
protected UserGroup getUserGroup(IdName groupFilter) throws BadRequestRestEx, NotFoundRestEx { try { if (groupFilter.getId() != null) { throw new BadRequestRestEx("Groups can only be referenced by name"); } else if (groupFilter.getName() != null) { return userGroupAdminService.get(groupFilter.getName()); } else { throw new BadRequestRestEx("Bad UserGroup filter " + groupFilter); } } catch (NotFoundServiceEx e) { LOGGER.warn("UserGroup not found " + groupFilter); throw new NotFoundRestEx("UserGroup not found " + groupFilter); } }
@Override public Response delete(String name, boolean cascade) throws ConflictRestEx, NotFoundRestEx, InternalErrorRestEx { try { if ( cascade ) { ruleAdminService.deleteRulesByRole(name); } else { RuleFilter filter = new RuleFilter(SpecialFilterType.ANY); filter.setRole(name); filter.getUser().setIncludeDefault(false); long cnt = ruleAdminService.count(filter); if ( cnt > 0 ) { throw new ConflictRestEx("Existing rules reference the role " + name); } } UserGroup role = userGroupAdminService.get(name); if ( ! userGroupAdminService.delete(role.getId())) { LOGGER.warn("Role not found: " + name); throw new NotFoundRestEx("Role not found: " + name); } return Response.status(Status.OK).entity("OK\n").build(); } catch (GeoFenceRestEx ex) { // already handled throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Role not found: " + name); throw new NotFoundRestEx("Role not found: " + name); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
public void deleteProfile(UserGroupModel profile) { org.geoserver.geofence.core.model.UserGroup remote_profile = null; try { remote_profile = geofenceRemoteService.getUserGroupAdminService().get(profile.getId()); geofenceRemoteService.getUserGroupAdminService().delete(remote_profile.getId()); } catch (NotFoundServiceEx e) { logger.error(e.getLocalizedMessage(), e.getCause()); throw new ApplicationException(e.getLocalizedMessage(), e.getCause()); } }
@Override public void update(String name, RESTInputGroup group) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { try { UserGroup old = userGroupAdminService.get(name); ShortGroup newGroup = new ShortGroup(); newGroup.setId(old.getId()); if ( (group.getExtId() != null) ) { throw new BadRequestRestEx("ExtId can't be updated"); } if ( (group.getName() != null) ) { throw new BadRequestRestEx("Name can't be updated"); } if ( group.isEnabled() != null ) { newGroup.setEnabled(group.isEnabled()); } userGroupAdminService.update(newGroup); } catch (GeoFenceRestEx ex) { // already handled throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Role not found: " + name + ": " + ex.getMessage(), ex); throw new NotFoundRestEx(ex.getMessage()); } catch (BadRequestServiceEx ex) { LOGGER.warn("Problems updating role:" + name + ": " + ex.getMessage(), ex); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error(ex); throw new InternalErrorRestEx(ex.getMessage()); } }
/** * @param profile * @param remote_user * @throws ResourceNotFoundFault */ private void copyUser(GSUserModel user, org.geoserver.geofence.core.model.GSUser remote_user) throws NotFoundServiceEx { remote_user.setName(user.getName()); remote_user.setFullName(user.getFullName()); remote_user.setEmailAddress(user.getEmailAddress()); remote_user.setEnabled(user.isEnabled()); remote_user.setAdmin(user.isAdmin()); remote_user.setPassword(user.getPassword()); remote_user.setDateCreation(user.getDateCreation()); Set<org.geoserver.geofence.core.model.UserGroup> remote_groups = new HashSet<org.geoserver.geofence.core.model.UserGroup>(); for(UserGroupModel group : user.getUserGroups()) { org.geoserver.geofence.core.model.UserGroup remote_group = geofenceRemoteService.getUserGroupAdminService().get(group.getId()); logger.error("TODO: profile refactoring!!!"); remote_groups.add(remote_group); } remote_user.setGroups(remote_groups); }
remote_profile = geofenceRemoteService.getUserGroupAdminService().get(profile.getId());