public void removeAllProfiles() throws NotFoundServiceEx { List<ShortGroup> list = userGroupAdminService.getList(null, null, null); for (ShortGroup item : list) { LOGGER.warn("Removing " + item); boolean ret = userGroupAdminService.delete(item.getId()); if ( !ret ) { LOGGER.error("Could not remove " + item); } } long count = userGroupAdminService.getCount(null); if ( count > 0 ) { LOGGER.error("Items not removed"); } }
@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()); } }
/** * Simplified operation used for quick re-insertion of data extracted with a GET op in the related service */ @Override public void setUserGroups(RESTFullUserGroupList groups) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { int okCnt = 0; for (ShortGroup group : groups) { LOGGER.info("Adding group " +group ); try { userGroupAdminService.insert(group); okCnt++; } catch (Exception e) { LOGGER.info("Could not add group " +group +": " + e.getMessage()); } } LOGGER.info(okCnt+"/"+groups.getList().size() + " items inserted"); }
remote_profile = geofenceRemoteService.getUserGroupAdminService().get(profile.getId()); short_profile.setName(profile.getName()); short_profile.setEnabled(profile.isEnabled()); geofenceRemoteService.getUserGroupAdminService().update(short_profile); short_profile.setName(profile.getName()); short_profile.setEnabled(profile.isEnabled()); geofenceRemoteService.getUserGroupAdminService().insert(short_profile);
@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()); } }
@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()); } }
@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()); } }
@Override public RESTFullUserGroupList getUserGroups() throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { List<ShortGroup> groups = userGroupAdminService.getList(null, null, null); return new RESTFullUserGroupList(groups); }
@Override public long count(String nameLike) { return userGroupAdminService.getCount(nameLike); }
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 RESTFullUserGroupList getList(String nameLike, Integer page, Integer entries) { List<ShortGroup> groups = userGroupAdminService.getList(nameLike, page, entries); return new RESTFullUserGroupList(groups); }
protected RESTBatch collectGroups(RESTBatch backup) { for (ShortGroup shortGroup : userGroupAdminService.getList(null, null, null)) { RESTBatchOperation op = RESTBatchOperationFactory.createGroupInputOp(shortGroup.getName()); RESTInputGroup input = (RESTInputGroup)op.getPayload(); input.setExtId(shortGroup.getExtId()); input.setEnabled(shortGroup.isEnabled()); backup.add(op); } return backup; }
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); } }
long newId = userGroupAdminService.insert(sp); LOGGER.info("Remapping userGroup " + oldId + " -> " + newId); remap.getUserGroups().put(oldId, newId);
/** * @deprecated misbehaves since usergroups introduction. Please use backup() */ @Override public RESTFullConfiguration getConfiguration(Boolean includeGRUsers) { RESTFullConfiguration cfg = new RESTFullConfiguration(); RESTFullUserList users = new RESTFullUserList(); List<GSUser> userlist = userAdminService.getFullList(null, null, null); for (GSUser user : userlist) { user.setGroups(userAdminService.getFull(user.getName()).getGroups()); } users.setList(userlist); cfg.setUserList(users); RESTFullUserGroupList profiles = new RESTFullUserGroupList(); profiles.setList(userGroupAdminService.getList(null, null, null)); cfg.setUserGroupList(profiles); RESTFullGSInstanceList instances = new RESTFullGSInstanceList(); instances.setList(instanceAdminService.getFullList(null, null, null)); cfg.setGsInstanceList(instances); RESTFullRuleList rules = new RESTFullRuleList(); rules.setList(ruleAdminService.getListFull(null, null, null)); cfg.setRuleList(rules); if ( includeGRUsers ) { RESTFullGRUserList grUsers = new RESTFullGRUserList(); grUsers.setList(grUserAdminService.getFullList(null, null, null)); cfg.setGrUserList(grUsers); } return cfg; }
/** * @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); }