Roberto Sánchez
2014-09-19 071a008cf28e733ca3aaafa57e675fd54a5ea33b
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -5,7 +5,6 @@
55 import java.util.List;
66
77 import javax.annotation.security.RolesAllowed;
8
-import javax.crypto.SealedObject;
98 import javax.inject.Inject;
109 import javax.inject.Provider;
1110 import javax.persistence.EntityManager;
....@@ -34,8 +33,8 @@
3433 import net.curisit.securis.security.Securable;
3534 import net.curisit.securis.utils.TokenHelper;
3635
37
-import org.apache.logging.log4j.Logger;
3836 import org.apache.logging.log4j.LogManager;
37
+import org.apache.logging.log4j.Logger;
3938
4039 import com.google.inject.persist.Transactional;
4140
....@@ -56,7 +55,8 @@
5655 @Inject
5756 Provider<EntityManager> emProvider;
5857
59
- public PackResource() {}
58
+ public PackResource() {
59
+ }
6060
6161 /**
6262 *
....@@ -65,7 +65,9 @@
6565 @GET
6666 @Path("/")
6767 @Securable
68
- @Produces({ MediaType.APPLICATION_JSON })
68
+ @Produces({
69
+ MediaType.APPLICATION_JSON
70
+ })
6971 public Response index(@Context BasicSecurityContext bsc) {
7072 LOG.info("Getting packs list ");
7173
....@@ -100,7 +102,9 @@
100102 @GET
101103 @Path("/{packId}")
102104 @Securable
103
- @Produces({ MediaType.APPLICATION_JSON })
105
+ @Produces({
106
+ MediaType.APPLICATION_JSON
107
+ })
104108 public Response get(@PathParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
105109 LOG.info("Getting pack data for id: {}: ", packId);
106110 if (packId == null || "".equals(packId)) {
....@@ -114,10 +118,9 @@
114118 LOG.error("Pack with id {} not found in DB", packId);
115119 return Response.status(Status.NOT_FOUND).build();
116120 }
117
- if (bsc.isUserInRole(BasicSecurityContext.ROL_ADVANCE)) {
118
- if (bsc.getOrganizationsIds() == null || !bsc.getOrganizationsIds().contains(pack.getOrgId())) {
119
- return generateErrorUnathorizedAccess(pack, bsc.getUserPrincipal());
120
- }
121
+ if (bsc.isUserInRole(BasicSecurityContext.ROL_ADVANCE)
122
+ && (bsc.getOrganizationsIds() == null || !bsc.getOrganizationsIds().contains(pack.getOrgId()))) {
123
+ return generateErrorUnathorizedAccess(pack, bsc.getUserPrincipal());
121124 }
122125 return Response.ok(pack).build();
123126 }
....@@ -127,7 +130,9 @@
127130 @Securable
128131 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
129132 @Consumes(MediaType.APPLICATION_JSON)
130
- @Produces({ MediaType.APPLICATION_JSON })
133
+ @Produces({
134
+ MediaType.APPLICATION_JSON
135
+ })
131136 @Transactional
132137 public Response create(Pack pack, @Context BasicSecurityContext bsc) {
133138 LOG.info("Creating new pack");
....@@ -173,7 +178,9 @@
173178 @Securable
174179 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
175180 @Consumes(MediaType.APPLICATION_JSON)
176
- @Produces({ MediaType.APPLICATION_JSON })
181
+ @Produces({
182
+ MediaType.APPLICATION_JSON
183
+ })
177184 public Response modify(Pack pack, @PathParam("packId") Integer packId) {
178185 LOG.info("Modifying pack with id: {}", packId);
179186 EntityManager em = emProvider.get();
....@@ -218,7 +225,9 @@
218225 @Securable
219226 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
220227 @Transactional
221
- @Produces({ MediaType.APPLICATION_JSON })
228
+ @Produces({
229
+ MediaType.APPLICATION_JSON
230
+ })
222231 public Response delete(@PathParam("packId") String packId) {
223232 LOG.info("Deleting pack with id: {}", packId);
224233 EntityManager em = emProvider.get();