From 52ce72b22ef8d92a1f35b4993bcddaaa66d67350 Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Thu, 18 Sep 2014 17:55:35 +0000
Subject: [PATCH] #396 fix - Fixed some SonarQube issues

---
 securis/src/main/java/net/curisit/securis/RestServicesApplication.java       |    4 
 securis/src/main/java/net/curisit/securis/services/ApiResource.java          |    2 
 securis/src/main/java/net/curisit/securis/AuthFilter.java                    |    6 
 securis/src/main/java/net/curisit/securis/MainApp.java                       |   10 
 securis/src/main/java/net/curisit/securis/services/BasicServices.java        |   18 
 securis/src/main/java/net/curisit/securis/services/ApplicationResource.java  |   20 +-
 securis/src/main/java/net/curisit/securis/services/PackResource.java         |  100 +++++----
 securis/src/main/java/net/curisit/securis/services/LicenseServices.java      |   11 
 securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java  |   67 +++--
 securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java       |   16 
 securis/src/main/java/net/curisit/securis/utils/TokenHelper.java             |   14 
 securis/src/main/java/net/curisit/securis/db/Organization.java               |    2 
 securis/src/main/java/net/curisit/securis/services/UserResource.java         |   93 ++++----
 securis/src/main/java/net/curisit/securis/utils/CacheTTL.java                |    6 
 securis/src/main/java/net/curisit/securis/services/LicenseResource.java      |   34 +-
 securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java             |   10 
 securis/src/patch/java/net/curisit/securis/LicenseGenerator.java             |   35 ++-
 securis/src/main/java/net/curisit/securis/db/LicenseType.java                |    6 
 securis/src/main/java/net/curisit/securis/services/OrganizationResource.java |  124 +++++++-----
 securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java  |    8 
 20 files changed, 316 insertions(+), 270 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/AuthFilter.java b/securis/src/main/java/net/curisit/securis/AuthFilter.java
index 8dfb27e..d9659e3 100644
--- a/securis/src/main/java/net/curisit/securis/AuthFilter.java
+++ b/securis/src/main/java/net/curisit/securis/AuthFilter.java
@@ -23,7 +23,7 @@
 @WebFilter(urlPatterns = "/*")
 public class AuthFilter implements Filter {
 
-	private static final Logger log = LogManager.getLogger(AuthFilter.class);
+	private static final Logger LOG = LogManager.getLogger(AuthFilter.class);
 
 	@Override
 	public void init(FilterConfig fc) throws ServletException {
@@ -40,7 +40,7 @@
 				username = (String) req.getSession().getAttribute("user");
 			String role = username.equals("advance") ? "advance" : "normal";
 			// ResteasyProviderFactory.pushContext(User.class, new User(sr.getParameter("user")));
-			log.info("Role for user: {} = {}", username, role);
+			LOG.info("Role for user: {} = {}", username, role);
 			fc.doFilter(new UserRoleRequestWrapper(role, sr.getParameter("user"), req), sr1);
 		} else {
 			fc.doFilter(req, sr1);
@@ -65,7 +65,7 @@
 
 		@Override
 		public boolean isUserInRole(String role) {
-			log.info("isUserRole METHOD: {}, {}", role, this.role);
+			LOG.info("isUserRole METHOD: {}, {}", role, this.role);
 			if (this.role == null) {
 				return super.isUserInRole(role);
 			}
diff --git a/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java b/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
index 9c193a1..b7c52bd 100644
--- a/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
+++ b/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
@@ -17,12 +17,12 @@
 
 @Provider
 public class DefaultExceptionHandler implements ExceptionMapper<Exception> {
-	private static final Logger log = LogManager.getLogger(DefaultExceptionHandler.class);
+	private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class);
 
 	public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR";
 
 	public DefaultExceptionHandler() {
-		log.info("Creating DefaultExceptionHandler ");
+		LOG.info("Creating DefaultExceptionHandler ");
 	}
 
 	@Context
@@ -32,21 +32,19 @@
 
 	@Override
 	public Response toResponse(Exception e) {
-		// log.info("Creating DefaultExceptionHandler ");
-		// e.printStackTrace();
 		if (e instanceof ForbiddenException) {
-			log.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
+			LOG.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
 			return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build();
 		}
 
 		if (e instanceof SeCurisServiceException) {
-			log.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
+			LOG.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
 			return Response.status(Status.fromStatusCode(((SeCurisServiceException) e).getStatus())).header(ERROR_MESSAGE_HEADER, e.getMessage()).type(MediaType.APPLICATION_JSON).build();
 		}
 
-		log.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
-		log.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
-		log.error("Request url: " + request.getRequestURL(), e);
+		LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
+		LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
+		LOG.error("Request url: " + request.getRequestURL(), e);
 		return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build();
 	}
 }
\ No newline at end of file
diff --git a/securis/src/main/java/net/curisit/securis/MainApp.java b/securis/src/main/java/net/curisit/securis/MainApp.java
index 6839254..d642451 100644
--- a/securis/src/main/java/net/curisit/securis/MainApp.java
+++ b/securis/src/main/java/net/curisit/securis/MainApp.java
@@ -32,7 +32,7 @@
 
 public class MainApp {
 
-	static final Logger log = LogManager.getLogger(MainApp.class);
+	private static final Logger LOG = LogManager.getLogger(MainApp.class);
 
 	private static Server server;
 	private static Injector injector = null;
@@ -42,14 +42,14 @@
 	private URI uri;
 
 	public static void main(String[] args) throws Exception {
-		log.info("SeCuris init...");
+		LOG.info("SeCuris init...");
 
 		SecurisModule securisModule = new SecurisModule();
 		JpaPersistModule jpaPersistModule = new JpaPersistModule("localdb");
 		Properties props = new Properties();
 		props.put("javax.persistence.jdbc.password", securisModule.getPassword());
 		props.put("javax.persistence.jdbc.url", securisModule.getUrl(securisModule.getAppDir()));
-		log.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
+		LOG.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
 		jpaPersistModule.properties(props);
 
 		injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
@@ -91,7 +91,7 @@
 		// errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class, "/");
 		// errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class.getCanonicalName(), "/");
 		// errorHandler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/");
-		log.info("Error Handlers: " + context.getErrorHandler());
+		LOG.info("Error Handlers: " + context.getErrorHandler());
 		ContextHandlerCollection contexts = new ContextHandlerCollection();
 
 		contexts.setHandlers(new Handler[]
@@ -101,7 +101,7 @@
 		server.setHandler(context);
 		server.start();
 		server.join();
-		log.info("Started server in: http://127.0.0.1:9997/");
+		LOG.info("Started server in: http://127.0.0.1:9997/");
 	}
 
 }
diff --git a/securis/src/main/java/net/curisit/securis/RestServicesApplication.java b/securis/src/main/java/net/curisit/securis/RestServicesApplication.java
index 9ca0111..8bf986d 100644
--- a/securis/src/main/java/net/curisit/securis/RestServicesApplication.java
+++ b/securis/src/main/java/net/curisit/securis/RestServicesApplication.java
@@ -13,7 +13,7 @@
 
 public class RestServicesApplication extends Application {
 
-	private static final Logger log = LogManager.getLogger(RestServicesApplication.class);
+	private static final Logger LOG = LogManager.getLogger(RestServicesApplication.class);
 
 	@Override
 	public Set<Class<?>> getClasses() {
@@ -21,7 +21,7 @@
 		classes.add(LicenseServices.class);
 		classes.add(BasicServices.class);
 
-		log.info("Returnes classes for services: {}", classes);
+		LOG.info("Returnes classes for services: {}", classes);
 		return classes;
 	}
 
diff --git a/securis/src/main/java/net/curisit/securis/db/LicenseType.java b/securis/src/main/java/net/curisit/securis/db/LicenseType.java
index b0be062..40bf8a2 100644
--- a/securis/src/main/java/net/curisit/securis/db/LicenseType.java
+++ b/securis/src/main/java/net/curisit/securis/db/LicenseType.java
@@ -34,7 +34,7 @@
 	{ @NamedQuery(name = "list-license_types", query = "SELECT lt FROM LicenseType lt") })
 public class LicenseType implements Serializable {
 
-	private static final Logger log = LogManager.getLogger(LicenseType.class);
+	private static final Logger LOG = LogManager.getLogger(LicenseType.class);
 	private static final long serialVersionUID = 1L;
 
 	@Id
@@ -96,13 +96,13 @@
 
 	@JsonProperty("application_id")
 	public Integer getApplicationId() {
-		log.info("application  " + application);
+		LOG.info("application  " + application);
 		return application == null ? null : application.getId();
 	}
 
 	@JsonProperty("application_id")
 	public void setApplicationId(Integer appId) {
-		log.info("setApplicationId(Integer appId)  " + appId);
+		LOG.info("setApplicationId(Integer appId)  " + appId);
 		application = new Application();
 		application.setId(appId);
 	}
diff --git a/securis/src/main/java/net/curisit/securis/db/Organization.java b/securis/src/main/java/net/curisit/securis/db/Organization.java
index df31a60..2dfbdf5 100644
--- a/securis/src/main/java/net/curisit/securis/db/Organization.java
+++ b/securis/src/main/java/net/curisit/securis/db/Organization.java
@@ -42,7 +42,7 @@
 public class Organization implements Serializable {
 
 	@SuppressWarnings("unused")
-	private static final Logger log = LogManager.getLogger(Organization.class);
+	private static final Logger LOG = LogManager.getLogger(Organization.class);
 
 	private static final long serialVersionUID = 1L;
 
diff --git a/securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java b/securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
index 21ebfe3..7e60cac 100644
--- a/securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
+++ b/securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
@@ -25,7 +25,7 @@
 	private static final int DEFAULT_PORT = 9997;
 	private static final String PROPERTIES_FILE_NAME = "/server.properties";
 
-	private static final Logger log = LogManager.getLogger(SecurisModule.class);
+	private static final Logger LOG = LogManager.getLogger(SecurisModule.class);
 
 	@Override
 	protected void configure() {
@@ -52,7 +52,7 @@
 		try {
 			// String url = MessageFormat.format("http://{0}/", InetAddress.getLocalHost().getHostAddress());
 			String url = MessageFormat.format("http://{0}/", "0.0.0.0");
-			log.debug("Server url{}", url);
+			LOG.debug("Server url{}", url);
 			return UriBuilder.fromUri(url).port(getPort()).build();
 		} catch (IllegalArgumentException | UriBuilderException e) {
 			return UriBuilder.fromUri("http://localhost/").port(getPort()).build();
@@ -89,7 +89,7 @@
 		if (!ftmp.exists()) {
 			if (!ftmp.mkdirs())
 				return null;
-			log.debug("Created temporary directory for app in: {}", ftmp.getAbsolutePath());
+			LOG.debug("Created temporary directory for app in: {}", ftmp.getAbsolutePath());
 			ftmp.deleteOnExit();
 		}
 		return ftmp;
@@ -108,7 +108,7 @@
 		if (!fAppDir.exists()) {
 			if (!fAppDir.mkdirs())
 				return null;
-			log.debug("Created app working directory app in: {}", fAppDir.getAbsolutePath());
+			LOG.debug("Created app working directory app in: {}", fAppDir.getAbsolutePath());
 		}
 		return fAppDir;
 	}
@@ -149,7 +149,7 @@
 		dataSource.setURL(getUrl(appDir));
 		dataSource.setUser("curis");
 		dataSource.setPassword(getPassword());
-		log.debug("JdbcDataSource: {}", dataSource);
+		LOG.debug("JdbcDataSource: {}", dataSource);
 		return dataSource;
 	}
 
diff --git a/securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java b/securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java
index 1240819..3f5c11c 100644
--- a/securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java
+++ b/securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java
@@ -34,7 +34,7 @@
 // @PreMatching
 @Priority(Priorities.AUTHENTICATION)
 public class SecurityInterceptor implements javax.ws.rs.container.ContainerRequestFilter {
-	private static final Logger log = LogManager.getLogger(SecurityInterceptor.class);
+	private static final Logger LOG = LogManager.getLogger(SecurityInterceptor.class);
 
 	@Inject
 	private TokenHelper tokenHelper;
@@ -59,7 +59,7 @@
 			return;
 		String token = servletRequest.getHeader(TokenHelper.TOKEN_HEADER_PÀRAM);
 		if (token == null || !tokenHelper.isTokenValid(token)) {
-			log.info("Access denied to '{}', Token not valid.", servletRequest.getPathInfo());
+			LOG.info("Access denied to '{}', Token not valid.", servletRequest.getPathInfo());
 			containerRequestContext.abortWith(Response.status(Status.UNAUTHORIZED).build());
 		} else {
 			Securable sec = method.getAnnotation(Securable.class);
@@ -69,7 +69,7 @@
 			int userRoles = getUserRoles(username);
 			// if (sec.roles() != 0) {
 			// if ((sec.roles() & userRoles) == 0) {
-			// log.info("User {} has no necessary role to access url: {}", username, servletRequest.getPathInfo());
+			// LOG.info("User {} has no necessary role to access url: {}", username, servletRequest.getPathInfo());
 			// containerRequestContext.abortWith(Response.status(Status.UNAUTHORIZED).build());
 			// }
 			// }
@@ -80,7 +80,7 @@
 			containerRequestContext.setSecurityContext(scw);
 			// Next line provide injection in resource methods
 			ResteasyProviderFactory.pushContext(BasicSecurityContext.class, scw);
-			log.debug("Added custom SecurityContext for user {}, orgs: {}", username, orgs);
+			LOG.debug("Added custom SecurityContext for user {}, orgs: {}", username, orgs);
 		}
 	}
 
diff --git a/securis/src/main/java/net/curisit/securis/services/ApiResource.java b/securis/src/main/java/net/curisit/securis/services/ApiResource.java
index adc0495..cf00f3f 100644
--- a/securis/src/main/java/net/curisit/securis/services/ApiResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/ApiResource.java
@@ -23,7 +23,7 @@
 public class ApiResource {
 
 	@SuppressWarnings("unused")
-	private static final Logger log = LogManager.getLogger(ApiResource.class);
+	private static final Logger LOG = LogManager.getLogger(ApiResource.class);
 
 	@Inject
 	TokenHelper tokenHelper;
diff --git a/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java b/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
index ee9c676..1c1d860 100644
--- a/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
@@ -46,7 +46,7 @@
 	@Inject
 	Provider<EntityManager> emProvider;
 
-	private static final Logger log = LogManager.getLogger(ApplicationResource.class);
+	private static final Logger LOG = LogManager.getLogger(ApplicationResource.class);
 
 	public ApplicationResource() {
 	}
@@ -60,7 +60,7 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response index() {
-		log.info("Getting applications list ");
+		LOG.info("Getting applications list ");
 
 		EntityManager em = emProvider.get();
 		TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class);
@@ -78,16 +78,16 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response get(@PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Getting application data for id: {}: ", appid);
+		LOG.info("Getting application data for id: {}: ", appid);
 		if (appid == null || appid.equals("")) {
-			log.error("Application ID is mandatory");
+			LOG.error("Application ID is mandatory");
 			return Response.status(Status.NOT_FOUND).build();
 		}
 
 		EntityManager em = emProvider.get();
 		Application app = em.find(Application.class, Integer.parseInt(appid));
 		if (app == null) {
-			log.error("Application with id {} not found in DB", appid);
+			LOG.error("Application with id {} not found in DB", appid);
 
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
 		}
@@ -101,7 +101,7 @@
 		{ MediaType.APPLICATION_JSON })
 	@Transactional
 	public Response create(Application app, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Creating new application");
+		LOG.info("Creating new application");
 		EntityManager em = emProvider.get();
 		app.setCreationTimestamp(new Date());
 		em.persist(app);
@@ -117,11 +117,11 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response modify(Application app, @PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Modifying application with id: {}", appid);
+		LOG.info("Modifying application with id: {}", appid);
 		EntityManager em = emProvider.get();
 		Application currentapp = em.find(Application.class, Integer.parseInt(appid));
 		if (currentapp == null) {
-			log.error("Application with id {} not found in DB", appid);
+			LOG.error("Application with id {} not found in DB", appid);
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
 		}
 		currentapp.setName(app.getName());
@@ -137,11 +137,11 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response delete(@PathParam("appid") String appid, @Context HttpServletRequest request) {
-		log.info("Deleting app with id: {}", appid);
+		LOG.info("Deleting app with id: {}", appid);
 		EntityManager em = emProvider.get();
 		Application app = em.find(Application.class, Integer.parseInt(appid));
 		if (app == null) {
-			log.error("Application with id {} can not be deleted, It was not found in DB", appid);
+			LOG.error("Application with id {} can not be deleted, It was not found in DB", appid);
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
 		}
 
diff --git a/securis/src/main/java/net/curisit/securis/services/BasicServices.java b/securis/src/main/java/net/curisit/securis/services/BasicServices.java
index 9dbdd84..6e639cc 100644
--- a/securis/src/main/java/net/curisit/securis/services/BasicServices.java
+++ b/securis/src/main/java/net/curisit/securis/services/BasicServices.java
@@ -36,7 +36,7 @@
 @Singleton
 public class BasicServices {
 
-	private static final Logger log = LogManager.getLogger(BasicServices.class);
+	private static final Logger LOG = LogManager.getLogger(BasicServices.class);
 
 	@Inject
 	TokenHelper tokenHelper;
@@ -58,7 +58,7 @@
 	@Produces(
 		{ MediaType.TEXT_HTML })
 	public Response init(@PathParam("module") String module, @Context HttpServletRequest request) {
-		log.info("App index main.html");
+		LOG.info("App index main.html");
 		String page = "/main.html";
 		URI uri = UriBuilder.fromUri(page).build();
 		return Response.seeOther(uri).build();
@@ -69,9 +69,9 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response login(@FormParam("username") String user, @FormParam("password") String password, @Context HttpServletRequest request) {
-		log.info("index session: " + request.getSession());
-		log.info("user: {}, pass: {}", user, password);
-		log.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
+		LOG.info("index session: " + request.getSession());
+		LOG.info("user: {}, pass: {}", user, password);
+		LOG.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
 
 		if ("no".equals(password))
 			return Response.status(Status.UNAUTHORIZED).build();
@@ -101,11 +101,11 @@
 		if (!valid)
 			return Response.status(Status.UNAUTHORIZED).build();
 
-		// log.info("Token : " + token);
+		// LOG.info("Token : " + token);
 		String user = tokenHelper.extractUserFromToken(token);
-		// log.info("Token user: " + user);
+		// LOG.info("Token user: " + user);
 		Date date = tokenHelper.extractDateCreationFromToken(token);
-		// log.info("Token date: " + date);
+		// LOG.info("Token date: " + date);
 
 		return Response.ok(Utils.createMap("valid", true, "user", user, "date", date)).build();
 	}
@@ -119,7 +119,7 @@
 		if (token == null)
 			Response.status(Status.BAD_REQUEST).build();
 		String user = tokenHelper.extractUserFromToken(token);
-		log.info("User {} has logged out", user);
+		LOG.info("User {} has logged out", user);
 		return Response.ok().build();
 	}
 }
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 0c04736..f7f2ec5 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
@@ -47,7 +47,7 @@
 @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;
@@ -68,7 +68,7 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
-		log.info("Getting licenses list ");
+		LOG.info("Getting licenses list ");
 
 		EntityManager em = emProvider.get();
 
@@ -77,7 +77,7 @@
 			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());
+				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();
 			}
 		}
@@ -99,7 +99,7 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
-		log.info("Getting organization data for id: {}: ", licId);
+		LOG.info("Getting organization data for id: {}: ", licId);
 
 		EntityManager em = emProvider.get();
 		License lic = getCurrentLicense(licId, bsc, em);
@@ -122,11 +122,11 @@
 		License lic = getCurrentLicense(licId, bsc, em);
 
 		if (lic.getLicenseData() == null) {
-			log.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
+			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());
+			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();
@@ -146,7 +146,7 @@
 		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);
+			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");
 		}
 
@@ -193,7 +193,7 @@
 		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);
+			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");
 		}
 
@@ -214,18 +214,18 @@
 		{ MediaType.APPLICATION_JSON })
 	@Transactional
 	public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
-		log.info("Creating new license from create()");
+		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());
+				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());
+						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();
 					}
 				}
@@ -273,7 +273,7 @@
 	@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);
+		LOG.info("Modifying organization with id: {}", licId);
 
 		EntityManager em = emProvider.get();
 
@@ -296,12 +296,12 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
-		log.info("Deleting license with id: {}", licId);
+		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());
+			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();
 		}
 
@@ -311,18 +311,18 @@
 
 	private License getCurrentLicense(Integer licId, BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException {
 		if (licId == null || licId.equals("")) {
-			log.error("License ID is mandatory");
+			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);
+			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());
+				LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
 				throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
 			}
 		}
diff --git a/securis/src/main/java/net/curisit/securis/services/LicenseServices.java b/securis/src/main/java/net/curisit/securis/services/LicenseServices.java
index 4a146f9..1eab294 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseServices.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseServices.java
@@ -33,7 +33,7 @@
 public class LicenseServices {
 
 	// private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class);
-	private static final Logger log = LogManager.getLogger(LicenseServices.class);
+	private static final Logger LOG = LogManager.getLogger(LicenseServices.class);
 
 	private static final int DEFAULT_LICENSE_EXPIRATION = 365;
 	private static final String LICENSE_STRING = "CurisIntegrity Config Server v{0}.{1}";
@@ -58,8 +58,7 @@
 			String index = IOUtils.toString(this.getClass().getResourceAsStream("/static/index.html"));
 			return Response.ok().entity(index).build();
 		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+			LOG.error("Error getting index.html", e);
 		}
 		return Response.ok().entity(MessageFormat.format(LICENSE_STRING, 0, 1)).build();
 	}
@@ -69,7 +68,7 @@
 	@Produces(
 		{ MediaType.TEXT_PLAIN })
 	public Response dummy(@Context HttpServletRequest request) {
-		log.info("Request: " + request.getPathInfo());
+		LOG.info("Request: " + request.getPathInfo());
 		return Response.ok().entity((uri == null)).build();
 	}
 
@@ -82,7 +81,7 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response testFile1(@MultipartForm FileUploadForm mfdi) {
-		log.info("FORM: texto: {}, file: {}", mfdi.getTexto(), new String(mfdi.getFile()));
+		LOG.info("FORM: texto: {}, file: {}", mfdi.getTexto(), new String(mfdi.getFile()));
 		return Response.ok("OK").build();
 	}
 
@@ -92,7 +91,7 @@
 		{ MediaType.APPLICATION_JSON })
 	public ServiceResponse<ServerConfigVersions> testFile(@PathParam("license") String license, @DefaultValue("-1") @QueryParam("minorVersion") int minorVersion, @DefaultValue("-1") @QueryParam("majorVersion") int majorVersion) {
 
-		log.info("Called 'current' service with license: {}", license);
+		LOG.info("Called 'current' service with license: {}", license);
 		ServiceResponse<ServerConfigVersions> response = new ServiceResponse<ServerConfigVersions>();
 
 		return response;
diff --git a/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java b/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
index 45dedbe..9218b96 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
@@ -24,6 +24,7 @@
 
 import net.curisit.integrity.commons.Utils;
 import net.curisit.securis.DefaultExceptionHandler;
+import net.curisit.securis.SeCurisException;
 import net.curisit.securis.db.Application;
 import net.curisit.securis.db.LicenseType;
 import net.curisit.securis.utils.TokenHelper;
@@ -41,7 +42,7 @@
 @Path("/licensetype")
 public class LicenseTypeResource {
 
-	private static final Logger log = LogManager.getLogger(LicenseTypeResource.class);
+	private static final Logger LOG = LogManager.getLogger(LicenseTypeResource.class);
 
 	@Inject
 	TokenHelper tokenHelper;
@@ -61,7 +62,7 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response index() {
-		log.info("Getting license types list ");
+		LOG.info("Getting license types list ");
 
 		EntityManager em = emProvider.get();
 		TypedQuery<LicenseType> q = em.createNamedQuery("list-license_types", LicenseType.class);
@@ -79,16 +80,16 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Getting license type data for id: {}: ", ltid);
+		LOG.info("Getting license type data for id: {}: ", ltid);
 		if (ltid == null || ltid.equals("")) {
-			log.error("LicenseType ID is mandatory");
+			LOG.error("LicenseType ID is mandatory");
 			return Response.status(Status.NOT_FOUND).build();
 		}
 
 		EntityManager em = emProvider.get();
 		LicenseType lt = em.find(LicenseType.class, Integer.parseInt(ltid));
 		if (lt == null) {
-			log.error("LicenseType with id {} not found in DB", ltid);
+			LOG.error("LicenseType with id {} not found in DB", ltid);
 			return Response.status(Status.NOT_FOUND).build();
 		}
 		return Response.ok(lt).build();
@@ -101,21 +102,20 @@
 		{ MediaType.APPLICATION_JSON })
 	@Transactional
 	public Response create(LicenseType lt, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Creating new license type");
+		LOG.info("Creating new license type");
 		EntityManager em = emProvider.get();
-		Application app = null;
-		if (lt.getApplicationId() != null) {
-			app = em.find(Application.class, lt.getApplicationId());
-			if (app == null) {
-				log.error("LicenseType application with id {} not found in DB", lt.getApplicationId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type's app not found with ID: " + lt.getApplicationId()).build();
-			}
-		} else {
-			log.error("Application is missing for current license type data");
+
+		try {
+			setApplication(lt, lt.getApplicationId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
+		}
+		
+		if (lt.getApplicationId() == null) {
+			LOG.error("Application is missing for current license type data");
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application is missing for current license type data").build();
 		}
 
-		lt.setApplication(app);
 		lt.setCreationTimestamp(new Date());
 		em.persist(lt);
 
@@ -130,28 +130,39 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response modify(LicenseType lt, @PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Modifying license type with id: {}", ltid);
+		LOG.info("Modifying license type with id: {}", ltid);
 		EntityManager em = emProvider.get();
 		LicenseType currentlt = em.find(LicenseType.class, Integer.parseInt(ltid));
 		if (currentlt == null) {
-			log.error("LicenseType with id {} not found in DB", ltid);
+			LOG.error("LicenseType with id {} not found in DB", ltid);
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type not found with ID: " + ltid).build();
 		}
-		Application app = null;
-		if (lt.getApplicationId() != null) {
-			app = em.find(Application.class, lt.getApplicationId());
-			if (app == null) {
-				log.error("LicenseType application with id {} not found in DB", lt.getApplicationId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type's app not found with ID: " + lt.getApplicationId()).build();
-			}
+
+		try {
+			setApplication(currentlt, lt.getApplicationId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
+		
 		currentlt.setCode(lt.getCode());
 		currentlt.setName(lt.getName());
 		currentlt.setDescription(lt.getDescription());
-		currentlt.setApplication(app);
 		em.persist(currentlt);
 
 		return Response.ok(currentlt).build();
+	}
+
+	private void setApplication(LicenseType licType, Integer applicationId, EntityManager em) throws SeCurisException {
+		Application app = null;
+		if (applicationId != null) {
+			app = em.find(Application.class, applicationId);
+			if (app == null) {
+				LOG.error("LicenseType application with id {} not found in DB", applicationId);
+				
+				throw new SecurityException("License type's app not found with ID: " + applicationId);
+			}
+		}
+		licType.setApplication(app);		
 	}
 
 	@DELETE
@@ -160,11 +171,11 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response delete(@PathParam("ltid") String ltid, @Context HttpServletRequest request) {
-		log.info("Deleting app with id: {}", ltid);
+		LOG.info("Deleting app with id: {}", ltid);
 		EntityManager em = emProvider.get();
 		LicenseType app = em.find(LicenseType.class, Integer.parseInt(ltid));
 		if (app == null) {
-			log.error("LicenseType with id {} can not be deleted, It was not found in DB", ltid);
+			LOG.error("LicenseType with id {} can not be deleted, It was not found in DB", ltid);
 			return Response.status(Status.NOT_FOUND).build();
 		}
 
diff --git a/securis/src/main/java/net/curisit/securis/services/OrganizationResource.java b/securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
index b956327..8a51b35 100644
--- a/securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
@@ -26,6 +26,7 @@
 
 import net.curisit.integrity.commons.Utils;
 import net.curisit.securis.DefaultExceptionHandler;
+import net.curisit.securis.SeCurisException;
 import net.curisit.securis.db.Organization;
 import net.curisit.securis.db.User;
 import net.curisit.securis.security.BasicSecurityContext;
@@ -46,7 +47,7 @@
 @Path("/organization")
 public class OrganizationResource {
 
-	private static final Logger log = LogManager.getLogger(OrganizationResource.class);
+	private static final Logger LOG = LogManager.getLogger(OrganizationResource.class);
 
 	@Inject
 	private Provider<EntityManager> emProvider;
@@ -65,24 +66,24 @@
 	@Securable
 	// @RolesAllowed(SecurityContextWrapper.ROL_ADVANCE)
 	public Response index(@Context BasicSecurityContext bsc) {
-		log.info("Getting organizations list ");
+		LOG.info("Getting organizations list ");
 
-		// log.info("User orgs: {}", request.getAttribute("oser_orgs"));
+		// LOG.info("User orgs: {}", request.getAttribute("oser_orgs"));
 		BasicSecurityContext bsc2 = ResteasyProviderFactory.getContextData(BasicSecurityContext.class);
-		log.info("bsc: {}", bsc);
-		log.info("bsc2: {}", bsc2);
-		// log.info("securityContext: {}", scw);
-		log.info("securityContext ROL_ADMIN?: {}", bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN));
+		LOG.info("bsc: {}", bsc);
+		LOG.info("bsc2: {}", bsc2);
+		// LOG.info("securityContext: {}", scw);
+		LOG.info("securityContext ROL_ADMIN?: {}", bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN));
 		EntityManager em = emProvider.get();
 		TypedQuery<Organization> q;
 		if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
-			log.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
+			LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
 			q = em.createNamedQuery("list-organizations", Organization.class);
 		} else {
 			q = em.createNamedQuery("list-organizations", Organization.class);
 			// if (securityContext.getOrganizationsIds() == null)
 			// Response.ok().build();
-			// log.info("Getting only {} orgs for user: {}", securityContext.getOrganizationsIds(), securityContext.getUserPrincipal());
+			// LOG.info("Getting only {} orgs for user: {}", securityContext.getOrganizationsIds(), securityContext.getUserPrincipal());
 			// q = em.createNamedQuery("list-organizations-by-ids", Organization.class);
 			// q.setParameter("list_ids", securityContext.getOrganizationsIds());
 		}
@@ -102,20 +103,20 @@
 		{ MediaType.APPLICATION_JSON })
 	@Securable
 	public Response get(@PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Getting organization data for id: {}: ", orgid);
+		LOG.info("Getting organization data for id: {}: ", orgid);
 		if (orgid == null || orgid.equals("")) {
-			log.error("Organization ID is mandatory");
+			LOG.error("Organization ID is mandatory");
 			return Response.status(Status.NOT_FOUND).build();
 		}
 		// if (!securityContext.isOrgAccesible(Integer.parseInt(orgid))) {
-		// log.error("Organization with id {} not accessible for user: {}", orgid, securityContext.getUserPrincipal());
+		// LOG.error("Organization with id {} not accessible for user: {}", orgid, securityContext.getUserPrincipal());
 		// return Response.status(Status.UNAUTHORIZED).build();
 		// }
 
 		EntityManager em = emProvider.get();
 		Organization org = em.find(Organization.class, Integer.parseInt(orgid));
 		if (org == null) {
-			log.error("Organization with id {} not found in DB", orgid);
+			LOG.error("Organization with id {} not found in DB", orgid);
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found, id: " + orgid).build();
 		}
 		return Response.ok(org).build();
@@ -139,16 +140,15 @@
 	@Securable
 	@RolesAllowed(BasicSecurityContext.ROL_ADMIN)
 	public Response create(Organization org, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Creating new organization");
+		LOG.info("Creating new organization");
 		EntityManager em = emProvider.get();
-		Organization parentOrg = null;
-		if (org.getParentOrgId() != null) {
-			parentOrg = em.find(Organization.class, org.getParentOrgId());
-			if (parentOrg == null) {
-				log.error("Organization parent with id {} not found in DB", org.getParentOrgId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's parent not found with ID: " + org.getParentOrgId()).build();
-			}
+		
+		try {
+			this.setParentOrg(org, org.getParentOrgId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
+		
 		List<User> users = null;
 		List<String> usersIds = org.getUsersIds();
 		if (usersIds != null && usersIds.size() > 0) {
@@ -156,7 +156,7 @@
 			for (String username : usersIds) {
 				User user = em.find(User.class, username);
 				if (user == null) {
-					log.error("Organization user with id {} not found in DB", username);
+					LOG.error("Organization user with id {} not found in DB", username);
 					return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build();
 				}
 				users.add(user);
@@ -164,11 +164,40 @@
 		}
 
 		org.setUsers(users);
-		org.setParentOrganization(parentOrg);
 		org.setCreationTimestamp(new Date());
 		em.persist(org);
 
 		return Response.ok(org).build();
+	}
+	
+	private void setParentOrg(Organization org, Integer parentOrgId, EntityManager em) throws SeCurisException {
+		Organization parentOrg = null;
+		if (parentOrgId != null) {
+			parentOrg = em.find(Organization.class, parentOrgId);
+			if (parentOrg == null) {
+				LOG.error("Organization parent with id {} not found in DB", org.getParentOrgId());
+				throw new SecurityException("Organization's parent not found with ID: " + org.getParentOrgId());
+			}
+		}
+
+		org.setParentOrganization(parentOrg);
+	}
+
+	private void setOrgUsers(Organization org, List<String> usersIds, EntityManager em) throws SeCurisException {
+		List<User> users = null;
+		if (usersIds != null && usersIds.size() > 0) {
+			users = new ArrayList<>();
+			for (String username : usersIds) {
+				User user = em.find(User.class, username);
+				if (user == null) {
+					LOG.error("Organization user with id '{}' not found in DB", username);
+					throw new SecurityException("Organization's user not found with ID: " + username);
+				}
+				users.add(user);
+			}
+		}
+
+		org.setUsers(users);
 	}
 
 	@PUT
@@ -181,42 +210,31 @@
 	@Securable
 	@RolesAllowed(BasicSecurityContext.ROL_ADMIN)
 	public Response modify(Organization org, @PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Modifying organization with id: {}", orgid);
+		LOG.info("Modifying organization with id: {}", orgid);
 		EntityManager em = emProvider.get();
 		Organization currentOrg = em.find(Organization.class, Integer.parseInt(orgid));
 		if (currentOrg == null) {
-			log.error("Organization with id {} not found in DB", orgid);
+			LOG.error("Organization with id {} not found in DB", orgid);
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found with ID: " + orgid).build();
 		}
-		Organization parentOrg = null;
-		if (org.getParentOrgId() != null) {
-			parentOrg = em.find(Organization.class, org.getParentOrgId());
-			if (parentOrg == null) {
-				log.error("Organization parent with id {} not found in DB", org.getParentOrgId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's parent not found with ID: " + org.getParentOrgId()).build();
-			}
-			if (isCyclicalRelationship(currentOrg.getId(), parentOrg)) {
-				log.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId());
-				return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Cyclical relationships are not allowed, please change the parent organization, current Parent: " + parentOrg.getName()).build();
+		try {
+			this.setParentOrg(currentOrg, org.getParentOrgId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
+		}
+		if (org.getParentOrganization() != null) {
+			if (isCyclicalRelationship(currentOrg.getId(), org.getParentOrganization())) {
+				LOG.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId());
+				return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Cyclical relationships are not allowed, please change the parent organization, current Parent: " + org.getParentOrganization().getName()).build();
 			}
 		}
-
-		List<User> users = null;
-		List<String> usersIds = org.getUsersIds();
-		if (usersIds != null && usersIds.size() > 0) {
-			users = new ArrayList<>();
-			for (String username : usersIds) {
-				User user = em.find(User.class, username);
-				if (user == null) {
-					log.error("Organization user with id '{}' not found in DB", username);
-					return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build();
-				}
-				users.add(user);
-			}
+		
+		try {
+			setOrgUsers(currentOrg, org.getUsersIds(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
 
-		currentOrg.setUsers(users);
-		currentOrg.setParentOrganization(parentOrg);
 		currentOrg.setCode(org.getCode());
 		currentOrg.setName(org.getName());
 		currentOrg.setDescription(org.getDescription());
@@ -233,15 +251,15 @@
 	@Securable
 	@RolesAllowed(BasicSecurityContext.ROL_ADMIN)
 	public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) {
-		log.info("Deleting organization with id: {}", orgid);
+		LOG.info("Deleting organization with id: {}", orgid);
 		EntityManager em = emProvider.get();
 		Organization org = em.find(Organization.class, Integer.parseInt(orgid));
 		if (org == null) {
-			log.error("Organization with id {} can not be deleted, It was not found in DB", orgid);
+			LOG.error("Organization with id {} can not be deleted, It was not found in DB", orgid);
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization was not found, ID: " + orgid).build();
 		}
 		if (org.getChildOrganizations() != null && org.getChildOrganizations().size() > 0) {
-			log.error("Organization has children and can not be deleted, ID: " + orgid);
+			LOG.error("Organization has children and can not be deleted, ID: " + orgid);
 			return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization has children and can not be deleted, ID: " + orgid).build();
 		}
 
diff --git a/securis/src/main/java/net/curisit/securis/services/PackResource.java b/securis/src/main/java/net/curisit/securis/services/PackResource.java
index 82c2dd8..03978de 100644
--- a/securis/src/main/java/net/curisit/securis/services/PackResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/PackResource.java
@@ -5,6 +5,7 @@
 import java.util.List;
 
 import javax.annotation.security.RolesAllowed;
+import javax.crypto.SealedObject;
 import javax.inject.Inject;
 import javax.inject.Provider;
 import javax.persistence.EntityManager;
@@ -24,6 +25,7 @@
 
 import net.curisit.integrity.commons.Utils;
 import net.curisit.securis.DefaultExceptionHandler;
+import net.curisit.securis.SeCurisException;
 import net.curisit.securis.db.LicenseType;
 import net.curisit.securis.db.Organization;
 import net.curisit.securis.db.Pack;
@@ -45,7 +47,7 @@
 @Path("/pack")
 public class PackResource {
 
-	private static final Logger log = LogManager.getLogger(PackResource.class);
+	private static final Logger LOG = LogManager.getLogger(PackResource.class);
 
 	@Inject
 	TokenHelper tokenHelper;
@@ -66,14 +68,14 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response index(@Context BasicSecurityContext bsc) {
-		log.info("Getting packs list ");
+		LOG.info("Getting packs list ");
 
 		EntityManager em = emProvider.get();
 		// TypedQuery<Pack> q = em.createNamedQuery("list-packs-by-orgs", Pack.class);
 
 		TypedQuery<Pack> q;
 		if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
-			log.info("Getting all packs for user: " + bsc.getUserPrincipal());
+			LOG.info("Getting all packs for user: " + bsc.getUserPrincipal());
 			q = em.createNamedQuery("list-packs", Pack.class);
 		} else {
 			q = em.createNamedQuery("list-packs-by-orgs", Pack.class);
@@ -88,7 +90,7 @@
 	}
 
 	private Response generateErrorUnathorizedAccess(Pack pack, Principal user) {
-		log.error("Pack with id {} not accesible by user {}", pack, user);
+		LOG.error("Pack with id {} not accesible by user {}", pack, user);
 		return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack").build();
 	}
 
@@ -102,16 +104,16 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response get(@PathParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
-		log.info("Getting pack data for id: {}: ", packId);
+		LOG.info("Getting pack data for id: {}: ", packId);
 		if (packId == null || packId.equals("")) {
-			log.error("Pack ID is mandatory");
+			LOG.error("Pack ID is mandatory");
 			return Response.status(Status.NOT_FOUND).build();
 		}
 
 		EntityManager em = emProvider.get();
 		Pack pack = em.find(Pack.class, packId);
 		if (pack == null) {
-			log.error("Pack with id {} not found in DB", packId);
+			LOG.error("Pack with id {} not found in DB", packId);
 			return Response.status(Status.NOT_FOUND).build();
 		}
 		if (bsc.isUserInRole(BasicSecurityContext.ROL_ADVANCE)) {
@@ -131,35 +133,41 @@
 		{ MediaType.APPLICATION_JSON })
 	@Transactional
 	public Response create(Pack pack, @Context BasicSecurityContext bsc) {
-		log.info("Creating new pack");
+		LOG.info("Creating new pack");
 		EntityManager em = emProvider.get();
 
-		Organization org = null;
-		if (pack.getOrgId() != null) {
-			org = em.find(Organization.class, pack.getOrgId());
-			if (org == null) {
-				log.error("Organization pack with id {} not found in DB", pack.getOrgId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack organization not found with ID: " + pack.getOrgId()).build();
-			}
+		try {
+			setPackOrganization(pack, pack.getOrgId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
-		LicenseType lt = null;
-		if (pack.getLicTypeId() != null) {
-			lt = em.find(LicenseType.class, pack.getLicTypeId());
-			if (lt == null) {
-				log.error("Pack license type with id {} not found in DB", pack.getLicTypeId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
-			}
+
+		try {
+			setPackLicenseType(pack, pack.getLicTypeId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
 
 		User user = em.find(User.class, bsc.getUserPrincipal().getName());
 
 		pack.setCreatedBy(user);
-		pack.setLicenseType(lt);
-		pack.setOrganization(org);
 		pack.setCreationTimestamp(new Date());
 		em.persist(pack);
 
 		return Response.ok(pack).build();
+	}
+	
+	private void setPackLicenseType(Pack pack, Integer licTypeId, EntityManager em) throws SeCurisException {
+		LicenseType lt = null;
+		if (licTypeId != null) {
+			lt = em.find(LicenseType.class, pack.getLicTypeId());
+			if (lt == null) {
+				LOG.error("Pack license type with id {} not found in DB", licTypeId);
+				throw new SeCurisException("Pack license type not found with ID: " + licTypeId);
+//				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
+			}
+		}
+		pack.setLicenseType(lt);
 	}
 
 	@PUT
@@ -172,29 +180,23 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response modify(Pack pack, @PathParam("packId") Integer packId) {
-		log.info("Modifying pack with id: {}", packId);
+		LOG.info("Modifying pack with id: {}", packId);
 		EntityManager em = emProvider.get();
 		Pack currentPack = em.find(Pack.class, packId);
 
-		Organization org = null;
-		if (pack.getOrgId() != null) {
-			org = em.find(Organization.class, pack.getOrgId());
-			if (org == null) {
-				log.error("Organization pack with id {} not found in DB", pack.getOrgId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack organization not found with ID: " + pack.getOrgId()).build();
-			}
+		try {
+			setPackOrganization(currentPack, pack.getOrgId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
-		LicenseType lt = null;
-		if (pack.getLicTypeId() != null) {
-			lt = em.find(LicenseType.class, pack.getLicTypeId());
-			if (lt == null) {
-				log.error("Pack license type with id {} not found in DB", pack.getLicTypeId());
-				return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
-			}
+
+		try {
+			setPackLicenseType(currentPack, pack.getLicTypeId(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
+		
 		currentPack.setLicensePreactivation(pack.isLicensePreactivation());
-		currentPack.setLicenseType(lt);
-		currentPack.setOrganization(org);
 		currentPack.setCode(pack.getCode());
 		currentPack.setComments(pack.getComments());
 		currentPack.setNumLicenses(pack.getNumLicenses());
@@ -202,6 +204,18 @@
 		em.persist(currentPack);
 
 		return Response.ok(pack).build();
+	}
+
+	private void setPackOrganization(Pack currentPack, Integer orgId, EntityManager em) throws SeCurisException {
+		Organization org = null;
+		if (orgId != null) {
+			org = em.find(Organization.class, orgId);
+			if (org == null) {
+				LOG.error("Organization pack with id {} not found in DB", orgId);
+				throw new SeCurisException("Pack organization not found with ID: " + orgId);
+			}
+		}
+		currentPack.setOrganization(org);
 	}
 
 	@DELETE
@@ -212,11 +226,11 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response delete(@PathParam("packId") String packId) {
-		log.info("Deleting pack with id: {}", packId);
+		LOG.info("Deleting pack with id: {}", packId);
 		EntityManager em = emProvider.get();
 		Pack org = em.find(Pack.class, Integer.parseInt(packId));
 		if (org == null) {
-			log.error("Pack with id {} can not be deleted, It was not found in DB", packId);
+			LOG.error("Pack with id {} can not be deleted, It was not found in DB", packId);
 			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack was not found, ID: " + packId).build();
 		}
 
diff --git a/securis/src/main/java/net/curisit/securis/services/UserResource.java b/securis/src/main/java/net/curisit/securis/services/UserResource.java
index f533283..514003b 100644
--- a/securis/src/main/java/net/curisit/securis/services/UserResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/UserResource.java
@@ -28,6 +28,7 @@
 
 import net.curisit.integrity.commons.Utils;
 import net.curisit.securis.DefaultExceptionHandler;
+import net.curisit.securis.SeCurisException;
 import net.curisit.securis.db.Organization;
 import net.curisit.securis.db.User;
 import net.curisit.securis.utils.TokenHelper;
@@ -52,7 +53,7 @@
 	Provider<EntityManager> emProvider;
 
 	// private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class);
-	private static final Logger log = LogManager.getLogger(UserResource.class);
+	private static final Logger LOG = LogManager.getLogger(UserResource.class);
 
 	public UserResource() {
 	}
@@ -66,7 +67,7 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response index() {
-		log.info("Getting users list ");
+		LOG.info("Getting users list ");
 
 		EntityManager em = emProvider.get();
 		TypedQuery<User> q = em.createNamedQuery("list-users", User.class);
@@ -85,16 +86,16 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response get(@PathParam("uid") String uid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Getting user data for id: {}: ", uid);
+		LOG.info("Getting user data for id: {}: ", uid);
 		if (uid == null || uid.equals("")) {
-			log.error("User ID is mandatory");
+			LOG.error("User ID is mandatory");
 			return Response.status(Status.NOT_FOUND).build();
 		}
 
 		EntityManager em = emProvider.get();
 		User lt = em.find(User.class, uid);
 		if (lt == null) {
-			log.error("User with id {} not found in DB", uid);
+			LOG.error("User with id {} not found in DB", uid);
 			return Response.status(Status.NOT_FOUND).build();
 		}
 		return Response.ok(lt).build();
@@ -107,35 +108,43 @@
 		{ MediaType.APPLICATION_JSON })
 	@Transactional
 	public Response create(User user, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Creating new user");
+		LOG.info("Creating new user");
 		EntityManager em = emProvider.get();
 		User currentUser = em.find(User.class, user.getUsername());
 		if (currentUser != null) {
-			log.info("User with id {} was found in DB, we'll try to modify it", user.getUsername());
+			LOG.info("User with id {} was found in DB, we'll try to modify it", user.getUsername());
 			return modify(user, user.getUsername(), token);
 		}
-
-		Set<Organization> orgs = null;
-		Set<Integer> orgsIds = user.getOrgsIds();
-		if (orgsIds != null && orgsIds.size() > 0) {
-			orgs = new HashSet<>();
-			for (Integer orgId : orgsIds) {
-				Organization o = em.find(Organization.class, orgId);
-				if (o == null) {
-					log.error("User organization with id {} not found in DB", orgId);
-					return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User's organization not found with ID: " + orgId).build();
-				}
-				orgs.add(o);
-			}
+		
+		try {
+			this.setUserOrg(user, user.getOrgsIds(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
-
-		user.setOrganizations(orgs);
 		user.setModificationTimestamp(new Date());
 		user.setLastLogin(null);
 		user.setCreationTimestamp(new Date());
 		em.persist(user);
 
 		return Response.ok(user).build();
+	}
+	
+	private void setUserOrg(User user, Set<Integer> orgsIds, EntityManager em) throws SeCurisException {
+		Set<Organization> orgs = null;
+		if (orgsIds != null && orgsIds.size() > 0) {
+			orgs = new HashSet<>();
+			for (Integer orgId : orgsIds) {
+				Organization o = em.find(Organization.class, orgId);
+				if (o == null) {
+					LOG.error("User organization with id {} not found in DB", orgId);
+					throw new SeCurisException("User's organization not found with ID: " + orgId);
+				}
+				orgs.add(o);
+			}
+		}
+
+		user.setOrganizations(orgs);
+
 	}
 
 	@PUT
@@ -146,29 +155,19 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response modify(User user, @PathParam("uid") String uid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		log.info("Modifying user with id: {}", uid);
+		LOG.info("Modifying user with id: {}", uid);
 		EntityManager em = emProvider.get();
 		User currentUser = em.find(User.class, uid);
 		if (currentUser == null) {
-			log.info("User with id {} not found in DB, we'll try to create it", uid);
+			LOG.info("User with id {} not found in DB, we'll try to create it", uid);
 			return create(user, token);
 		}
 
-		Set<Organization> orgs = null;
-		Set<Integer> orgsIds = user.getOrgsIds();
-		if (orgsIds != null && orgsIds.size() > 0) {
-			orgs = new HashSet<>();
-			for (Integer orgId : orgsIds) {
-				Organization o = em.find(Organization.class, orgId);
-				if (o == null) {
-					log.error("User organization with id {} not found in DB", orgId);
-					return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User's user not found with ID: " + orgId).build();
-				}
-				orgs.add(o);
-			}
+		try {
+			this.setUserOrg(currentUser, user.getOrgsIds(), em);
+		} catch (SeCurisException e) {
+			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
 		}
-
-		currentUser.setOrganizations(orgs);
 		currentUser.setFirstName(user.getFirstName());
 		currentUser.setLastName(user.getLastName());
 		currentUser.setRoles(user.getRoles());
@@ -188,11 +187,11 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response delete(@PathParam("uid") String uid, @Context HttpServletRequest request) {
-		log.info("Deleting app with id: {}", uid);
+		LOG.info("Deleting app with id: {}", uid);
 		EntityManager em = emProvider.get();
 		User app = em.find(User.class, uid);
 		if (app == null) {
-			log.error("User with id {} can not be deleted, It was not found in DB", uid);
+			LOG.error("User with id {} can not be deleted, It was not found in DB", uid);
 			return Response.status(Status.NOT_FOUND).build();
 		}
 
@@ -205,9 +204,9 @@
 	@Produces(
 		{ MediaType.APPLICATION_JSON })
 	public Response login(@FormParam("username") String user, @FormParam("password") String password, @Context HttpServletRequest request) {
-		log.info("index session: " + request.getSession());
-		log.info("user: {}, pass: {}", user, password);
-		log.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
+		LOG.info("index session: " + request.getSession());
+		LOG.info("user: {}, pass: {}", user, password);
+		LOG.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
 
 		if ("no".equals(password))
 			return Response.status(Status.UNAUTHORIZED).build();
@@ -233,14 +232,14 @@
 		if (token == null)
 			return Response.status(Status.FORBIDDEN).build();
 
-		log.info("Token : " + token);
+		LOG.info("Token : " + token);
 		String user = tokenHelper.extractUserFromToken(token);
-		log.info("Token user: " + user);
+		LOG.info("Token user: " + user);
 		Date date = tokenHelper.extractDateCreationFromToken(token);
-		log.info("Token date: " + date);
+		LOG.info("Token date: " + date);
 		boolean valid = tokenHelper.isTokenValid(token);
 
-		log.info("Is Token valid: " + valid);
+		LOG.info("Is Token valid: " + valid);
 
 		return Response.ok(Utils.createMap("valid", true, "user", user, "date", date, "token", token)).build();
 	}
diff --git a/securis/src/main/java/net/curisit/securis/utils/CacheTTL.java b/securis/src/main/java/net/curisit/securis/utils/CacheTTL.java
index 9f7ea3d..01b5c9b 100644
--- a/securis/src/main/java/net/curisit/securis/utils/CacheTTL.java
+++ b/securis/src/main/java/net/curisit/securis/utils/CacheTTL.java
@@ -20,7 +20,7 @@
 @Singleton
 public class CacheTTL {
 
-	private static final Logger log = LogManager.getLogger(CacheTTL.class);
+	private static final Logger LOG = LogManager.getLogger(CacheTTL.class);
 
 	/**
 	 * Period before token expires, set in seconds.
@@ -42,11 +42,11 @@
 						// We check for expired object every 60 seconds
 						Thread.sleep(60 * 1000);
 					} catch (InterruptedException e) {
-						log.error("Exiting from Cache Thread");
+						LOG.error("Exiting from Cache Thread");
 						data.clear();
 						return;
 					}
-					// log.info("Cheking expired objects " + new Date());
+					// LOG.info("Cheking expired objects " + new Date());
 					Date now = new Date();
 					List<String> keysToRemove = new ArrayList<>();
 					for (String key : CacheTTL.this.data.keySet()) {
diff --git a/securis/src/main/java/net/curisit/securis/utils/TokenHelper.java b/securis/src/main/java/net/curisit/securis/utils/TokenHelper.java
index ec477a8..9b3d041 100644
--- a/securis/src/main/java/net/curisit/securis/utils/TokenHelper.java
+++ b/securis/src/main/java/net/curisit/securis/utils/TokenHelper.java
@@ -20,7 +20,7 @@
 @Singleton
 public class TokenHelper {
 
-	private static final Logger log = LogManager.getLogger(TokenHelper.class);
+	private static final Logger LOG = LogManager.getLogger(TokenHelper.class);
 
 	/**
 	 * Period before token expires, set in hours.
@@ -52,9 +52,9 @@
 			sb.append(Utils.toIsoFormat(date));
 			return Base64.encodeBytes(sb.toString().getBytes("utf-8"));
 		} catch (NoSuchAlgorithmException e) {
-			log.error("Error generating SHA-256 hash", e);
+			LOG.error("Error generating SHA-256 hash", e);
 		} catch (UnsupportedEncodingException e) {
-			log.error("Error generating SHA-256 hash", e);
+			LOG.error("Error generating SHA-256 hash", e);
 		}
 		return null;
 
@@ -92,9 +92,9 @@
 			String newSecret = generateSecret(user, date);
 			return newSecret.equals(secret);
 		} catch (IOException e) {
-			log.error("Error decoding Base64 token", e);
+			LOG.error("Error decoding Base64 token", e);
 		} catch (NoSuchAlgorithmException e) {
-			log.error("Error generation secret to compare with", e);
+			LOG.error("Error generation secret to compare with", e);
 		}
 		return false;
 	}
@@ -110,7 +110,7 @@
 			String user = parts[1];
 			return user;
 		} catch (IOException e) {
-			log.error("Error decoding Base64 token", e);
+			LOG.error("Error decoding Base64 token", e);
 		}
 		return null;
 	}
@@ -124,7 +124,7 @@
 			Date date = Utils.toDateFromIso(parts[2]);
 			return date;
 		} catch (IOException e) {
-			log.error("Error decoding Base64 token", e);
+			LOG.error("Error decoding Base64 token", e);
 		}
 		return null;
 	}
diff --git a/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java b/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java
index d57a8ca..a9d3414 100644
--- a/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java
+++ b/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java
@@ -33,7 +33,7 @@
  */
 public class LicenseGenerator {
 
-	private static final Logger log = LogManager.getLogger(LicenseGenerator.class);
+	private static final Logger LOG = LogManager.getLogger(LicenseGenerator.class);
 
 	private static LicenseGenerator singleton = new LicenseGenerator();
 
@@ -58,7 +58,7 @@
 	 * @throws SeCurisException
 	 */
 	public LicenseBean generateLicense(RequestBean req, Map<String, Object> metadata, Date expirationDate, String licenseType, String licenseCode) throws SeCurisException {
-		log.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), req.getAppCode()));
+		LOG.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), req.getAppCode()));
 		LicenseBean license = new LicenseBean(req);
 		license.setLicenseType(licenseType);
 		license.setLicenseCode(licenseCode);
@@ -83,14 +83,14 @@
 			json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8");
 			Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
 		} catch (UnsupportedEncodingException e) {
-			log.error("Error creating json doc from license: " + license, e);
+			LOG.error("Error creating json doc from license: " + license, e);
 			throw new SeCurisException("Error creating json doc from license: " + license, e);
 		} catch (IOException e) {
-			log.error("Error creating license file: " + file, e);
+			LOG.error("Error creating license file: " + file, e);
 			throw new SeCurisException("Error creating json doc from license: " + license, e);
 		}
 
-		log.info("License saved in {}", file);
+		LOG.info("License saved in {}", file);
 
 	}
 
@@ -119,15 +119,15 @@
 			licBean.setSignature(Base64.encodeBase64String(signatureData));
 			return licBean.getSignature();
 		} catch (NoSuchAlgorithmException e) {
-			log.error("Error signing license for " + licBean, e);
+			LOG.error("Error signing license for " + licBean, e);
 		} catch (InvalidKeyException e) {
-			log.error("Error signing license for " + licBean, e);
+			LOG.error("Error signing license for " + licBean, e);
 		} catch (InvalidKeySpecException e) {
-			log.error("Error signing license for " + licBean, e);
+			LOG.error("Error signing license for " + licBean, e);
 		} catch (IOException e) {
-			log.error("Error signing license for " + licBean, e);
+			LOG.error("Error signing license for " + licBean, e);
 		} catch (SignatureException e) {
-			log.error("Error signing license for " + licBean, e);
+			LOG.error("Error signing license for " + licBean, e);
 		}
 		throw new SeCurisException("License could not be generated");
 	}
@@ -136,11 +136,18 @@
 
 		RequestBean req = ReqGenerator.getInstance().loadRequest(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req"));
 		Map<String, Object> metadata = new TreeMap<>();
-		metadata.put("maxUsers", 20);
-		metadata.put("maxSessionUsers", 2);
+//		CurisData parameters:
+//		metadata.put("maxUsers", 5);
+//		metadata.put("maxSessionUsers", 100);
+		// curisIntegrity
+		metadata.put("maxUsers", 0);
+		metadata.put("maxInstances", 0);
+		metadata.put("timeThreshold", 0);
+		metadata.put("datasetPrefix", "BP");
+		metadata.put("extendedMode", true);
 		Date expirationDate = new Date(new Date().getTime() + (1000L * 3600 * 24 * 365 * 10));
-		LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CD-01", "LIC-CURISTEC-0001");
-		LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/YanFei.lic"));
+		LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CI-01", "LIC-CURISTEC-0001");
+		LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/AxelLicCI.lic"));
 
 		System.out.print("License expires at: " + expirationDate.getTime());
  

--
Gitblit v1.3.2