@Test public void testHelloEndpoint() { String secret ="mysecret"; RestAssured.baseURI = keycloakURL; Response response = given().urlEncodingEnabled(true) .auth().preemptive().basic("quarkus-client", secret) .param("grant_type", "password") .param("client_id", "quarkus-client") .param("username", "test") .param("password", "test") .header("Accept", ContentType.JSON.getAcceptHeader()) .post("/auth/realms/quarkus-realm/protocol/openid-connect/token") .then().statusCode(200).extract() .response(); JsonReader jsonReader = Json.createReader(new StringReader(response.getBody().asString())); JsonObject object = jsonReader.readObject(); String userToken = object.getString("access_token"); response = given().urlEncodingEnabled(true) .auth().preemptive().basic("quarkus-client", secret) .param("grant_type", "password") .param("client_id", "quarkus-client") .param("username", "admin") .param("password", "test") .header("Accept", ContentType.JSON.getAcceptHeader()) .post("/auth/realms/quarkus-realm/protocol/openid-connect/token") .then().statusCode(200).extract() .response(); jsonReader = Json.createReader(new StringReader(response.getBody().asString())); object = jsonReader.readObject(); String adminToken = object.getString("access_token"); RestAssured.baseURI = "http: given().auth().preemptive() .oauth2(userToken) .when().get("/customers") .then() .statusCode(200) .body("$.size()", is(2)); JsonObject objOrder = Json.createObjectBuilder() .add("item", "bike") .add("price", new Long(100)) .build(); given().auth() .oauth2(adminToken) .contentType("application/json") .body(objOrder.toString()) .when() .post("/orders/1") .then() .statusCode(201); objOrder = Json.createObjectBuilder() .add("id", new Long(1)) .add("item", "mountain bike") .add("price", new Long(100)) .build(); given().auth() .oauth2(adminToken) .contentType("application/json") .body(objOrder.toString()) .when() .put("/orders") .then() .statusCode(204); given().auth() .oauth2(userToken) .when().get("/orders?customerId=1") .then() .statusCode(200) .body(containsString("mountain bike")); given().auth() .oauth2(adminToken) .when().delete("/orders/1") .then() .statusCode(204); }
@DELETE @RolesAllowed("admin") public Response delete(@QueryParam("id") Long customerId) { customerRepository.deleteCustomer(customerId); return Response.status(204).build(); }
CustomerEndpoint { @DELETE @RolesAllowed("admin") public Response delete(@QueryParam("id") Long customerId) { customerRepository.deleteCustomer(customerId); return Response.status(204).build(); } }
CustomerEndpoint { @DELETE @RolesAllowed("admin") public Response delete(@QueryParam("id") Long customerId) { customerRepository.deleteCustomer(customerId); return Response.status(204).build(); }  }
CustomerEndpoint { @DELETE @RolesAllowed("admin") public Response delete(@QueryParam("id") Long customerId) { customerRepository.deleteCustomer(customerId); return Response.status(204).build(); }  @GET @RolesAllowed("user") List<Customer> getAll(); @POST @RolesAllowed("admin") Response create(Customer customer); @PUT @RolesAllowed("admin") Response update(Customer customer); @DELETE @RolesAllowed("admin") Response delete(@QueryParam("id") Long customerId); }
CustomerEndpoint { @DELETE @RolesAllowed("admin") public Response delete(@QueryParam("id") Long customerId) { customerRepository.deleteCustomer(customerId); return Response.status(204).build(); }  @GET @RolesAllowed("user") List<Customer> getAll(); @POST @RolesAllowed("admin") Response create(Customer customer); @PUT @RolesAllowed("admin") Response update(Customer customer); @DELETE @RolesAllowed("admin") Response delete(@QueryParam("id") Long customerId);  }