public void removeAllUsers() throws NotFoundServiceEx { List<ShortUser> list = userAdminService.getList(null, null, null); for (ShortUser item : list) { LOGGER.warn("Removing " + item); boolean ret = userAdminService.delete(item.getId()); if ( !ret ) { LOGGER.error("Could not remove " + item); } } long count = userAdminService.getCount(null); if ( count > 0 ) { LOGGER.error("Items not removed"); } }
@Override public void update(String name, RESTInputUser user) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { try { GSUser old = userAdminService.get(name); update(old.getId(), user); } catch (NotFoundServiceEx ex) { LOGGER.warn("User not found: " + name); throw new NotFoundRestEx("User not found: " + name); } }
@Override public RESTFullUserList getUsers() throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { List<GSUser> users = userAdminService.getFullList(null, null, null); RESTFullUserList ret = new RESTFullUserList(); ret.setList(users); return ret; }
private void addIntoGroup(IdName userId, IdName groupId) throws InternalErrorRestEx, BadRequestRestEx, NotFoundRestEx { try { UserGroup group = getUserGroup(groupId); GSUser user = getUser(userId); // needed for param check GSUser fulluser = userAdminService.getFull(user.getName()); fulluser.getGroups().add(group); userAdminService.update(user); } catch (BadRequestRestEx e) { throw e; } catch (NotFoundRestEx e) { throw e; } catch (Exception e) { LOGGER.warn("Unexpected exception", e); throw new InternalErrorRestEx(e.getMessage()); } }
@Override public Response delete(String username, boolean cascade) throws ConflictRestEx, NotFoundRestEx, InternalErrorRestEx { try { if ( cascade ) { ruleAdminService.deleteRulesByUser(username); } else { RuleFilter filter = new RuleFilter(SpecialFilterType.ANY); filter.setUser(username); filter.getUser().setIncludeDefault(false); long cnt = ruleAdminService.count(filter); if ( cnt > 0 ) { throw new ConflictRestEx("Existing rules reference the user " + username); } } GSUser user = userAdminService.get(username); // may throw NotFoundServiceEx if ( ! userAdminService.delete(user.getId())) { LOGGER.warn("ILLEGAL STATE -- User not found: " + user); // this should not happen throw new NotFoundRestEx("ILLEGAL STATE -- User not found: " + user); } return Response.status(Status.OK).entity("OK\n").build(); } catch (GeoFenceRestEx ex) { // already handled throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("User not found: " + username); throw new NotFoundRestEx("User not found: " +username); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
long usersCount = geofenceRemoteService.getUserAdminService().getCount(null) + 1; List<org.geoserver.geofence.core.model.GSUser> usersList = geofenceRemoteService.getUserAdminService().getFullList(null, page, limit);
/** * @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; }
/** * Simplified operation used for quick re-insertion of data extracted with a GET op in the related service */ @Override public void setUsers(RESTShortUserList users) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { int okCnt = 0; for (RESTShortUser su : users) { LOGGER.info("Adding user " +su ); try { GSUser u = new GSUser(); u.setExtId(su.getExtId()); u.setName(su.getUserName()); u.setEnabled(su.isEnabled()); // group list is not retrievable in shortuser :| userAdminService.insert(u); okCnt++; } catch (Exception e) { LOGGER.info("Could not add user " +su +": " + e.getMessage()); } } LOGGER.info(okCnt+"/"+users.getUserList().size() + " items inserted"); }
@Override public long count(String nameLike) { return userAdminService.getCount(nameLike); }
@Override public RESTOutputUser get(String name) throws NotFoundRestEx, InternalErrorRestEx { try { GSUser ret = userAdminService.getFull(name); return toOutputUser(ret); } catch (NotFoundServiceEx ex) { LOGGER.warn("User not found: " + name); throw new NotFoundRestEx("User not found: " + name); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
public void deleteUser(GSUserModel user) throws ApplicationException { org.geoserver.geofence.core.model.GSUser remote_user = null; try { remote_user = geofenceRemoteService.getUserAdminService().get(user.getId()); geofenceRemoteService.getUserAdminService().delete(remote_user.getId()); } catch (NotFoundServiceEx e) { logger.error(e.getLocalizedMessage(), e.getCause()); throw new ApplicationException(e.getLocalizedMessage(), e.getCause()); } }
user.setId(null); long newId = userAdminService.insert(user); LOGGER.info("Remapping user " + oldId + " -> " + newId); remap.getUsers().put(oldId, newId);
@Override public RESTShortUserList getList(String nameLike, Integer page, Integer entries) throws BadRequestRestEx, InternalErrorRestEx { try { List<GSUser> list = userAdminService.getFullList(nameLike, page, entries); RESTShortUserList ret = new RESTShortUserList(list.size()); for (GSUser user : list) { ret.add(toShortUser(user)); } return ret; } catch (BadRequestServiceEx ex) { LOGGER.warn(ex.getMessage()); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.warn("Unexpected exception", ex); throw new InternalErrorRestEx(ex.getMessage()); } }
protected GSUser getUser(IdName userFilter) throws BadRequestRestEx, NotFoundRestEx { try { if (userFilter.getId() != null) { throw new BadRequestRestEx("Users can only be referenced by name"); } else if (userFilter.getName() != null) { return userAdminService.get(userFilter.getName()); } else { throw new BadRequestRestEx("Bad GSUser filter " + userFilter); } } catch (NotFoundServiceEx e) { LOGGER.warn("GSUser not found " + userFilter); throw new NotFoundRestEx("GSUser not found " + userFilter); } }
protected RESTBatch collectUsers(RESTBatch backup) { for (GSUser user : userAdminService.getFullList(null, null, null, true)) { RESTBatchOperation op = RESTBatchOperationFactory.createUserInputOp(); RESTInputUser input = new RESTInputUser(); op.setPayload(input); input.setAdmin(user.isAdmin()); input.setEmailAddress(user.getEmailAddress()); input.setEnabled(user.getEnabled()); input.setExtId(user.getExtId()); input.setFullName(user.getFullName()); input.setName(user.getName()); input.setPassword(user.getPassword()); if(user.getGroups() != null) { input.setGroups(new ArrayList<IdName>(user.getGroups().size())); for (UserGroup userGroup : user.getGroups()) { input.getGroups().add(new IdName(userGroup.getName())); } } backup.add(op); } return backup; }