@Test public void testDeleteUser() throws Exception { createUser("deleteMe"); String xml = sendRequest(GET, "/users", 200); assertTrue(xml.contains("deleteMe")); sendRequest(DELETE, "/users/idontexist", 400); sendRequest(DELETE, "/users/deleteMe", 200); sendRequest(GET, "/users/deleteMe", 404); }
@DELETE @Path("{userCriteria}") public Response deleteUser(@PathParam("userCriteria") final String userCriteria) { writeLock(); try { if (!hasEditRights()) { throw getException(Status.BAD_REQUEST, new RuntimeException(m_securityContext.getUserPrincipal().getName() + " does not have write access to users!")); } OnmsUser user = null; try { user = m_userManager.getOnmsUser(userCriteria); } catch (final Throwable t) { throw getException(Status.BAD_REQUEST, t); } if (user == null) throw getException(Status.BAD_REQUEST, "deleteUser: User does not exist: " + userCriteria); log().debug("deleteUser: deleting user " + user); try { m_userManager.deleteUser(user.getUsername()); } catch (final Throwable t) { throw getException(Status.INTERNAL_SERVER_ERROR, t); } return Response.ok().build(); } finally { writeUnlock(); } }
UserRestService extends OnmsRestService { @DELETE @Path("{userCriteria}") public Response deleteUser(@PathParam("userCriteria") final String userCriteria) { writeLock(); try { if (!hasEditRights()) { throw getException(Status.BAD_REQUEST, new RuntimeException(m_securityContext.getUserPrincipal().getName() + " does not have write access to users!")); } OnmsUser user = null; try { user = m_userManager.getOnmsUser(userCriteria); } catch (final Throwable t) { throw getException(Status.BAD_REQUEST, t); } if (user == null) throw getException(Status.BAD_REQUEST, "deleteUser: User does not exist: " + userCriteria); log().debug("deleteUser: deleting user " + user); try { m_userManager.deleteUser(user.getUsername()); } catch (final Throwable t) { throw getException(Status.INTERNAL_SERVER_ERROR, t); } return Response.ok().build(); } finally { writeUnlock(); } } }
UserRestService extends OnmsRestService { @DELETE @Path("{userCriteria}") public Response deleteUser(@PathParam("userCriteria") final String userCriteria) { writeLock(); try { if (!hasEditRights()) { throw getException(Status.BAD_REQUEST, new RuntimeException(m_securityContext.getUserPrincipal().getName() + " does not have write access to users!")); } OnmsUser user = null; try { user = m_userManager.getOnmsUser(userCriteria); } catch (final Throwable t) { throw getException(Status.BAD_REQUEST, t); } if (user == null) throw getException(Status.BAD_REQUEST, "deleteUser: User does not exist: " + userCriteria); log().debug("deleteUser: deleting user " + user); try { m_userManager.deleteUser(user.getUsername()); } catch (final Throwable t) { throw getException(Status.INTERNAL_SERVER_ERROR, t); } return Response.ok().build(); } finally { writeUnlock(); } }  }
UserRestService extends OnmsRestService { @DELETE @Path("{userCriteria}") public Response deleteUser(@PathParam("userCriteria") final String userCriteria) { writeLock(); try { if (!hasEditRights()) { throw getException(Status.BAD_REQUEST, new RuntimeException(m_securityContext.getUserPrincipal().getName() + " does not have write access to users!")); } OnmsUser user = null; try { user = m_userManager.getOnmsUser(userCriteria); } catch (final Throwable t) { throw getException(Status.BAD_REQUEST, t); } if (user == null) throw getException(Status.BAD_REQUEST, "deleteUser: User does not exist: " + userCriteria); log().debug("deleteUser: deleting user " + user); try { m_userManager.deleteUser(user.getUsername()); } catch (final Throwable t) { throw getException(Status.INTERNAL_SERVER_ERROR, t); } return Response.ok().build(); } finally { writeUnlock(); } }  @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) OnmsUserList getUsers(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Path("{username}") OnmsUser getUser(@PathParam("username") final String username); @POST @Consumes(MediaType.APPLICATION_XML) Response addUser(final OnmsUser user); @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("{userCriteria}") Response updateUser(@PathParam("userCriteria") final String userCriteria, final MultivaluedMapImpl params); @DELETE @Path("{userCriteria}") Response deleteUser(@PathParam("userCriteria") final String userCriteria); boolean hasEditRights(); }
UserRestService extends OnmsRestService { @DELETE @Path("{userCriteria}") public Response deleteUser(@PathParam("userCriteria") final String userCriteria) { writeLock(); try { if (!hasEditRights()) { throw getException(Status.BAD_REQUEST, new RuntimeException(m_securityContext.getUserPrincipal().getName() + " does not have write access to users!")); } OnmsUser user = null; try { user = m_userManager.getOnmsUser(userCriteria); } catch (final Throwable t) { throw getException(Status.BAD_REQUEST, t); } if (user == null) throw getException(Status.BAD_REQUEST, "deleteUser: User does not exist: " + userCriteria); log().debug("deleteUser: deleting user " + user); try { m_userManager.deleteUser(user.getUsername()); } catch (final Throwable t) { throw getException(Status.INTERNAL_SERVER_ERROR, t); } return Response.ok().build(); } finally { writeUnlock(); } }  @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) OnmsUserList getUsers(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Path("{username}") OnmsUser getUser(@PathParam("username") final String username); @POST @Consumes(MediaType.APPLICATION_XML) Response addUser(final OnmsUser user); @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("{userCriteria}") Response updateUser(@PathParam("userCriteria") final String userCriteria, final MultivaluedMapImpl params); @DELETE @Path("{userCriteria}") Response deleteUser(@PathParam("userCriteria") final String userCriteria); boolean hasEditRights();  }