rsanchez
2017-04-13 84588a793c9484f9182d253ed83ad11687a1d4f8
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -38,6 +38,7 @@
3838 import net.curisit.securis.db.PackMetadata;
3939 import net.curisit.securis.db.PackStatus;
4040 import net.curisit.securis.db.User;
41
+import net.curisit.securis.db.User.Rol;
4142 import net.curisit.securis.ioc.EnsureTransaction;
4243 import net.curisit.securis.security.BasicSecurityContext;
4344 import net.curisit.securis.security.Securable;
....@@ -90,12 +91,15 @@
9091 LOG.info("Getting all packs for user: " + bsc.getUserPrincipal());
9192 q = em.createNamedQuery("list-packs", Pack.class);
9293 } else {
93
- if (bsc.getOrganizationsIds() == null || bsc.getOrganizationsIds().isEmpty() || //
94
- bsc.getApplicationsIds() == null || bsc.getApplicationsIds().isEmpty()) {
94
+ if (bsc.getApplicationsIds() == null || bsc.getApplicationsIds().isEmpty()) {
9595 return Response.ok().build();
9696 }
97
- q = em.createNamedQuery("list-packs-by-orgs-apps", Pack.class);
98
- q.setParameter("list_ids_org", bsc.getOrganizationsIds());
97
+ if (bsc.getOrganizationsIds() == null || bsc.getOrganizationsIds().isEmpty()) {
98
+ q = em.createNamedQuery("list-packs-by-apps", Pack.class);
99
+ } else {
100
+ q = em.createNamedQuery("list-packs-by-orgs-apps", Pack.class);
101
+ q.setParameter("list_ids_org", bsc.getOrganizationsIds());
102
+ }
99103 q.setParameter("list_ids_app", bsc.getApplicationsIds());
100104 LOG.info("Getting packs from orgs: {} and apps: {}", bsc.getOrganizationsIds(), bsc.getApplicationsIds());
101105 }
....@@ -140,7 +144,7 @@
140144
141145 @POST
142146 @Path("/")
143
- @Securable
147
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
144148 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
145149 @Consumes(MediaType.APPLICATION_JSON)
146150 @Produces({ MediaType.APPLICATION_JSON })
....@@ -207,7 +211,7 @@
207211 */
208212 @GET
209213 @Path("/{packId}/next_license_code")
210
- @Securable
214
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
211215 @Produces({ MediaType.TEXT_PLAIN })
212216 public Response getCodeSuffix(@PathParam("packId") Integer packId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
213217 // EntityManager em = emProvider.get();
....@@ -249,7 +253,7 @@
249253 @POST
250254 @Path("/{packId}")
251255 @EnsureTransaction
252
- @Securable
256
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
253257 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
254258 @Consumes(MediaType.APPLICATION_JSON)
255259 @Produces({ MediaType.APPLICATION_JSON })
....@@ -314,7 +318,7 @@
314318 @POST
315319 @Path("/{packId}/activate")
316320 @EnsureTransaction
317
- @Securable
321
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
318322 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
319323 @Consumes(MediaType.APPLICATION_JSON)
320324 @Produces({ MediaType.APPLICATION_JSON })
....@@ -338,7 +342,7 @@
338342 @POST
339343 @Path("/{packId}/putonhold")
340344 @EnsureTransaction
341
- @Securable
345
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
342346 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
343347 @Consumes(MediaType.APPLICATION_JSON)
344348 @Produces({ MediaType.APPLICATION_JSON })
....@@ -362,7 +366,7 @@
362366 @POST
363367 @Path("/{packId}/cancel")
364368 @EnsureTransaction
365
- @Securable
369
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
366370 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
367371 @Consumes(MediaType.APPLICATION_JSON)
368372 @Produces({ MediaType.APPLICATION_JSON })
....@@ -403,7 +407,7 @@
403407
404408 @DELETE
405409 @Path("/{packId}")
406
- @Securable
410
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
407411 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
408412 @EnsureTransaction
409413 @Produces({ MediaType.APPLICATION_JSON })