diff --git a/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java b/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java index 129a11a080..1fe66757b5 100644 --- a/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java +++ b/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java @@ -83,14 +83,14 @@ public class AlbumService { @GET @Produces("application/json") public Response findAll() { - return Response.ok(this.entityManager.createQuery("from Album where userId = '" + request.getUserPrincipal().getName() + "'").getResultList()).build(); + return Response.ok(this.entityManager.createQuery("from Album where userId = :id").setParameter("id", request.getUserPrincipal().getName()).getResultList()).build(); } @GET @Path("{id}") @Produces("application/json") public Response findById(@PathParam("id") String id) { - List result = this.entityManager.createQuery("from Album where id = " + id).getResultList(); + List result = this.entityManager.createQuery("from Album where id = :id").setParameter("id", id).getResultList(); if (result.isEmpty()) { return Response.status(Status.NOT_FOUND).build(); diff --git a/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/ProfileService.java b/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/ProfileService.java index 92e300dec5..62591227d7 100644 --- a/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/ProfileService.java +++ b/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/ProfileService.java @@ -43,7 +43,7 @@ public class ProfileService { @Produces("application/json") public Response view(@Context HttpServletRequest request) { Principal userPrincipal = request.getUserPrincipal(); - List albums = this.entityManager.createQuery("from Album where userId = '" + userPrincipal.getName() + "'").getResultList(); + List albums = this.entityManager.createQuery("from Album where userId = :id").setParameter("id", userPrincipal.getName()).getResultList(); return Response.ok(new Profile(userPrincipal.getName(), albums.size())).build(); }