From 8d5386be38db25a2a41c3bf6c876adee21ca26cc Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Fri, 19 Sep 2014 08:26:02 +0000
Subject: [PATCH] #396 fix - Fixed more SonarQube issues

---
 securis/src/main/java/net/curisit/securis/services/LicenseResource.java |  525 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 261 insertions(+), 264 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
index f7f2ec5..1ef497d 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
@@ -40,317 +40,314 @@
 import com.google.inject.persist.Transactional;
 
 /**
- * License resource, this service will provide methods to create, modify and delete licenses
+ * License resource, this service will provide methods to create, modify and
+ * delete licenses
  * 
  * @author roberto <roberto.sanchez@curisit.net>
  */
 @Path("/license")
 public class LicenseResource {
 
-	private static final Logger LOG = LogManager.getLogger(LicenseResource.class);
+    private static final Logger LOG = LogManager.getLogger(LicenseResource.class);
 
-	@Inject
-	TokenHelper tokenHelper;
+    @Inject
+    TokenHelper tokenHelper;
 
-	@Inject
-	Provider<EntityManager> emProvider;
+    @Inject
+    Provider<EntityManager> emProvider;
 
-	public LicenseResource() {
-	}
+    public LicenseResource() {}
 
-	/**
-	 * 
-	 * @return the server version in format majorVersion.minorVersion
-	 */
-	@GET
-	@Path("/")
-	@Securable
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
-		LOG.info("Getting licenses list ");
+    /**
+     * 
+     * @return the server version in format majorVersion.minorVersion
+     */
+    @GET
+    @Path("/")
+    @Securable
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
+        LOG.info("Getting licenses list ");
 
-		EntityManager em = emProvider.get();
+        EntityManager em = emProvider.get();
 
-		if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
-			Pack pack = em.find(Pack.class, packId);
-			if (pack == null)
-				return Response.ok().build();
-			if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
-				LOG.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal());
-				return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack licenses").build();
-			}
-		}
-		TypedQuery<License> q = em.createNamedQuery("list-licenses-by-pack", License.class);
-		q.setParameter("packId", packId);
-		List<License> list = q.getResultList();
+        if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
+            Pack pack = em.find(Pack.class, packId);
+            if (pack == null) {
+                return Response.ok().build();
+            }
+            if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
+                LOG.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal());
+                return Response.status(Status.UNAUTHORIZED)
+                        .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack licenses").build();
+            }
+        }
+        TypedQuery<License> q = em.createNamedQuery("list-licenses-by-pack", License.class);
+        q.setParameter("packId", packId);
+        List<License> list = q.getResultList();
 
-		return Response.ok(list).build();
-	}
+        return Response.ok(list).build();
+    }
 
-	/**
-	 * 
-	 * @return the server version in format majorVersion.minorVersion
-	 * @throws SeCurisServiceException
-	 */
-	@GET
-	@Path("/{licId}")
-	@Securable
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
-		LOG.info("Getting organization data for id: {}: ", licId);
+    /**
+     * 
+     * @return the server version in format majorVersion.minorVersion
+     * @throws SeCurisServiceException
+     */
+    @GET
+    @Path("/{licId}")
+    @Securable
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+        LOG.info("Getting organization data for id: {}: ", licId);
 
-		EntityManager em = emProvider.get();
-		License lic = getCurrentLicense(licId, bsc, em);
-		return Response.ok(lic).build();
-	}
+        EntityManager em = emProvider.get();
+        License lic = getCurrentLicense(licId, bsc, em);
+        return Response.ok(lic).build();
+    }
 
-	/**
-	 * 
-	 * @return The license file, only of license is active
-	 * @throws SeCurisServiceException
-	 */
-	@GET
-	@Path("/{licId}/download")
-	@Securable
-	@Produces(
-		{ MediaType.APPLICATION_OCTET_STREAM })
-	public Response download(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+    /**
+     * 
+     * @return The license file, only of license is active
+     * @throws SeCurisServiceException
+     */
+    @GET
+    @Path("/{licId}/download")
+    @Securable
+    @Produces({ MediaType.APPLICATION_OCTET_STREAM })
+    public Response download(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
-		EntityManager em = emProvider.get();
-		License lic = getCurrentLicense(licId, bsc, em);
+        EntityManager em = emProvider.get();
+        License lic = getCurrentLicense(licId, bsc, em);
 
-		if (lic.getLicenseData() == null) {
-			LOG.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
-			throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License has not contain data to generate license file");
-		}
-		if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) {
-			LOG.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal());
-			throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License is not active, so It can not be downloaded");
-		}
-		return Response.ok(lic.getLicenseData()).build();
-	}
+        if (lic.getLicenseData() == null) {
+            LOG.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
+            throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License has not contain data to generate license file");
+        }
+        if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) {
+            LOG.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal());
+            throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License is not active, so It can not be downloaded");
+        }
+        return Response.ok(lic.getLicenseData()).build();
+    }
 
-	@PUT
-	@POST
-	@Path("/{licId}/activate")
-	@Securable
-	@Transactional
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response activate(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+    @PUT
+    @POST
+    @Path("/{licId}/activate")
+    @Securable
+    @Transactional
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response activate(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
-		EntityManager em = emProvider.get();
-		License lic = getCurrentLicense(licId, bsc, em);
+        EntityManager em = emProvider.get();
+        License lic = getCurrentLicense(licId, bsc, em);
 
-		if (License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
-			LOG.error("License with id {} can not be activated from current license status", licId);
-			throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be activated from the current license status");
-		}
+        if (License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
+            LOG.error("License with id {} can not be activated from current license status", licId);
+            throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId
+                    + " can not be activated from the current license status");
+        }
 
-		lic.setStatus(License.Status.ACTIVE);
-		lic.setModificationTimestamp(new Date());
-		em.persist(lic);
-		User user = getUser(bsc.getUserPrincipal().getName(), em);
-		em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.ACTIVATE));
-		return Response.ok(lic).build();
-	}
+        lic.setStatus(License.Status.ACTIVE);
+        lic.setModificationTimestamp(new Date());
+        em.persist(lic);
+        User user = getUser(bsc.getUserPrincipal().getName(), em);
+        em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.ACTIVATE));
+        return Response.ok(lic).build();
+    }
 
-	@PUT
-	@POST
-	@Path("/{licId}/send")
-	@Securable
-	@Transactional
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response send(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+    @PUT
+    @POST
+    @Path("/{licId}/send")
+    @Securable
+    @Transactional
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response send(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
-		EntityManager em = emProvider.get();
-		License lic = getCurrentLicense(licId, bsc, em);
+        EntityManager em = emProvider.get();
+        License lic = getCurrentLicense(licId, bsc, em);
 
-		User user = getUser(bsc.getUserPrincipal().getName(), em);
-		// TODO: Send mail with lic file
-		lic.setModificationTimestamp(new Date());
-		em.persist(lic);
-		em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.SEND, "Email sent to: " + lic.getEmail()));
-		return Response.ok(lic).build();
-	}
+        User user = getUser(bsc.getUserPrincipal().getName(), em);
+        // TODO: Send mail with lic file
+        lic.setModificationTimestamp(new Date());
+        em.persist(lic);
+        em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.SEND, "Email sent to: " + lic.getEmail()));
+        return Response.ok(lic).build();
+    }
 
-	@PUT
-	@POST
-	@Path("/{licId}/cancel")
-	@Securable
-	@Transactional
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response cancel(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+    @PUT
+    @POST
+    @Path("/{licId}/cancel")
+    @Securable
+    @Transactional
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response cancel(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
-		EntityManager em = emProvider.get();
-		License lic = getCurrentLicense(licId, bsc, em);
+        EntityManager em = emProvider.get();
+        License lic = getCurrentLicense(licId, bsc, em);
 
-		if (License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) {
-			LOG.error("License with id {} can not be canceled from current license status", licId);
-			throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be canceled from the current license status");
-		}
+        if (License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) {
+            LOG.error("License with id {} can not be canceled from current license status", licId);
+            throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId
+                    + " can not be canceled from the current license status");
+        }
 
-		lic.setStatus(License.Status.CANCELED);
-		lic.setModificationTimestamp(new Date());
-		em.persist(lic);
+        lic.setStatus(License.Status.CANCELED);
+        lic.setModificationTimestamp(new Date());
+        em.persist(lic);
 
-		User user = getUser(bsc.getUserPrincipal().getName(), em);
-		em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.CANCEL));
-		return Response.ok(lic).build();
-	}
+        User user = getUser(bsc.getUserPrincipal().getName(), em);
+        em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.CANCEL));
+        return Response.ok(lic).build();
+    }
 
-	@POST
-	@Path("/")
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Securable
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	@Transactional
-	public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
-		LOG.info("Creating new license from create()");
-		EntityManager em = emProvider.get();
-		Pack pack = null;
-		if (lic.getPackId() != null) {
-			pack = em.find(Pack.class, lic.getPackId());
-			if (pack == null) {
-				LOG.error("License pack with id {} not found in DB", lic.getPackId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build();
-			} else {
-				if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
-					if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
-						LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
-						return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
-					}
-				}
-			}
-		}
+    @POST
+    @Path("/")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Securable
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Transactional
+    public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+        LOG.info("Creating new license from create()");
+        EntityManager em = emProvider.get();
+        Pack pack = null;
+        if (lic.getPackId() != null) {
+            pack = em.find(Pack.class, lic.getPackId());
+            if (pack == null) {
+                LOG.error("License pack with id {} not found in DB", lic.getPackId());
+                return Response.status(Status.NOT_FOUND)
+                        .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build();
+            } else {
+                if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
+                    if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
+                        LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
+                        return Response.status(Status.UNAUTHORIZED)
+                                .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
+                    }
+                }
+            }
+        }
 
-		User createdBy = getUser(bsc.getUserPrincipal().getName(), em);
+        User createdBy = getUser(bsc.getUserPrincipal().getName(), em);
 
-		// ODO: Manage status if request data is set
-		lic.setCreatedBy(createdBy);
-		lic.setStatus(License.Status.CREATED);
-		lic.setCreationTimestamp(new Date());
-		lic.setModificationTimestamp(lic.getCreationTimestamp());
-		em.persist(lic);
-		em.persist(createLicenseHistoryAction(lic, createdBy, LicenseHistory.Actions.CREATE));
+        // ODO: Manage status if request data is set
+        lic.setCreatedBy(createdBy);
+        lic.setStatus(License.Status.CREATED);
+        lic.setCreationTimestamp(new Date());
+        lic.setModificationTimestamp(lic.getCreationTimestamp());
+        em.persist(lic);
+        em.persist(createLicenseHistoryAction(lic, createdBy, LicenseHistory.Actions.CREATE));
 
-		return Response.ok(lic).build();
-	}
+        return Response.ok(lic).build();
+    }
 
-	@POST
-	@Path("/")
-	@Consumes(MediaType.MULTIPART_FORM_DATA)
-	@Securable
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	@Transactional
-	public Response createWithFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException {
-		License lic = new License();
-		lic.setCode(mpfdi.getFormDataPart("code", String.class, null));
-		lic.setRequestData(mpfdi.getFormDataPart("request_data", String.class, null));
-		lic.setPackId(mpfdi.getFormDataPart("pack_id", Integer.class, null));
-		lic.setFullName(mpfdi.getFormDataPart("full_name", String.class, null));
-		lic.setEmail(mpfdi.getFormDataPart("email", String.class, null));
-		lic.setComments(mpfdi.getFormDataPart("comments", String.class, null));
+    @POST
+    @Path("/")
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Securable
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Transactional
+    public Response createWithFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException {
+        License lic = new License();
+        lic.setCode(mpfdi.getFormDataPart("code", String.class, null));
+        lic.setRequestData(mpfdi.getFormDataPart("request_data", String.class, null));
+        lic.setPackId(mpfdi.getFormDataPart("pack_id", Integer.class, null));
+        lic.setFullName(mpfdi.getFormDataPart("full_name", String.class, null));
+        lic.setEmail(mpfdi.getFormDataPart("email", String.class, null));
+        lic.setComments(mpfdi.getFormDataPart("comments", String.class, null));
 
-		return create(lic, bsc);
-	}
+        return create(lic, bsc);
+    }
 
-	@PUT
-	@POST
-	@Path("/{licId}")
-	@Securable
-	@Transactional
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
-		LOG.info("Modifying organization with id: {}", licId);
+    @PUT
+    @POST
+    @Path("/{licId}")
+    @Securable
+    @Transactional
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+        LOG.info("Modifying organization with id: {}", licId);
 
-		EntityManager em = emProvider.get();
+        EntityManager em = emProvider.get();
 
-		License currentLicense = getCurrentLicense(licId, bsc, em);
+        License currentLicense = getCurrentLicense(licId, bsc, em);
 
-		currentLicense.setCode(lic.getCode());
-		currentLicense.setFullName(lic.getFullName());
-		currentLicense.setEmail(lic.getEmail());
-		currentLicense.setRequestData(lic.getRequestData());
-		currentLicense.setModificationTimestamp(new Date());
-		em.persist(currentLicense);
+        currentLicense.setCode(lic.getCode());
+        currentLicense.setFullName(lic.getFullName());
+        currentLicense.setEmail(lic.getEmail());
+        currentLicense.setRequestData(lic.getRequestData());
+        currentLicense.setModificationTimestamp(new Date());
+        em.persist(currentLicense);
 
-		return Response.ok(currentLicense).build();
-	}
+        return Response.ok(currentLicense).build();
+    }
 
-	@DELETE
-	@Path("/{licId}")
-	@Transactional
-	@Securable
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
-		LOG.info("Deleting license with id: {}", licId);
-		EntityManager em = emProvider.get();
-		License lic = getCurrentLicense(licId, bsc, em);
+    @DELETE
+    @Path("/{licId}")
+    @Transactional
+    @Securable
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
+        LOG.info("Deleting license with id: {}", licId);
+        EntityManager em = emProvider.get();
+        License lic = getCurrentLicense(licId, bsc, em);
 
-		if (lic.getStatus() != License.Status.CANCELED || lic.getStatus() != License.Status.CREATED) {
-			LOG.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus());
-			return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License can not be deleted in current status").build();
-		}
+        if (lic.getStatus() != License.Status.CANCELED || lic.getStatus() != License.Status.CREATED) {
+            LOG.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus());
+            return Response.status(Status.FORBIDDEN)
+                    .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License can not be deleted in current status").build();
+        }
 
-		em.remove(lic);
-		return Response.ok(Utils.createMap("success", true, "id", licId)).build();
-	}
+        em.remove(lic);
+        return Response.ok(Utils.createMap("success", true, "id", licId)).build();
+    }
 
-	private License getCurrentLicense(Integer licId, BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException {
-		if (licId == null || licId.equals("")) {
-			LOG.error("License ID is mandatory");
-			throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "Missing license ID");
-		}
+    private License getCurrentLicense(Integer licId, BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException {
+        if (licId == null || "".equals(licId)) {
+            LOG.error("License ID is mandatory");
+            throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "Missing license ID");
+        }
 
-		License lic = em.find(License.class, licId);
-		if (lic == null) {
-			LOG.error("License with id {} not found in DB", licId);
-			throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId);
-		}
-		if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
-			if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
-				LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
-				throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
-			}
-		}
-		return lic;
-	}
+        License lic = em.find(License.class, licId);
+        if (lic == null) {
+            LOG.error("License with id {} not found in DB", licId);
+            throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId);
+        }
+        if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
+            if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
+                LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
+                throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
+            }
+        }
+        return lic;
+    }
 
-	private User getUser(String username, EntityManager em) throws SeCurisServiceException {
-		User user = null;
-		if (username != null) {
-			user = em.find(User.class, username);
-			if (user == null) {
-				throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "User not found with username: " + username);
-			}
-		}
-		return user;
-	}
+    private User getUser(String username, EntityManager em) throws SeCurisServiceException {
+        User user = null;
+        if (username != null) {
+            user = em.find(User.class, username);
+            if (user == null) {
+                throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "User not found with username: " + username);
+            }
+        }
+        return user;
+    }
 
-	private LicenseHistory createLicenseHistoryAction(License lic, User user, String action, String comments) {
-		LicenseHistory lh = new LicenseHistory();
-		lh.setLicense(lic);
-		lh.setUser(user);
-		lh.setTimestamp(new Date());
-		lh.setAction(action);
-		lh.setComments(comments);
-		return lh;
-	}
+    private LicenseHistory createLicenseHistoryAction(License lic, User user, String action, String comments) {
+        LicenseHistory lh = new LicenseHistory();
+        lh.setLicense(lic);
+        lh.setUser(user);
+        lh.setTimestamp(new Date());
+        lh.setAction(action);
+        lh.setComments(comments);
+        return lh;
+    }
 
-	private LicenseHistory createLicenseHistoryAction(License lic, User user, String action) {
-		return createLicenseHistoryAction(lic, user, action, null);
-	}
+    private LicenseHistory createLicenseHistoryAction(License lic, User user, String action) {
+        return createLicenseHistoryAction(lic, user, action, null);
+    }
 }

--
Gitblit v1.3.2