Roberto Sánchez
2014-09-19 071a008cf28e733ca3aaafa57e675fd54a5ea33b
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -33,9 +33,9 @@
3333 import net.curisit.securis.services.exception.SeCurisServiceException;
3434 import net.curisit.securis.utils.TokenHelper;
3535
36
-import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
37
-import org.apache.logging.log4j.Logger;
3836 import org.apache.logging.log4j.LogManager;
37
+import org.apache.logging.log4j.Logger;
38
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
3939
4040 import com.google.inject.persist.Transactional;
4141
....@@ -56,7 +56,8 @@
5656 @Inject
5757 Provider<EntityManager> emProvider;
5858
59
- public LicenseResource() {}
59
+ public LicenseResource() {
60
+ }
6061
6162 /**
6263 *
....@@ -65,7 +66,9 @@
6566 @GET
6667 @Path("/")
6768 @Securable
68
- @Produces({ MediaType.APPLICATION_JSON })
69
+ @Produces({
70
+ MediaType.APPLICATION_JSON
71
+ })
6972 public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
7073 LOG.info("Getting licenses list ");
7174
....@@ -97,7 +100,9 @@
97100 @GET
98101 @Path("/{licId}")
99102 @Securable
100
- @Produces({ MediaType.APPLICATION_JSON })
103
+ @Produces({
104
+ MediaType.APPLICATION_JSON
105
+ })
101106 public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
102107 LOG.info("Getting organization data for id: {}: ", licId);
103108
....@@ -114,7 +119,9 @@
114119 @GET
115120 @Path("/{licId}/download")
116121 @Securable
117
- @Produces({ MediaType.APPLICATION_OCTET_STREAM })
122
+ @Produces({
123
+ MediaType.APPLICATION_OCTET_STREAM
124
+ })
118125 public Response download(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
119126
120127 EntityManager em = emProvider.get();
....@@ -137,7 +144,9 @@
137144 @Securable
138145 @Transactional
139146 @Consumes(MediaType.APPLICATION_JSON)
140
- @Produces({ MediaType.APPLICATION_JSON })
147
+ @Produces({
148
+ MediaType.APPLICATION_JSON
149
+ })
141150 public Response activate(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
142151
143152 EntityManager em = emProvider.get();
....@@ -163,7 +172,9 @@
163172 @Securable
164173 @Transactional
165174 @Consumes(MediaType.APPLICATION_JSON)
166
- @Produces({ MediaType.APPLICATION_JSON })
175
+ @Produces({
176
+ MediaType.APPLICATION_JSON
177
+ })
167178 public Response send(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
168179
169180 EntityManager em = emProvider.get();
....@@ -183,7 +194,9 @@
183194 @Securable
184195 @Transactional
185196 @Consumes(MediaType.APPLICATION_JSON)
186
- @Produces({ MediaType.APPLICATION_JSON })
197
+ @Produces({
198
+ MediaType.APPLICATION_JSON
199
+ })
187200 public Response cancel(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
188201
189202 EntityManager em = emProvider.get();
....@@ -208,7 +221,9 @@
208221 @Path("/")
209222 @Consumes(MediaType.APPLICATION_JSON)
210223 @Securable
211
- @Produces({ MediaType.APPLICATION_JSON })
224
+ @Produces({
225
+ MediaType.APPLICATION_JSON
226
+ })
212227 @Transactional
213228 public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
214229 LOG.info("Creating new license from create()");
....@@ -221,12 +236,10 @@
221236 return Response.status(Status.NOT_FOUND)
222237 .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build();
223238 } else {
224
- if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
225
- if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
226
- LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
227
- return Response.status(Status.UNAUTHORIZED)
228
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
229
- }
239
+ if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN) && !bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
240
+ LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
241
+ return Response.status(Status.UNAUTHORIZED)
242
+ .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
230243 }
231244 }
232245 }
....@@ -248,7 +261,9 @@
248261 @Path("/")
249262 @Consumes(MediaType.MULTIPART_FORM_DATA)
250263 @Securable
251
- @Produces({ MediaType.APPLICATION_JSON })
264
+ @Produces({
265
+ MediaType.APPLICATION_JSON
266
+ })
252267 @Transactional
253268 public Response createWithFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException {
254269 License lic = new License();
....@@ -268,7 +283,9 @@
268283 @Securable
269284 @Transactional
270285 @Consumes(MediaType.APPLICATION_JSON)
271
- @Produces({ MediaType.APPLICATION_JSON })
286
+ @Produces({
287
+ MediaType.APPLICATION_JSON
288
+ })
272289 public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
273290 LOG.info("Modifying organization with id: {}", licId);
274291
....@@ -290,7 +307,9 @@
290307 @Path("/{licId}")
291308 @Transactional
292309 @Securable
293
- @Produces({ MediaType.APPLICATION_JSON })
310
+ @Produces({
311
+ MediaType.APPLICATION_JSON
312
+ })
294313 public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
295314 LOG.info("Deleting license with id: {}", licId);
296315 EntityManager em = emProvider.get();
....@@ -317,11 +336,9 @@
317336 LOG.error("License with id {} not found in DB", licId);
318337 throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId);
319338 }
320
- if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
321
- if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
322
- LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
323
- throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
324
- }
339
+ if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN) && !bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
340
+ LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
341
+ throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
325342 }
326343 return lic;
327344 }