Roberto Sánchez
2014-09-18 52ce72b22ef8d92a1f35b4993bcddaaa66d67350
#396 fix - Fixed some SonarQube issues
20 files modified
changed files
securis/src/main/java/net/curisit/securis/AuthFilter.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/MainApp.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/RestServicesApplication.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/LicenseType.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Organization.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApiResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/BasicServices.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseServices.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/PackResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/UserResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/utils/CacheTTL.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/utils/TokenHelper.java patch | view | blame | history
securis/src/patch/java/net/curisit/securis/LicenseGenerator.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/AuthFilter.java
....@@ -23,7 +23,7 @@
2323 @WebFilter(urlPatterns = "/*")
2424 public class AuthFilter implements Filter {
2525
26
- private static final Logger log = LogManager.getLogger(AuthFilter.class);
26
+ private static final Logger LOG = LogManager.getLogger(AuthFilter.class);
2727
2828 @Override
2929 public void init(FilterConfig fc) throws ServletException {
....@@ -40,7 +40,7 @@
4040 username = (String) req.getSession().getAttribute("user");
4141 String role = username.equals("advance") ? "advance" : "normal";
4242 // ResteasyProviderFactory.pushContext(User.class, new User(sr.getParameter("user")));
43
- log.info("Role for user: {} = {}", username, role);
43
+ LOG.info("Role for user: {} = {}", username, role);
4444 fc.doFilter(new UserRoleRequestWrapper(role, sr.getParameter("user"), req), sr1);
4545 } else {
4646 fc.doFilter(req, sr1);
....@@ -65,7 +65,7 @@
6565
6666 @Override
6767 public boolean isUserInRole(String role) {
68
- log.info("isUserRole METHOD: {}, {}", role, this.role);
68
+ LOG.info("isUserRole METHOD: {}, {}", role, this.role);
6969 if (this.role == null) {
7070 return super.isUserInRole(role);
7171 }
securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
....@@ -17,12 +17,12 @@
1717
1818 @Provider
1919 public class DefaultExceptionHandler implements ExceptionMapper<Exception> {
20
- private static final Logger log = LogManager.getLogger(DefaultExceptionHandler.class);
20
+ private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class);
2121
2222 public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR";
2323
2424 public DefaultExceptionHandler() {
25
- log.info("Creating DefaultExceptionHandler ");
25
+ LOG.info("Creating DefaultExceptionHandler ");
2626 }
2727
2828 @Context
....@@ -32,21 +32,19 @@
3232
3333 @Override
3434 public Response toResponse(Exception e) {
35
- // log.info("Creating DefaultExceptionHandler ");
36
- // e.printStackTrace();
3735 if (e instanceof ForbiddenException) {
38
- log.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
36
+ LOG.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
3937 return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build();
4038 }
4139
4240 if (e instanceof SeCurisServiceException) {
43
- log.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
41
+ LOG.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
4442 return Response.status(Status.fromStatusCode(((SeCurisServiceException) e).getStatus())).header(ERROR_MESSAGE_HEADER, e.getMessage()).type(MediaType.APPLICATION_JSON).build();
4543 }
4644
47
- log.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
48
- log.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
49
- log.error("Request url: " + request.getRequestURL(), e);
45
+ LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
46
+ LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
47
+ LOG.error("Request url: " + request.getRequestURL(), e);
5048 return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build();
5149 }
5250 }
securis/src/main/java/net/curisit/securis/MainApp.java
....@@ -32,7 +32,7 @@
3232
3333 public class MainApp {
3434
35
- static final Logger log = LogManager.getLogger(MainApp.class);
35
+ private static final Logger LOG = LogManager.getLogger(MainApp.class);
3636
3737 private static Server server;
3838 private static Injector injector = null;
....@@ -42,14 +42,14 @@
4242 private URI uri;
4343
4444 public static void main(String[] args) throws Exception {
45
- log.info("SeCuris init...");
45
+ LOG.info("SeCuris init...");
4646
4747 SecurisModule securisModule = new SecurisModule();
4848 JpaPersistModule jpaPersistModule = new JpaPersistModule("localdb");
4949 Properties props = new Properties();
5050 props.put("javax.persistence.jdbc.password", securisModule.getPassword());
5151 props.put("javax.persistence.jdbc.url", securisModule.getUrl(securisModule.getAppDir()));
52
- log.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
52
+ LOG.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
5353 jpaPersistModule.properties(props);
5454
5555 injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
....@@ -91,7 +91,7 @@
9191 // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class, "/");
9292 // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class.getCanonicalName(), "/");
9393 // errorHandler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/");
94
- log.info("Error Handlers: " + context.getErrorHandler());
94
+ LOG.info("Error Handlers: " + context.getErrorHandler());
9595 ContextHandlerCollection contexts = new ContextHandlerCollection();
9696
9797 contexts.setHandlers(new Handler[]
....@@ -101,7 +101,7 @@
101101 server.setHandler(context);
102102 server.start();
103103 server.join();
104
- log.info("Started server in: http://127.0.0.1:9997/");
104
+ LOG.info("Started server in: http://127.0.0.1:9997/");
105105 }
106106
107107 }
securis/src/main/java/net/curisit/securis/RestServicesApplication.java
....@@ -13,7 +13,7 @@
1313
1414 public class RestServicesApplication extends Application {
1515
16
- private static final Logger log = LogManager.getLogger(RestServicesApplication.class);
16
+ private static final Logger LOG = LogManager.getLogger(RestServicesApplication.class);
1717
1818 @Override
1919 public Set<Class<?>> getClasses() {
....@@ -21,7 +21,7 @@
2121 classes.add(LicenseServices.class);
2222 classes.add(BasicServices.class);
2323
24
- log.info("Returnes classes for services: {}", classes);
24
+ LOG.info("Returnes classes for services: {}", classes);
2525 return classes;
2626 }
2727
securis/src/main/java/net/curisit/securis/db/LicenseType.java
....@@ -34,7 +34,7 @@
3434 { @NamedQuery(name = "list-license_types", query = "SELECT lt FROM LicenseType lt") })
3535 public class LicenseType implements Serializable {
3636
37
- private static final Logger log = LogManager.getLogger(LicenseType.class);
37
+ private static final Logger LOG = LogManager.getLogger(LicenseType.class);
3838 private static final long serialVersionUID = 1L;
3939
4040 @Id
....@@ -96,13 +96,13 @@
9696
9797 @JsonProperty("application_id")
9898 public Integer getApplicationId() {
99
- log.info("application " + application);
99
+ LOG.info("application " + application);
100100 return application == null ? null : application.getId();
101101 }
102102
103103 @JsonProperty("application_id")
104104 public void setApplicationId(Integer appId) {
105
- log.info("setApplicationId(Integer appId) " + appId);
105
+ LOG.info("setApplicationId(Integer appId) " + appId);
106106 application = new Application();
107107 application.setId(appId);
108108 }
securis/src/main/java/net/curisit/securis/db/Organization.java
....@@ -42,7 +42,7 @@
4242 public class Organization implements Serializable {
4343
4444 @SuppressWarnings("unused")
45
- private static final Logger log = LogManager.getLogger(Organization.class);
45
+ private static final Logger LOG = LogManager.getLogger(Organization.class);
4646
4747 private static final long serialVersionUID = 1L;
4848
securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
....@@ -25,7 +25,7 @@
2525 private static final int DEFAULT_PORT = 9997;
2626 private static final String PROPERTIES_FILE_NAME = "/server.properties";
2727
28
- private static final Logger log = LogManager.getLogger(SecurisModule.class);
28
+ private static final Logger LOG = LogManager.getLogger(SecurisModule.class);
2929
3030 @Override
3131 protected void configure() {
....@@ -52,7 +52,7 @@
5252 try {
5353 // String url = MessageFormat.format("http://{0}/", InetAddress.getLocalHost().getHostAddress());
5454 String url = MessageFormat.format("http://{0}/", "0.0.0.0");
55
- log.debug("Server url{}", url);
55
+ LOG.debug("Server url{}", url);
5656 return UriBuilder.fromUri(url).port(getPort()).build();
5757 } catch (IllegalArgumentException | UriBuilderException e) {
5858 return UriBuilder.fromUri("http://localhost/").port(getPort()).build();
....@@ -89,7 +89,7 @@
8989 if (!ftmp.exists()) {
9090 if (!ftmp.mkdirs())
9191 return null;
92
- log.debug("Created temporary directory for app in: {}", ftmp.getAbsolutePath());
92
+ LOG.debug("Created temporary directory for app in: {}", ftmp.getAbsolutePath());
9393 ftmp.deleteOnExit();
9494 }
9595 return ftmp;
....@@ -108,7 +108,7 @@
108108 if (!fAppDir.exists()) {
109109 if (!fAppDir.mkdirs())
110110 return null;
111
- log.debug("Created app working directory app in: {}", fAppDir.getAbsolutePath());
111
+ LOG.debug("Created app working directory app in: {}", fAppDir.getAbsolutePath());
112112 }
113113 return fAppDir;
114114 }
....@@ -149,7 +149,7 @@
149149 dataSource.setURL(getUrl(appDir));
150150 dataSource.setUser("curis");
151151 dataSource.setPassword(getPassword());
152
- log.debug("JdbcDataSource: {}", dataSource);
152
+ LOG.debug("JdbcDataSource: {}", dataSource);
153153 return dataSource;
154154 }
155155
securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java
....@@ -34,7 +34,7 @@
3434 // @PreMatching
3535 @Priority(Priorities.AUTHENTICATION)
3636 public class SecurityInterceptor implements javax.ws.rs.container.ContainerRequestFilter {
37
- private static final Logger log = LogManager.getLogger(SecurityInterceptor.class);
37
+ private static final Logger LOG = LogManager.getLogger(SecurityInterceptor.class);
3838
3939 @Inject
4040 private TokenHelper tokenHelper;
....@@ -59,7 +59,7 @@
5959 return;
6060 String token = servletRequest.getHeader(TokenHelper.TOKEN_HEADER_PÀRAM);
6161 if (token == null || !tokenHelper.isTokenValid(token)) {
62
- log.info("Access denied to '{}', Token not valid.", servletRequest.getPathInfo());
62
+ LOG.info("Access denied to '{}', Token not valid.", servletRequest.getPathInfo());
6363 containerRequestContext.abortWith(Response.status(Status.UNAUTHORIZED).build());
6464 } else {
6565 Securable sec = method.getAnnotation(Securable.class);
....@@ -69,7 +69,7 @@
6969 int userRoles = getUserRoles(username);
7070 // if (sec.roles() != 0) {
7171 // if ((sec.roles() & userRoles) == 0) {
72
- // log.info("User {} has no necessary role to access url: {}", username, servletRequest.getPathInfo());
72
+ // LOG.info("User {} has no necessary role to access url: {}", username, servletRequest.getPathInfo());
7373 // containerRequestContext.abortWith(Response.status(Status.UNAUTHORIZED).build());
7474 // }
7575 // }
....@@ -80,7 +80,7 @@
8080 containerRequestContext.setSecurityContext(scw);
8181 // Next line provide injection in resource methods
8282 ResteasyProviderFactory.pushContext(BasicSecurityContext.class, scw);
83
- log.debug("Added custom SecurityContext for user {}, orgs: {}", username, orgs);
83
+ LOG.debug("Added custom SecurityContext for user {}, orgs: {}", username, orgs);
8484 }
8585 }
8686
securis/src/main/java/net/curisit/securis/services/ApiResource.java
....@@ -23,7 +23,7 @@
2323 public class ApiResource {
2424
2525 @SuppressWarnings("unused")
26
- private static final Logger log = LogManager.getLogger(ApiResource.class);
26
+ private static final Logger LOG = LogManager.getLogger(ApiResource.class);
2727
2828 @Inject
2929 TokenHelper tokenHelper;
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
....@@ -46,7 +46,7 @@
4646 @Inject
4747 Provider<EntityManager> emProvider;
4848
49
- private static final Logger log = LogManager.getLogger(ApplicationResource.class);
49
+ private static final Logger LOG = LogManager.getLogger(ApplicationResource.class);
5050
5151 public ApplicationResource() {
5252 }
....@@ -60,7 +60,7 @@
6060 @Produces(
6161 { MediaType.APPLICATION_JSON })
6262 public Response index() {
63
- log.info("Getting applications list ");
63
+ LOG.info("Getting applications list ");
6464
6565 EntityManager em = emProvider.get();
6666 TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class);
....@@ -78,16 +78,16 @@
7878 @Produces(
7979 { MediaType.APPLICATION_JSON })
8080 public Response get(@PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
81
- log.info("Getting application data for id: {}: ", appid);
81
+ LOG.info("Getting application data for id: {}: ", appid);
8282 if (appid == null || appid.equals("")) {
83
- log.error("Application ID is mandatory");
83
+ LOG.error("Application ID is mandatory");
8484 return Response.status(Status.NOT_FOUND).build();
8585 }
8686
8787 EntityManager em = emProvider.get();
8888 Application app = em.find(Application.class, Integer.parseInt(appid));
8989 if (app == null) {
90
- log.error("Application with id {} not found in DB", appid);
90
+ LOG.error("Application with id {} not found in DB", appid);
9191
9292 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
9393 }
....@@ -101,7 +101,7 @@
101101 { MediaType.APPLICATION_JSON })
102102 @Transactional
103103 public Response create(Application app, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
104
- log.info("Creating new application");
104
+ LOG.info("Creating new application");
105105 EntityManager em = emProvider.get();
106106 app.setCreationTimestamp(new Date());
107107 em.persist(app);
....@@ -117,11 +117,11 @@
117117 @Produces(
118118 { MediaType.APPLICATION_JSON })
119119 public Response modify(Application app, @PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
120
- log.info("Modifying application with id: {}", appid);
120
+ LOG.info("Modifying application with id: {}", appid);
121121 EntityManager em = emProvider.get();
122122 Application currentapp = em.find(Application.class, Integer.parseInt(appid));
123123 if (currentapp == null) {
124
- log.error("Application with id {} not found in DB", appid);
124
+ LOG.error("Application with id {} not found in DB", appid);
125125 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
126126 }
127127 currentapp.setName(app.getName());
....@@ -137,11 +137,11 @@
137137 @Produces(
138138 { MediaType.APPLICATION_JSON })
139139 public Response delete(@PathParam("appid") String appid, @Context HttpServletRequest request) {
140
- log.info("Deleting app with id: {}", appid);
140
+ LOG.info("Deleting app with id: {}", appid);
141141 EntityManager em = emProvider.get();
142142 Application app = em.find(Application.class, Integer.parseInt(appid));
143143 if (app == null) {
144
- log.error("Application with id {} can not be deleted, It was not found in DB", appid);
144
+ LOG.error("Application with id {} can not be deleted, It was not found in DB", appid);
145145 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
146146 }
147147
securis/src/main/java/net/curisit/securis/services/BasicServices.java
....@@ -36,7 +36,7 @@
3636 @Singleton
3737 public class BasicServices {
3838
39
- private static final Logger log = LogManager.getLogger(BasicServices.class);
39
+ private static final Logger LOG = LogManager.getLogger(BasicServices.class);
4040
4141 @Inject
4242 TokenHelper tokenHelper;
....@@ -58,7 +58,7 @@
5858 @Produces(
5959 { MediaType.TEXT_HTML })
6060 public Response init(@PathParam("module") String module, @Context HttpServletRequest request) {
61
- log.info("App index main.html");
61
+ LOG.info("App index main.html");
6262 String page = "/main.html";
6363 URI uri = UriBuilder.fromUri(page).build();
6464 return Response.seeOther(uri).build();
....@@ -69,9 +69,9 @@
6969 @Produces(
7070 { MediaType.APPLICATION_JSON })
7171 public Response login(@FormParam("username") String user, @FormParam("password") String password, @Context HttpServletRequest request) {
72
- log.info("index session: " + request.getSession());
73
- log.info("user: {}, pass: {}", user, password);
74
- log.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
72
+ LOG.info("index session: " + request.getSession());
73
+ LOG.info("user: {}, pass: {}", user, password);
74
+ LOG.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
7575
7676 if ("no".equals(password))
7777 return Response.status(Status.UNAUTHORIZED).build();
....@@ -101,11 +101,11 @@
101101 if (!valid)
102102 return Response.status(Status.UNAUTHORIZED).build();
103103
104
- // log.info("Token : " + token);
104
+ // LOG.info("Token : " + token);
105105 String user = tokenHelper.extractUserFromToken(token);
106
- // log.info("Token user: " + user);
106
+ // LOG.info("Token user: " + user);
107107 Date date = tokenHelper.extractDateCreationFromToken(token);
108
- // log.info("Token date: " + date);
108
+ // LOG.info("Token date: " + date);
109109
110110 return Response.ok(Utils.createMap("valid", true, "user", user, "date", date)).build();
111111 }
....@@ -119,7 +119,7 @@
119119 if (token == null)
120120 Response.status(Status.BAD_REQUEST).build();
121121 String user = tokenHelper.extractUserFromToken(token);
122
- log.info("User {} has logged out", user);
122
+ LOG.info("User {} has logged out", user);
123123 return Response.ok().build();
124124 }
125125 }
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -47,7 +47,7 @@
4747 @Path("/license")
4848 public class LicenseResource {
4949
50
- private static final Logger log = LogManager.getLogger(LicenseResource.class);
50
+ private static final Logger LOG = LogManager.getLogger(LicenseResource.class);
5151
5252 @Inject
5353 TokenHelper tokenHelper;
....@@ -68,7 +68,7 @@
6868 @Produces(
6969 { MediaType.APPLICATION_JSON })
7070 public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
71
- log.info("Getting licenses list ");
71
+ LOG.info("Getting licenses list ");
7272
7373 EntityManager em = emProvider.get();
7474
....@@ -77,7 +77,7 @@
7777 if (pack == null)
7878 return Response.ok().build();
7979 if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
80
- log.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal());
80
+ LOG.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal());
8181 return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack licenses").build();
8282 }
8383 }
....@@ -99,7 +99,7 @@
9999 @Produces(
100100 { MediaType.APPLICATION_JSON })
101101 public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
102
- log.info("Getting organization data for id: {}: ", licId);
102
+ LOG.info("Getting organization data for id: {}: ", licId);
103103
104104 EntityManager em = emProvider.get();
105105 License lic = getCurrentLicense(licId, bsc, em);
....@@ -122,11 +122,11 @@
122122 License lic = getCurrentLicense(licId, bsc, em);
123123
124124 if (lic.getLicenseData() == null) {
125
- log.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
125
+ LOG.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
126126 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License has not contain data to generate license file");
127127 }
128128 if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) {
129
- log.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal());
129
+ LOG.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal());
130130 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License is not active, so It can not be downloaded");
131131 }
132132 return Response.ok(lic.getLicenseData()).build();
....@@ -146,7 +146,7 @@
146146 License lic = getCurrentLicense(licId, bsc, em);
147147
148148 if (License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
149
- log.error("License with id {} can not be activated from current license status", licId);
149
+ LOG.error("License with id {} can not be activated from current license status", licId);
150150 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be activated from the current license status");
151151 }
152152
....@@ -193,7 +193,7 @@
193193 License lic = getCurrentLicense(licId, bsc, em);
194194
195195 if (License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) {
196
- log.error("License with id {} can not be canceled from current license status", licId);
196
+ LOG.error("License with id {} can not be canceled from current license status", licId);
197197 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be canceled from the current license status");
198198 }
199199
....@@ -214,18 +214,18 @@
214214 { MediaType.APPLICATION_JSON })
215215 @Transactional
216216 public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
217
- log.info("Creating new license from create()");
217
+ LOG.info("Creating new license from create()");
218218 EntityManager em = emProvider.get();
219219 Pack pack = null;
220220 if (lic.getPackId() != null) {
221221 pack = em.find(Pack.class, lic.getPackId());
222222 if (pack == null) {
223
- log.error("License pack with id {} not found in DB", lic.getPackId());
223
+ LOG.error("License pack with id {} not found in DB", lic.getPackId());
224224 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build();
225225 } else {
226226 if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
227227 if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
228
- log.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
228
+ LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
229229 return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
230230 }
231231 }
....@@ -273,7 +273,7 @@
273273 @Produces(
274274 { MediaType.APPLICATION_JSON })
275275 public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
276
- log.info("Modifying organization with id: {}", licId);
276
+ LOG.info("Modifying organization with id: {}", licId);
277277
278278 EntityManager em = emProvider.get();
279279
....@@ -296,12 +296,12 @@
296296 @Produces(
297297 { MediaType.APPLICATION_JSON })
298298 public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
299
- log.info("Deleting license with id: {}", licId);
299
+ LOG.info("Deleting license with id: {}", licId);
300300 EntityManager em = emProvider.get();
301301 License lic = getCurrentLicense(licId, bsc, em);
302302
303303 if (lic.getStatus() != License.Status.CANCELED || lic.getStatus() != License.Status.CREATED) {
304
- log.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus());
304
+ LOG.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus());
305305 return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License can not be deleted in current status").build();
306306 }
307307
....@@ -311,18 +311,18 @@
311311
312312 private License getCurrentLicense(Integer licId, BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException {
313313 if (licId == null || licId.equals("")) {
314
- log.error("License ID is mandatory");
314
+ LOG.error("License ID is mandatory");
315315 throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "Missing license ID");
316316 }
317317
318318 License lic = em.find(License.class, licId);
319319 if (lic == null) {
320
- log.error("License with id {} not found in DB", licId);
320
+ LOG.error("License with id {} not found in DB", licId);
321321 throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId);
322322 }
323323 if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
324324 if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
325
- log.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
325
+ LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
326326 throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
327327 }
328328 }
securis/src/main/java/net/curisit/securis/services/LicenseServices.java
....@@ -33,7 +33,7 @@
3333 public class LicenseServices {
3434
3535 // private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class);
36
- private static final Logger log = LogManager.getLogger(LicenseServices.class);
36
+ private static final Logger LOG = LogManager.getLogger(LicenseServices.class);
3737
3838 private static final int DEFAULT_LICENSE_EXPIRATION = 365;
3939 private static final String LICENSE_STRING = "CurisIntegrity Config Server v{0}.{1}";
....@@ -58,8 +58,7 @@
5858 String index = IOUtils.toString(this.getClass().getResourceAsStream("/static/index.html"));
5959 return Response.ok().entity(index).build();
6060 } catch (IOException e) {
61
- // TODO Auto-generated catch block
62
- e.printStackTrace();
61
+ LOG.error("Error getting index.html", e);
6362 }
6463 return Response.ok().entity(MessageFormat.format(LICENSE_STRING, 0, 1)).build();
6564 }
....@@ -69,7 +68,7 @@
6968 @Produces(
7069 { MediaType.TEXT_PLAIN })
7170 public Response dummy(@Context HttpServletRequest request) {
72
- log.info("Request: " + request.getPathInfo());
71
+ LOG.info("Request: " + request.getPathInfo());
7372 return Response.ok().entity((uri == null)).build();
7473 }
7574
....@@ -82,7 +81,7 @@
8281 @Produces(
8382 { MediaType.APPLICATION_JSON })
8483 public Response testFile1(@MultipartForm FileUploadForm mfdi) {
85
- log.info("FORM: texto: {}, file: {}", mfdi.getTexto(), new String(mfdi.getFile()));
84
+ LOG.info("FORM: texto: {}, file: {}", mfdi.getTexto(), new String(mfdi.getFile()));
8685 return Response.ok("OK").build();
8786 }
8887
....@@ -92,7 +91,7 @@
9291 { MediaType.APPLICATION_JSON })
9392 public ServiceResponse<ServerConfigVersions> testFile(@PathParam("license") String license, @DefaultValue("-1") @QueryParam("minorVersion") int minorVersion, @DefaultValue("-1") @QueryParam("majorVersion") int majorVersion) {
9493
95
- log.info("Called 'current' service with license: {}", license);
94
+ LOG.info("Called 'current' service with license: {}", license);
9695 ServiceResponse<ServerConfigVersions> response = new ServiceResponse<ServerConfigVersions>();
9796
9897 return response;
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
....@@ -24,6 +24,7 @@
2424
2525 import net.curisit.integrity.commons.Utils;
2626 import net.curisit.securis.DefaultExceptionHandler;
27
+import net.curisit.securis.SeCurisException;
2728 import net.curisit.securis.db.Application;
2829 import net.curisit.securis.db.LicenseType;
2930 import net.curisit.securis.utils.TokenHelper;
....@@ -41,7 +42,7 @@
4142 @Path("/licensetype")
4243 public class LicenseTypeResource {
4344
44
- private static final Logger log = LogManager.getLogger(LicenseTypeResource.class);
45
+ private static final Logger LOG = LogManager.getLogger(LicenseTypeResource.class);
4546
4647 @Inject
4748 TokenHelper tokenHelper;
....@@ -61,7 +62,7 @@
6162 @Produces(
6263 { MediaType.APPLICATION_JSON })
6364 public Response index() {
64
- log.info("Getting license types list ");
65
+ LOG.info("Getting license types list ");
6566
6667 EntityManager em = emProvider.get();
6768 TypedQuery<LicenseType> q = em.createNamedQuery("list-license_types", LicenseType.class);
....@@ -79,16 +80,16 @@
7980 @Produces(
8081 { MediaType.APPLICATION_JSON })
8182 public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
82
- log.info("Getting license type data for id: {}: ", ltid);
83
+ LOG.info("Getting license type data for id: {}: ", ltid);
8384 if (ltid == null || ltid.equals("")) {
84
- log.error("LicenseType ID is mandatory");
85
+ LOG.error("LicenseType ID is mandatory");
8586 return Response.status(Status.NOT_FOUND).build();
8687 }
8788
8889 EntityManager em = emProvider.get();
8990 LicenseType lt = em.find(LicenseType.class, Integer.parseInt(ltid));
9091 if (lt == null) {
91
- log.error("LicenseType with id {} not found in DB", ltid);
92
+ LOG.error("LicenseType with id {} not found in DB", ltid);
9293 return Response.status(Status.NOT_FOUND).build();
9394 }
9495 return Response.ok(lt).build();
....@@ -101,21 +102,20 @@
101102 { MediaType.APPLICATION_JSON })
102103 @Transactional
103104 public Response create(LicenseType lt, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
104
- log.info("Creating new license type");
105
+ LOG.info("Creating new license type");
105106 EntityManager em = emProvider.get();
106
- Application app = null;
107
- if (lt.getApplicationId() != null) {
108
- app = em.find(Application.class, lt.getApplicationId());
109
- if (app == null) {
110
- log.error("LicenseType application with id {} not found in DB", lt.getApplicationId());
111
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type's app not found with ID: " + lt.getApplicationId()).build();
112
- }
113
- } else {
114
- log.error("Application is missing for current license type data");
107
+
108
+ try {
109
+ setApplication(lt, lt.getApplicationId(), em);
110
+ } catch (SeCurisException e) {
111
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
112
+ }
113
+
114
+ if (lt.getApplicationId() == null) {
115
+ LOG.error("Application is missing for current license type data");
115116 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application is missing for current license type data").build();
116117 }
117118
118
- lt.setApplication(app);
119119 lt.setCreationTimestamp(new Date());
120120 em.persist(lt);
121121
....@@ -130,28 +130,39 @@
130130 @Produces(
131131 { MediaType.APPLICATION_JSON })
132132 public Response modify(LicenseType lt, @PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
133
- log.info("Modifying license type with id: {}", ltid);
133
+ LOG.info("Modifying license type with id: {}", ltid);
134134 EntityManager em = emProvider.get();
135135 LicenseType currentlt = em.find(LicenseType.class, Integer.parseInt(ltid));
136136 if (currentlt == null) {
137
- log.error("LicenseType with id {} not found in DB", ltid);
137
+ LOG.error("LicenseType with id {} not found in DB", ltid);
138138 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type not found with ID: " + ltid).build();
139139 }
140
- Application app = null;
141
- if (lt.getApplicationId() != null) {
142
- app = em.find(Application.class, lt.getApplicationId());
143
- if (app == null) {
144
- log.error("LicenseType application with id {} not found in DB", lt.getApplicationId());
145
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type's app not found with ID: " + lt.getApplicationId()).build();
146
- }
140
+
141
+ try {
142
+ setApplication(currentlt, lt.getApplicationId(), em);
143
+ } catch (SeCurisException e) {
144
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
147145 }
146
+
148147 currentlt.setCode(lt.getCode());
149148 currentlt.setName(lt.getName());
150149 currentlt.setDescription(lt.getDescription());
151
- currentlt.setApplication(app);
152150 em.persist(currentlt);
153151
154152 return Response.ok(currentlt).build();
153
+ }
154
+
155
+ private void setApplication(LicenseType licType, Integer applicationId, EntityManager em) throws SeCurisException {
156
+ Application app = null;
157
+ if (applicationId != null) {
158
+ app = em.find(Application.class, applicationId);
159
+ if (app == null) {
160
+ LOG.error("LicenseType application with id {} not found in DB", applicationId);
161
+
162
+ throw new SecurityException("License type's app not found with ID: " + applicationId);
163
+ }
164
+ }
165
+ licType.setApplication(app);
155166 }
156167
157168 @DELETE
....@@ -160,11 +171,11 @@
160171 @Produces(
161172 { MediaType.APPLICATION_JSON })
162173 public Response delete(@PathParam("ltid") String ltid, @Context HttpServletRequest request) {
163
- log.info("Deleting app with id: {}", ltid);
174
+ LOG.info("Deleting app with id: {}", ltid);
164175 EntityManager em = emProvider.get();
165176 LicenseType app = em.find(LicenseType.class, Integer.parseInt(ltid));
166177 if (app == null) {
167
- log.error("LicenseType with id {} can not be deleted, It was not found in DB", ltid);
178
+ LOG.error("LicenseType with id {} can not be deleted, It was not found in DB", ltid);
168179 return Response.status(Status.NOT_FOUND).build();
169180 }
170181
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -26,6 +26,7 @@
2626
2727 import net.curisit.integrity.commons.Utils;
2828 import net.curisit.securis.DefaultExceptionHandler;
29
+import net.curisit.securis.SeCurisException;
2930 import net.curisit.securis.db.Organization;
3031 import net.curisit.securis.db.User;
3132 import net.curisit.securis.security.BasicSecurityContext;
....@@ -46,7 +47,7 @@
4647 @Path("/organization")
4748 public class OrganizationResource {
4849
49
- private static final Logger log = LogManager.getLogger(OrganizationResource.class);
50
+ private static final Logger LOG = LogManager.getLogger(OrganizationResource.class);
5051
5152 @Inject
5253 private Provider<EntityManager> emProvider;
....@@ -65,24 +66,24 @@
6566 @Securable
6667 // @RolesAllowed(SecurityContextWrapper.ROL_ADVANCE)
6768 public Response index(@Context BasicSecurityContext bsc) {
68
- log.info("Getting organizations list ");
69
+ LOG.info("Getting organizations list ");
6970
70
- // log.info("User orgs: {}", request.getAttribute("oser_orgs"));
71
+ // LOG.info("User orgs: {}", request.getAttribute("oser_orgs"));
7172 BasicSecurityContext bsc2 = ResteasyProviderFactory.getContextData(BasicSecurityContext.class);
72
- log.info("bsc: {}", bsc);
73
- log.info("bsc2: {}", bsc2);
74
- // log.info("securityContext: {}", scw);
75
- log.info("securityContext ROL_ADMIN?: {}", bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN));
73
+ LOG.info("bsc: {}", bsc);
74
+ LOG.info("bsc2: {}", bsc2);
75
+ // LOG.info("securityContext: {}", scw);
76
+ LOG.info("securityContext ROL_ADMIN?: {}", bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN));
7677 EntityManager em = emProvider.get();
7778 TypedQuery<Organization> q;
7879 if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
79
- log.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
80
+ LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
8081 q = em.createNamedQuery("list-organizations", Organization.class);
8182 } else {
8283 q = em.createNamedQuery("list-organizations", Organization.class);
8384 // if (securityContext.getOrganizationsIds() == null)
8485 // Response.ok().build();
85
- // log.info("Getting only {} orgs for user: {}", securityContext.getOrganizationsIds(), securityContext.getUserPrincipal());
86
+ // LOG.info("Getting only {} orgs for user: {}", securityContext.getOrganizationsIds(), securityContext.getUserPrincipal());
8687 // q = em.createNamedQuery("list-organizations-by-ids", Organization.class);
8788 // q.setParameter("list_ids", securityContext.getOrganizationsIds());
8889 }
....@@ -102,20 +103,20 @@
102103 { MediaType.APPLICATION_JSON })
103104 @Securable
104105 public Response get(@PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
105
- log.info("Getting organization data for id: {}: ", orgid);
106
+ LOG.info("Getting organization data for id: {}: ", orgid);
106107 if (orgid == null || orgid.equals("")) {
107
- log.error("Organization ID is mandatory");
108
+ LOG.error("Organization ID is mandatory");
108109 return Response.status(Status.NOT_FOUND).build();
109110 }
110111 // if (!securityContext.isOrgAccesible(Integer.parseInt(orgid))) {
111
- // log.error("Organization with id {} not accessible for user: {}", orgid, securityContext.getUserPrincipal());
112
+ // LOG.error("Organization with id {} not accessible for user: {}", orgid, securityContext.getUserPrincipal());
112113 // return Response.status(Status.UNAUTHORIZED).build();
113114 // }
114115
115116 EntityManager em = emProvider.get();
116117 Organization org = em.find(Organization.class, Integer.parseInt(orgid));
117118 if (org == null) {
118
- log.error("Organization with id {} not found in DB", orgid);
119
+ LOG.error("Organization with id {} not found in DB", orgid);
119120 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found, id: " + orgid).build();
120121 }
121122 return Response.ok(org).build();
....@@ -139,16 +140,15 @@
139140 @Securable
140141 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
141142 public Response create(Organization org, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
142
- log.info("Creating new organization");
143
+ LOG.info("Creating new organization");
143144 EntityManager em = emProvider.get();
144
- Organization parentOrg = null;
145
- if (org.getParentOrgId() != null) {
146
- parentOrg = em.find(Organization.class, org.getParentOrgId());
147
- if (parentOrg == null) {
148
- log.error("Organization parent with id {} not found in DB", org.getParentOrgId());
149
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's parent not found with ID: " + org.getParentOrgId()).build();
150
- }
145
+
146
+ try {
147
+ this.setParentOrg(org, org.getParentOrgId(), em);
148
+ } catch (SeCurisException e) {
149
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
151150 }
151
+
152152 List<User> users = null;
153153 List<String> usersIds = org.getUsersIds();
154154 if (usersIds != null && usersIds.size() > 0) {
....@@ -156,7 +156,7 @@
156156 for (String username : usersIds) {
157157 User user = em.find(User.class, username);
158158 if (user == null) {
159
- log.error("Organization user with id {} not found in DB", username);
159
+ LOG.error("Organization user with id {} not found in DB", username);
160160 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build();
161161 }
162162 users.add(user);
....@@ -164,11 +164,40 @@
164164 }
165165
166166 org.setUsers(users);
167
- org.setParentOrganization(parentOrg);
168167 org.setCreationTimestamp(new Date());
169168 em.persist(org);
170169
171170 return Response.ok(org).build();
171
+ }
172
+
173
+ private void setParentOrg(Organization org, Integer parentOrgId, EntityManager em) throws SeCurisException {
174
+ Organization parentOrg = null;
175
+ if (parentOrgId != null) {
176
+ parentOrg = em.find(Organization.class, parentOrgId);
177
+ if (parentOrg == null) {
178
+ LOG.error("Organization parent with id {} not found in DB", org.getParentOrgId());
179
+ throw new SecurityException("Organization's parent not found with ID: " + org.getParentOrgId());
180
+ }
181
+ }
182
+
183
+ org.setParentOrganization(parentOrg);
184
+ }
185
+
186
+ private void setOrgUsers(Organization org, List<String> usersIds, EntityManager em) throws SeCurisException {
187
+ List<User> users = null;
188
+ if (usersIds != null && usersIds.size() > 0) {
189
+ users = new ArrayList<>();
190
+ for (String username : usersIds) {
191
+ User user = em.find(User.class, username);
192
+ if (user == null) {
193
+ LOG.error("Organization user with id '{}' not found in DB", username);
194
+ throw new SecurityException("Organization's user not found with ID: " + username);
195
+ }
196
+ users.add(user);
197
+ }
198
+ }
199
+
200
+ org.setUsers(users);
172201 }
173202
174203 @PUT
....@@ -181,42 +210,31 @@
181210 @Securable
182211 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
183212 public Response modify(Organization org, @PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
184
- log.info("Modifying organization with id: {}", orgid);
213
+ LOG.info("Modifying organization with id: {}", orgid);
185214 EntityManager em = emProvider.get();
186215 Organization currentOrg = em.find(Organization.class, Integer.parseInt(orgid));
187216 if (currentOrg == null) {
188
- log.error("Organization with id {} not found in DB", orgid);
217
+ LOG.error("Organization with id {} not found in DB", orgid);
189218 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found with ID: " + orgid).build();
190219 }
191
- Organization parentOrg = null;
192
- if (org.getParentOrgId() != null) {
193
- parentOrg = em.find(Organization.class, org.getParentOrgId());
194
- if (parentOrg == null) {
195
- log.error("Organization parent with id {} not found in DB", org.getParentOrgId());
196
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's parent not found with ID: " + org.getParentOrgId()).build();
197
- }
198
- if (isCyclicalRelationship(currentOrg.getId(), parentOrg)) {
199
- log.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId());
200
- 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();
220
+ try {
221
+ this.setParentOrg(currentOrg, org.getParentOrgId(), em);
222
+ } catch (SeCurisException e) {
223
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
224
+ }
225
+ if (org.getParentOrganization() != null) {
226
+ if (isCyclicalRelationship(currentOrg.getId(), org.getParentOrganization())) {
227
+ LOG.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId());
228
+ 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();
201229 }
202230 }
203
-
204
- List<User> users = null;
205
- List<String> usersIds = org.getUsersIds();
206
- if (usersIds != null && usersIds.size() > 0) {
207
- users = new ArrayList<>();
208
- for (String username : usersIds) {
209
- User user = em.find(User.class, username);
210
- if (user == null) {
211
- log.error("Organization user with id '{}' not found in DB", username);
212
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build();
213
- }
214
- users.add(user);
215
- }
231
+
232
+ try {
233
+ setOrgUsers(currentOrg, org.getUsersIds(), em);
234
+ } catch (SeCurisException e) {
235
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
216236 }
217237
218
- currentOrg.setUsers(users);
219
- currentOrg.setParentOrganization(parentOrg);
220238 currentOrg.setCode(org.getCode());
221239 currentOrg.setName(org.getName());
222240 currentOrg.setDescription(org.getDescription());
....@@ -233,15 +251,15 @@
233251 @Securable
234252 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
235253 public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) {
236
- log.info("Deleting organization with id: {}", orgid);
254
+ LOG.info("Deleting organization with id: {}", orgid);
237255 EntityManager em = emProvider.get();
238256 Organization org = em.find(Organization.class, Integer.parseInt(orgid));
239257 if (org == null) {
240
- log.error("Organization with id {} can not be deleted, It was not found in DB", orgid);
258
+ LOG.error("Organization with id {} can not be deleted, It was not found in DB", orgid);
241259 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization was not found, ID: " + orgid).build();
242260 }
243261 if (org.getChildOrganizations() != null && org.getChildOrganizations().size() > 0) {
244
- log.error("Organization has children and can not be deleted, ID: " + orgid);
262
+ LOG.error("Organization has children and can not be deleted, ID: " + orgid);
245263 return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization has children and can not be deleted, ID: " + orgid).build();
246264 }
247265
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -5,6 +5,7 @@
55 import java.util.List;
66
77 import javax.annotation.security.RolesAllowed;
8
+import javax.crypto.SealedObject;
89 import javax.inject.Inject;
910 import javax.inject.Provider;
1011 import javax.persistence.EntityManager;
....@@ -24,6 +25,7 @@
2425
2526 import net.curisit.integrity.commons.Utils;
2627 import net.curisit.securis.DefaultExceptionHandler;
28
+import net.curisit.securis.SeCurisException;
2729 import net.curisit.securis.db.LicenseType;
2830 import net.curisit.securis.db.Organization;
2931 import net.curisit.securis.db.Pack;
....@@ -45,7 +47,7 @@
4547 @Path("/pack")
4648 public class PackResource {
4749
48
- private static final Logger log = LogManager.getLogger(PackResource.class);
50
+ private static final Logger LOG = LogManager.getLogger(PackResource.class);
4951
5052 @Inject
5153 TokenHelper tokenHelper;
....@@ -66,14 +68,14 @@
6668 @Produces(
6769 { MediaType.APPLICATION_JSON })
6870 public Response index(@Context BasicSecurityContext bsc) {
69
- log.info("Getting packs list ");
71
+ LOG.info("Getting packs list ");
7072
7173 EntityManager em = emProvider.get();
7274 // TypedQuery<Pack> q = em.createNamedQuery("list-packs-by-orgs", Pack.class);
7375
7476 TypedQuery<Pack> q;
7577 if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
76
- log.info("Getting all packs for user: " + bsc.getUserPrincipal());
78
+ LOG.info("Getting all packs for user: " + bsc.getUserPrincipal());
7779 q = em.createNamedQuery("list-packs", Pack.class);
7880 } else {
7981 q = em.createNamedQuery("list-packs-by-orgs", Pack.class);
....@@ -88,7 +90,7 @@
8890 }
8991
9092 private Response generateErrorUnathorizedAccess(Pack pack, Principal user) {
91
- log.error("Pack with id {} not accesible by user {}", pack, user);
93
+ LOG.error("Pack with id {} not accesible by user {}", pack, user);
9294 return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack").build();
9395 }
9496
....@@ -102,16 +104,16 @@
102104 @Produces(
103105 { MediaType.APPLICATION_JSON })
104106 public Response get(@PathParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
105
- log.info("Getting pack data for id: {}: ", packId);
107
+ LOG.info("Getting pack data for id: {}: ", packId);
106108 if (packId == null || packId.equals("")) {
107
- log.error("Pack ID is mandatory");
109
+ LOG.error("Pack ID is mandatory");
108110 return Response.status(Status.NOT_FOUND).build();
109111 }
110112
111113 EntityManager em = emProvider.get();
112114 Pack pack = em.find(Pack.class, packId);
113115 if (pack == null) {
114
- log.error("Pack with id {} not found in DB", packId);
116
+ LOG.error("Pack with id {} not found in DB", packId);
115117 return Response.status(Status.NOT_FOUND).build();
116118 }
117119 if (bsc.isUserInRole(BasicSecurityContext.ROL_ADVANCE)) {
....@@ -131,35 +133,41 @@
131133 { MediaType.APPLICATION_JSON })
132134 @Transactional
133135 public Response create(Pack pack, @Context BasicSecurityContext bsc) {
134
- log.info("Creating new pack");
136
+ LOG.info("Creating new pack");
135137 EntityManager em = emProvider.get();
136138
137
- Organization org = null;
138
- if (pack.getOrgId() != null) {
139
- org = em.find(Organization.class, pack.getOrgId());
140
- if (org == null) {
141
- log.error("Organization pack with id {} not found in DB", pack.getOrgId());
142
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack organization not found with ID: " + pack.getOrgId()).build();
143
- }
139
+ try {
140
+ setPackOrganization(pack, pack.getOrgId(), em);
141
+ } catch (SeCurisException e) {
142
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
144143 }
145
- LicenseType lt = null;
146
- if (pack.getLicTypeId() != null) {
147
- lt = em.find(LicenseType.class, pack.getLicTypeId());
148
- if (lt == null) {
149
- log.error("Pack license type with id {} not found in DB", pack.getLicTypeId());
150
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
151
- }
144
+
145
+ try {
146
+ setPackLicenseType(pack, pack.getLicTypeId(), em);
147
+ } catch (SeCurisException e) {
148
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
152149 }
153150
154151 User user = em.find(User.class, bsc.getUserPrincipal().getName());
155152
156153 pack.setCreatedBy(user);
157
- pack.setLicenseType(lt);
158
- pack.setOrganization(org);
159154 pack.setCreationTimestamp(new Date());
160155 em.persist(pack);
161156
162157 return Response.ok(pack).build();
158
+ }
159
+
160
+ private void setPackLicenseType(Pack pack, Integer licTypeId, EntityManager em) throws SeCurisException {
161
+ LicenseType lt = null;
162
+ if (licTypeId != null) {
163
+ lt = em.find(LicenseType.class, pack.getLicTypeId());
164
+ if (lt == null) {
165
+ LOG.error("Pack license type with id {} not found in DB", licTypeId);
166
+ throw new SeCurisException("Pack license type not found with ID: " + licTypeId);
167
+// return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
168
+ }
169
+ }
170
+ pack.setLicenseType(lt);
163171 }
164172
165173 @PUT
....@@ -172,29 +180,23 @@
172180 @Produces(
173181 { MediaType.APPLICATION_JSON })
174182 public Response modify(Pack pack, @PathParam("packId") Integer packId) {
175
- log.info("Modifying pack with id: {}", packId);
183
+ LOG.info("Modifying pack with id: {}", packId);
176184 EntityManager em = emProvider.get();
177185 Pack currentPack = em.find(Pack.class, packId);
178186
179
- Organization org = null;
180
- if (pack.getOrgId() != null) {
181
- org = em.find(Organization.class, pack.getOrgId());
182
- if (org == null) {
183
- log.error("Organization pack with id {} not found in DB", pack.getOrgId());
184
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack organization not found with ID: " + pack.getOrgId()).build();
185
- }
187
+ try {
188
+ setPackOrganization(currentPack, pack.getOrgId(), em);
189
+ } catch (SeCurisException e) {
190
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
186191 }
187
- LicenseType lt = null;
188
- if (pack.getLicTypeId() != null) {
189
- lt = em.find(LicenseType.class, pack.getLicTypeId());
190
- if (lt == null) {
191
- log.error("Pack license type with id {} not found in DB", pack.getLicTypeId());
192
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
193
- }
192
+
193
+ try {
194
+ setPackLicenseType(currentPack, pack.getLicTypeId(), em);
195
+ } catch (SeCurisException e) {
196
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
194197 }
198
+
195199 currentPack.setLicensePreactivation(pack.isLicensePreactivation());
196
- currentPack.setLicenseType(lt);
197
- currentPack.setOrganization(org);
198200 currentPack.setCode(pack.getCode());
199201 currentPack.setComments(pack.getComments());
200202 currentPack.setNumLicenses(pack.getNumLicenses());
....@@ -202,6 +204,18 @@
202204 em.persist(currentPack);
203205
204206 return Response.ok(pack).build();
207
+ }
208
+
209
+ private void setPackOrganization(Pack currentPack, Integer orgId, EntityManager em) throws SeCurisException {
210
+ Organization org = null;
211
+ if (orgId != null) {
212
+ org = em.find(Organization.class, orgId);
213
+ if (org == null) {
214
+ LOG.error("Organization pack with id {} not found in DB", orgId);
215
+ throw new SeCurisException("Pack organization not found with ID: " + orgId);
216
+ }
217
+ }
218
+ currentPack.setOrganization(org);
205219 }
206220
207221 @DELETE
....@@ -212,11 +226,11 @@
212226 @Produces(
213227 { MediaType.APPLICATION_JSON })
214228 public Response delete(@PathParam("packId") String packId) {
215
- log.info("Deleting pack with id: {}", packId);
229
+ LOG.info("Deleting pack with id: {}", packId);
216230 EntityManager em = emProvider.get();
217231 Pack org = em.find(Pack.class, Integer.parseInt(packId));
218232 if (org == null) {
219
- log.error("Pack with id {} can not be deleted, It was not found in DB", packId);
233
+ LOG.error("Pack with id {} can not be deleted, It was not found in DB", packId);
220234 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack was not found, ID: " + packId).build();
221235 }
222236
securis/src/main/java/net/curisit/securis/services/UserResource.java
....@@ -28,6 +28,7 @@
2828
2929 import net.curisit.integrity.commons.Utils;
3030 import net.curisit.securis.DefaultExceptionHandler;
31
+import net.curisit.securis.SeCurisException;
3132 import net.curisit.securis.db.Organization;
3233 import net.curisit.securis.db.User;
3334 import net.curisit.securis.utils.TokenHelper;
....@@ -52,7 +53,7 @@
5253 Provider<EntityManager> emProvider;
5354
5455 // private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class);
55
- private static final Logger log = LogManager.getLogger(UserResource.class);
56
+ private static final Logger LOG = LogManager.getLogger(UserResource.class);
5657
5758 public UserResource() {
5859 }
....@@ -66,7 +67,7 @@
6667 @Produces(
6768 { MediaType.APPLICATION_JSON })
6869 public Response index() {
69
- log.info("Getting users list ");
70
+ LOG.info("Getting users list ");
7071
7172 EntityManager em = emProvider.get();
7273 TypedQuery<User> q = em.createNamedQuery("list-users", User.class);
....@@ -85,16 +86,16 @@
8586 @Produces(
8687 { MediaType.APPLICATION_JSON })
8788 public Response get(@PathParam("uid") String uid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
88
- log.info("Getting user data for id: {}: ", uid);
89
+ LOG.info("Getting user data for id: {}: ", uid);
8990 if (uid == null || uid.equals("")) {
90
- log.error("User ID is mandatory");
91
+ LOG.error("User ID is mandatory");
9192 return Response.status(Status.NOT_FOUND).build();
9293 }
9394
9495 EntityManager em = emProvider.get();
9596 User lt = em.find(User.class, uid);
9697 if (lt == null) {
97
- log.error("User with id {} not found in DB", uid);
98
+ LOG.error("User with id {} not found in DB", uid);
9899 return Response.status(Status.NOT_FOUND).build();
99100 }
100101 return Response.ok(lt).build();
....@@ -107,35 +108,43 @@
107108 { MediaType.APPLICATION_JSON })
108109 @Transactional
109110 public Response create(User user, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
110
- log.info("Creating new user");
111
+ LOG.info("Creating new user");
111112 EntityManager em = emProvider.get();
112113 User currentUser = em.find(User.class, user.getUsername());
113114 if (currentUser != null) {
114
- log.info("User with id {} was found in DB, we'll try to modify it", user.getUsername());
115
+ LOG.info("User with id {} was found in DB, we'll try to modify it", user.getUsername());
115116 return modify(user, user.getUsername(), token);
116117 }
117
-
118
- Set<Organization> orgs = null;
119
- Set<Integer> orgsIds = user.getOrgsIds();
120
- if (orgsIds != null && orgsIds.size() > 0) {
121
- orgs = new HashSet<>();
122
- for (Integer orgId : orgsIds) {
123
- Organization o = em.find(Organization.class, orgId);
124
- if (o == null) {
125
- log.error("User organization with id {} not found in DB", orgId);
126
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User's organization not found with ID: " + orgId).build();
127
- }
128
- orgs.add(o);
129
- }
118
+
119
+ try {
120
+ this.setUserOrg(user, user.getOrgsIds(), em);
121
+ } catch (SeCurisException e) {
122
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
130123 }
131
-
132
- user.setOrganizations(orgs);
133124 user.setModificationTimestamp(new Date());
134125 user.setLastLogin(null);
135126 user.setCreationTimestamp(new Date());
136127 em.persist(user);
137128
138129 return Response.ok(user).build();
130
+ }
131
+
132
+ private void setUserOrg(User user, Set<Integer> orgsIds, EntityManager em) throws SeCurisException {
133
+ Set<Organization> orgs = null;
134
+ if (orgsIds != null && orgsIds.size() > 0) {
135
+ orgs = new HashSet<>();
136
+ for (Integer orgId : orgsIds) {
137
+ Organization o = em.find(Organization.class, orgId);
138
+ if (o == null) {
139
+ LOG.error("User organization with id {} not found in DB", orgId);
140
+ throw new SeCurisException("User's organization not found with ID: " + orgId);
141
+ }
142
+ orgs.add(o);
143
+ }
144
+ }
145
+
146
+ user.setOrganizations(orgs);
147
+
139148 }
140149
141150 @PUT
....@@ -146,29 +155,19 @@
146155 @Produces(
147156 { MediaType.APPLICATION_JSON })
148157 public Response modify(User user, @PathParam("uid") String uid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
149
- log.info("Modifying user with id: {}", uid);
158
+ LOG.info("Modifying user with id: {}", uid);
150159 EntityManager em = emProvider.get();
151160 User currentUser = em.find(User.class, uid);
152161 if (currentUser == null) {
153
- log.info("User with id {} not found in DB, we'll try to create it", uid);
162
+ LOG.info("User with id {} not found in DB, we'll try to create it", uid);
154163 return create(user, token);
155164 }
156165
157
- Set<Organization> orgs = null;
158
- Set<Integer> orgsIds = user.getOrgsIds();
159
- if (orgsIds != null && orgsIds.size() > 0) {
160
- orgs = new HashSet<>();
161
- for (Integer orgId : orgsIds) {
162
- Organization o = em.find(Organization.class, orgId);
163
- if (o == null) {
164
- log.error("User organization with id {} not found in DB", orgId);
165
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User's user not found with ID: " + orgId).build();
166
- }
167
- orgs.add(o);
168
- }
166
+ try {
167
+ this.setUserOrg(currentUser, user.getOrgsIds(), em);
168
+ } catch (SeCurisException e) {
169
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
169170 }
170
-
171
- currentUser.setOrganizations(orgs);
172171 currentUser.setFirstName(user.getFirstName());
173172 currentUser.setLastName(user.getLastName());
174173 currentUser.setRoles(user.getRoles());
....@@ -188,11 +187,11 @@
188187 @Produces(
189188 { MediaType.APPLICATION_JSON })
190189 public Response delete(@PathParam("uid") String uid, @Context HttpServletRequest request) {
191
- log.info("Deleting app with id: {}", uid);
190
+ LOG.info("Deleting app with id: {}", uid);
192191 EntityManager em = emProvider.get();
193192 User app = em.find(User.class, uid);
194193 if (app == null) {
195
- log.error("User with id {} can not be deleted, It was not found in DB", uid);
194
+ LOG.error("User with id {} can not be deleted, It was not found in DB", uid);
196195 return Response.status(Status.NOT_FOUND).build();
197196 }
198197
....@@ -205,9 +204,9 @@
205204 @Produces(
206205 { MediaType.APPLICATION_JSON })
207206 public Response login(@FormParam("username") String user, @FormParam("password") String password, @Context HttpServletRequest request) {
208
- log.info("index session: " + request.getSession());
209
- log.info("user: {}, pass: {}", user, password);
210
- log.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
207
+ LOG.info("index session: " + request.getSession());
208
+ LOG.info("user: {}, pass: {}", user, password);
209
+ LOG.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
211210
212211 if ("no".equals(password))
213212 return Response.status(Status.UNAUTHORIZED).build();
....@@ -233,14 +232,14 @@
233232 if (token == null)
234233 return Response.status(Status.FORBIDDEN).build();
235234
236
- log.info("Token : " + token);
235
+ LOG.info("Token : " + token);
237236 String user = tokenHelper.extractUserFromToken(token);
238
- log.info("Token user: " + user);
237
+ LOG.info("Token user: " + user);
239238 Date date = tokenHelper.extractDateCreationFromToken(token);
240
- log.info("Token date: " + date);
239
+ LOG.info("Token date: " + date);
241240 boolean valid = tokenHelper.isTokenValid(token);
242241
243
- log.info("Is Token valid: " + valid);
242
+ LOG.info("Is Token valid: " + valid);
244243
245244 return Response.ok(Utils.createMap("valid", true, "user", user, "date", date, "token", token)).build();
246245 }
securis/src/main/java/net/curisit/securis/utils/CacheTTL.java
....@@ -20,7 +20,7 @@
2020 @Singleton
2121 public class CacheTTL {
2222
23
- private static final Logger log = LogManager.getLogger(CacheTTL.class);
23
+ private static final Logger LOG = LogManager.getLogger(CacheTTL.class);
2424
2525 /**
2626 * Period before token expires, set in seconds.
....@@ -42,11 +42,11 @@
4242 // We check for expired object every 60 seconds
4343 Thread.sleep(60 * 1000);
4444 } catch (InterruptedException e) {
45
- log.error("Exiting from Cache Thread");
45
+ LOG.error("Exiting from Cache Thread");
4646 data.clear();
4747 return;
4848 }
49
- // log.info("Cheking expired objects " + new Date());
49
+ // LOG.info("Cheking expired objects " + new Date());
5050 Date now = new Date();
5151 List<String> keysToRemove = new ArrayList<>();
5252 for (String key : CacheTTL.this.data.keySet()) {
securis/src/main/java/net/curisit/securis/utils/TokenHelper.java
....@@ -20,7 +20,7 @@
2020 @Singleton
2121 public class TokenHelper {
2222
23
- private static final Logger log = LogManager.getLogger(TokenHelper.class);
23
+ private static final Logger LOG = LogManager.getLogger(TokenHelper.class);
2424
2525 /**
2626 * Period before token expires, set in hours.
....@@ -52,9 +52,9 @@
5252 sb.append(Utils.toIsoFormat(date));
5353 return Base64.encodeBytes(sb.toString().getBytes("utf-8"));
5454 } catch (NoSuchAlgorithmException e) {
55
- log.error("Error generating SHA-256 hash", e);
55
+ LOG.error("Error generating SHA-256 hash", e);
5656 } catch (UnsupportedEncodingException e) {
57
- log.error("Error generating SHA-256 hash", e);
57
+ LOG.error("Error generating SHA-256 hash", e);
5858 }
5959 return null;
6060
....@@ -92,9 +92,9 @@
9292 String newSecret = generateSecret(user, date);
9393 return newSecret.equals(secret);
9494 } catch (IOException e) {
95
- log.error("Error decoding Base64 token", e);
95
+ LOG.error("Error decoding Base64 token", e);
9696 } catch (NoSuchAlgorithmException e) {
97
- log.error("Error generation secret to compare with", e);
97
+ LOG.error("Error generation secret to compare with", e);
9898 }
9999 return false;
100100 }
....@@ -110,7 +110,7 @@
110110 String user = parts[1];
111111 return user;
112112 } catch (IOException e) {
113
- log.error("Error decoding Base64 token", e);
113
+ LOG.error("Error decoding Base64 token", e);
114114 }
115115 return null;
116116 }
....@@ -124,7 +124,7 @@
124124 Date date = Utils.toDateFromIso(parts[2]);
125125 return date;
126126 } catch (IOException e) {
127
- log.error("Error decoding Base64 token", e);
127
+ LOG.error("Error decoding Base64 token", e);
128128 }
129129 return null;
130130 }
securis/src/patch/java/net/curisit/securis/LicenseGenerator.java
....@@ -33,7 +33,7 @@
3333 */
3434 public class LicenseGenerator {
3535
36
- private static final Logger log = LogManager.getLogger(LicenseGenerator.class);
36
+ private static final Logger LOG = LogManager.getLogger(LicenseGenerator.class);
3737
3838 private static LicenseGenerator singleton = new LicenseGenerator();
3939
....@@ -58,7 +58,7 @@
5858 * @throws SeCurisException
5959 */
6060 public LicenseBean generateLicense(RequestBean req, Map<String, Object> metadata, Date expirationDate, String licenseType, String licenseCode) throws SeCurisException {
61
- log.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), req.getAppCode()));
61
+ LOG.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), req.getAppCode()));
6262 LicenseBean license = new LicenseBean(req);
6363 license.setLicenseType(licenseType);
6464 license.setLicenseCode(licenseCode);
....@@ -83,14 +83,14 @@
8383 json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8");
8484 Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
8585 } catch (UnsupportedEncodingException e) {
86
- log.error("Error creating json doc from license: " + license, e);
86
+ LOG.error("Error creating json doc from license: " + license, e);
8787 throw new SeCurisException("Error creating json doc from license: " + license, e);
8888 } catch (IOException e) {
89
- log.error("Error creating license file: " + file, e);
89
+ LOG.error("Error creating license file: " + file, e);
9090 throw new SeCurisException("Error creating json doc from license: " + license, e);
9191 }
9292
93
- log.info("License saved in {}", file);
93
+ LOG.info("License saved in {}", file);
9494
9595 }
9696
....@@ -119,15 +119,15 @@
119119 licBean.setSignature(Base64.encodeBase64String(signatureData));
120120 return licBean.getSignature();
121121 } catch (NoSuchAlgorithmException e) {
122
- log.error("Error signing license for " + licBean, e);
122
+ LOG.error("Error signing license for " + licBean, e);
123123 } catch (InvalidKeyException e) {
124
- log.error("Error signing license for " + licBean, e);
124
+ LOG.error("Error signing license for " + licBean, e);
125125 } catch (InvalidKeySpecException e) {
126
- log.error("Error signing license for " + licBean, e);
126
+ LOG.error("Error signing license for " + licBean, e);
127127 } catch (IOException e) {
128
- log.error("Error signing license for " + licBean, e);
128
+ LOG.error("Error signing license for " + licBean, e);
129129 } catch (SignatureException e) {
130
- log.error("Error signing license for " + licBean, e);
130
+ LOG.error("Error signing license for " + licBean, e);
131131 }
132132 throw new SeCurisException("License could not be generated");
133133 }
....@@ -136,11 +136,18 @@
136136
137137 RequestBean req = ReqGenerator.getInstance().loadRequest(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req"));
138138 Map<String, Object> metadata = new TreeMap<>();
139
- metadata.put("maxUsers", 20);
140
- metadata.put("maxSessionUsers", 2);
139
+// CurisData parameters:
140
+// metadata.put("maxUsers", 5);
141
+// metadata.put("maxSessionUsers", 100);
142
+ // curisIntegrity
143
+ metadata.put("maxUsers", 0);
144
+ metadata.put("maxInstances", 0);
145
+ metadata.put("timeThreshold", 0);
146
+ metadata.put("datasetPrefix", "BP");
147
+ metadata.put("extendedMode", true);
141148 Date expirationDate = new Date(new Date().getTime() + (1000L * 3600 * 24 * 365 * 10));
142
- LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CD-01", "LIC-CURISTEC-0001");
143
- LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/YanFei.lic"));
149
+ LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CI-01", "LIC-CURISTEC-0001");
150
+ LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/AxelLicCI.lic"));
144151
145152 System.out.print("License expires at: " + expirationDate.getTime());
146153