@Test public void checkAuthenticationOnPostAndDeleteMethods(){ WebResource resource = client().resource("/" + ServerAPI.LICENSE_RESOURCE); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.UNAUTHORIZED_401, response.getStatus()); resource = client().resource("/" + ServerAPI.LICENSE_RESOURCE + "/licenseId"); response = resource.accept(MediaType.APPLICATION_JSON).delete(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.UNAUTHORIZED_401, response.getStatus()); resource = client().resource("/" + ServerAPI.LICENSE_RESOURCE + "/licenseId"); response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.UNAUTHORIZED_401, response.getStatus()); }
@DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postLicense(@Auth final DbCredential credential, final License license); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @POST @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response approve(@Auth final DbCredential credential, @PathParam("name") final String name, @QueryParam(ServerAPI.APPROVED_PARAM) final BooleanParam approved); }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postLicense(@Auth final DbCredential credential, final License license); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @POST @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response approve(@Auth final DbCredential credential, @PathParam("name") final String name, @QueryParam(ServerAPI.APPROVED_PARAM) final BooleanParam approved);  }