diff --git a/pom.xml b/pom.xml index f0fbbe9dca59ce783bd43aca6cf05d853af841cc..dfec021ef6dc66f63cbcae42ae73fc67023dcee8 100644 --- a/pom.xml +++ b/pom.xml @@ -66,30 +66,15 @@ </repositories> <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-log4j2</artifactId> - </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>${spring-boot-starter-actuator.version}</version> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.springframework.data</groupId> @@ -99,22 +84,11 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> - </exclusions> + </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.springframework.security.oauth</groupId> @@ -146,12 +120,6 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> - </exclusions> <scope>test</scope> </dependency> <dependency> diff --git a/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java b/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java index b8259bca62316e46275d43e2b90620862bc4ab23..9310be3de5104705f8d6bccf8310e7778bfc77ff 100644 --- a/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java +++ b/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java @@ -4,6 +4,7 @@ import eu.hbp.mip.model.UserInfo; import eu.hbp.mip.utils.CORSFilter; import eu.hbp.mip.utils.CustomLoginUrlAuthenticationEntryPoint; import eu.hbp.mip.utils.HTTPUtil; +import eu.hbp.mip.utils.UserActionLogging; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -131,7 +132,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private Filter ssoFilter() { OAuth2ClientAuthenticationProcessingFilter hbpFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/hbp"); OAuth2RestTemplate hbpTemplate = new OAuth2RestTemplate(hbp(), oauth2ClientContext); - hbpFilter.setAuthenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler(frontendRedirectAfterLogin)); + hbpFilter.setAuthenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler(frontendRedirectAfterLogin)); hbpFilter.setRestTemplate(hbpTemplate); hbpFilter.setTokenServices(new UserInfoTokenServices(hbpResource().getUserInfoUri(), hbp().getClientId())); return hbpFilter; diff --git a/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java b/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java index 3b567b102c182f529006f055a11112efd5c749a7..963b181576f0626620d76b3a0370dcb840767778 100644 --- a/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java @@ -10,6 +10,7 @@ import eu.hbp.mip.model.Article; import eu.hbp.mip.model.User; import eu.hbp.mip.model.UserInfo; import eu.hbp.mip.repositories.ArticleRepository; +import eu.hbp.mip.utils.UserActionLogging; import io.swagger.annotations.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,8 +31,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/articles", description = "the articles API") public class ArticlesApi { - private static final Logger LOGGER = LoggerFactory.getLogger(ArticlesApi.class); - @Autowired private UserInfo userInfo; @@ -44,8 +43,6 @@ public class ArticlesApi { @ApiParam(value = "Only ask own articles") @RequestParam(value = "own", required = false) Boolean own, @ApiParam(value = "Only ask results matching status", allowableValues = "draft, published") @RequestParam(value = "status", required = false) String status ) { - LOGGER.info("Get articles"); - User user = userInfo.getUser(); Iterable<Article> articles; @@ -69,7 +66,8 @@ public class ArticlesApi { } } } - + UserActionLogging.LogAction("Get articles", "id : Get All articles"); + return ResponseEntity.ok(articles); } @@ -80,8 +78,7 @@ public class ArticlesApi { public ResponseEntity<Void> addAnArticle( @RequestBody @ApiParam(value = "Article to create", required = true) @Valid Article article ) { - LOGGER.info("Create an article"); - + User user = userInfo.getUser(); article.setCreatedAt(new Date()); @@ -111,7 +108,7 @@ public class ArticlesApi { slug = new Slugify().slugify(article.getTitle()); } catch (IOException e) { slug = ""; - LOGGER.trace("Cannot slugify title", e); + //LOGGER.trace("Cannot slugify title", e); } boolean alreadyExists = true; @@ -130,8 +127,7 @@ public class ArticlesApi { } articleRepository.save(article); - LOGGER.info("Article saved"); - + UserActionLogging.LogAction("Created article", "id : " + article.getSlug()); return new ResponseEntity<>(HttpStatus.CREATED); } @@ -141,7 +137,7 @@ public class ArticlesApi { public ResponseEntity<Article> getAnArticle( @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug ) { - LOGGER.info("Get an article"); + UserActionLogging.LogAction("Getting an article", "id : " + slug); User user = userInfo.getUser(); Article article; @@ -149,7 +145,7 @@ public class ArticlesApi { if(article == null) { - LOGGER.warn("Cannot find article : " + slug); + //LOGGER.warn("Cannot find article : " + slug); return ResponseEntity.badRequest().body(null); } @@ -169,7 +165,7 @@ public class ArticlesApi { @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @RequestBody @ApiParam(value = "Article to update", required = true) @Valid Article article ) { - LOGGER.info("Update an article"); + UserActionLogging.LogAction("Update an article", "id : " + slug); User user = userInfo.getUser(); @@ -201,8 +197,7 @@ public class ArticlesApi { articleRepository.save(article); - LOGGER.info("Article updated"); - + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java index 9f4fee480c37b7b0b0ac8d3fad50ed8e7bf79e59..deef20f755c0fd961e09a238eb662a671a9532e2 100644 --- a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java @@ -20,6 +20,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import eu.hbp.mip.utils.JWTUtil; +import eu.hbp.mip.utils.UserActionLogging; import java.io.IOException; import java.util.*; @@ -33,7 +34,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/experiments", description = "the experiments API") public class ExperimentApi { - private static final Logger LOGGER = LoggerFactory.getLogger(ExperimentApi.class); + //private static final Logger LOGGER = LoggerFactory.getLogger(ExperimentApi.class); private static final Gson gson = new Gson(); @@ -61,7 +62,7 @@ public class ExperimentApi { @ApiOperation(value = "Create an experiment on Exareme", response = Experiment.class) @RequestMapping(value = "/exareme", method = RequestMethod.POST) public ResponseEntity<String> runExaremeExperiment(@RequestBody ExperimentQuery expQuery) { - LOGGER.info("send ExaremeExperiment"); + //LOGGER.info("send ExaremeExperiment"); Experiment experiment = saveExperiment(expQuery); @@ -87,23 +88,24 @@ public class ExperimentApi { experiment.setHasError(code >= 400); experiment.setHasServerError(code >= 500); } catch (IOException e) { - LOGGER.trace("Invalid UUID", e); - LOGGER.warn("Exareme experiment failed to run properly !"); + //LOGGER.trace("Invalid UUID", e); + //LOGGER.warn("Exareme experiment failed to run properly !"); experiment.setHasError(true); experiment.setHasServerError(true); experiment.setResult(e.getMessage()); } finishExperiment(experiment); }).start(); - + + UserActionLogging.LogAction("create ExaremeExperiment", "no info"); + return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); } @ApiOperation(value = "Create a workflow", response = Experiment.class) @RequestMapping(value = "/workflow", method = RequestMethod.POST) public ResponseEntity<String> runWorkflow(@RequestBody ExperimentQuery expQuery) { - LOGGER.info("send Workflow"); - + Experiment experiment = saveExperiment(expQuery); String algoCode = expQuery.getAlgorithms().get(0).getCode(); @@ -132,7 +134,7 @@ public class ExperimentApi { experiment.setHasError(code >= 400); experiment.setHasServerError(code >= 500); } catch (IOException e) { - LOGGER.trace("Invalid UUID", e); + //LOGGER.trace("Invalid UUID", e); experiment.setHasError(true); experiment.setHasServerError(true); experiment.setResult(e.getMessage()); @@ -140,6 +142,8 @@ public class ExperimentApi { finishExperiment(experiment); }).start(); + UserActionLogging.LogAction("create workflow", "no info"); + return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); } @@ -147,15 +151,14 @@ public class ExperimentApi { @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) public ResponseEntity<String> getExperiment( @ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { - LOGGER.info("Get an experiment"); Experiment experiment; UUID experimentUuid; try { experimentUuid = UUID.fromString(uuid); } catch (IllegalArgumentException iae) { - LOGGER.trace("Invalid UUID", iae); - LOGGER.warn("An invalid Experiment UUID was received ! " + uuid); + //LOGGER.trace("Invalid UUID", iae); + //LOGGER.warn("An invalid Experiment UUID was received ! " + uuid); return ResponseEntity.badRequest().body("Invalid Experiment UUID"); } @@ -164,7 +167,9 @@ public class ExperimentApi { if (experiment == null) { return new ResponseEntity<>("Not found", HttpStatus.NOT_FOUND); } - + + UserActionLogging.LogAction("Get an experiment ", " uuid : "+ uuid); + return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); } @@ -172,8 +177,9 @@ public class ExperimentApi { @RequestMapping(value = "/workflow/status/{historyId}", method = RequestMethod.GET) public ResponseEntity<String> getWorkflowStatus( @ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId) { - LOGGER.info("Get a workflow status"); - + + UserActionLogging.LogAction("Get a workflow status", " historyId : "+ historyId); + String url = workflowUrl + "/getWorkflowStatus/" + historyId; try { User user = userInfo.getUser(); @@ -186,6 +192,7 @@ public class ExperimentApi { } catch (IOException e) { return ResponseEntity.status(500).body(e.getMessage()); } + } // TODO: factorize workflow results @@ -193,8 +200,8 @@ public class ExperimentApi { @RequestMapping(value = "/workflow/results/{historyId}", method = RequestMethod.GET) public ResponseEntity<String> getWorkflowResults( @ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId) { - LOGGER.info("Get a workflow results"); - + UserActionLogging.LogAction("Get workflow results", " historyId : "+ historyId); + String url = workflowUrl + "/getWorkflowResults/" + historyId; try { StringBuilder response = new StringBuilder(); @@ -214,8 +221,9 @@ public class ExperimentApi { public ResponseEntity<String> getWorkflowResultBody( @ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId, @ApiParam(value = "resultId", required = true) @PathVariable("resultId") String resultId) { - LOGGER.info("Get a workflow result content"); + UserActionLogging.LogAction("Get workflow result content", " historyId : "+ historyId + " resultId : "+ resultId); + String url = workflowUrl + "/getWorkflowResultsBody/" + historyId + "/contents/" + resultId; try { StringBuilder response = new StringBuilder(); @@ -235,7 +243,7 @@ public class ExperimentApi { public ResponseEntity<String> getWorkflowResultsDetails( @ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId, @ApiParam(value = "resultId", required = true) @PathVariable("resultId") String resultId) { - LOGGER.info("Get a workflow result content"); + UserActionLogging.LogAction("Get workflow result details", " historyId : "+ historyId + " resultId : "+ resultId); String url = workflowUrl + "/getWorkflowResultsDetails/" + historyId + "/contents/" + resultId; try { @@ -255,7 +263,8 @@ public class ExperimentApi { @RequestMapping(value = "/{uuid}/markAsViewed", method = RequestMethod.GET) public ResponseEntity<String> markExperimentAsViewed( @ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { - LOGGER.info("Mark an experiment as viewed"); + + UserActionLogging.LogAction("Mark an experiment as viewed", " uuid : "+ uuid); Experiment experiment; UUID experimentUuid; @@ -263,8 +272,8 @@ public class ExperimentApi { try { experimentUuid = UUID.fromString(uuid); } catch (IllegalArgumentException iae) { - LOGGER.trace("Invalid UUID", iae); - LOGGER.warn("An invalid Experiment UUID was received !"); + //LOGGER.trace("Invalid UUID", iae); + //LOGGER.warn("An invalid Experiment UUID was received !"); return ResponseEntity.badRequest().body("Invalid Experiment UUID"); } @@ -274,7 +283,7 @@ public class ExperimentApi { experiment.setResultsViewed(true); experimentRepository.save(experiment); - LOGGER.info("Experiment updated (marked as viewed)"); + UserActionLogging.LogAction("Experiment updated (marked as viewed)", " "); return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); } @@ -283,8 +292,9 @@ public class ExperimentApi { @RequestMapping(value = "/{uuid}/markAsShared", method = RequestMethod.GET) public ResponseEntity<String> markExperimentAsShared( @ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { - LOGGER.info("Mark an experiment as shared"); + UserActionLogging.LogAction("Mark an experiment as shared", " uuid : "+ uuid); + return doMarkExperimentAsShared(uuid, true); } @@ -292,8 +302,8 @@ public class ExperimentApi { @RequestMapping(value = "/{uuid}/markAsUnshared", method = RequestMethod.GET) public ResponseEntity<String> markExperimentAsUnshared( @ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { - LOGGER.info("Mark an experiment as unshared"); - + UserActionLogging.LogAction("Mark an experiment as unshared", " uuid : "+ uuid); + return doMarkExperimentAsShared(uuid, false); } @@ -301,8 +311,9 @@ public class ExperimentApi { @RequestMapping(method = RequestMethod.GET, params = { "maxResultCount" }) public ResponseEntity<String> listExperiments( @ApiParam(value = "maxResultCount") @RequestParam int maxResultCount) { - LOGGER.info("List experiments"); + UserActionLogging.LogAction("List experiments", " maxResultCount : "+ maxResultCount); + return doListExperiments(false, null); } @@ -310,7 +321,8 @@ public class ExperimentApi { @RequestMapping(method = RequestMethod.GET, params = { "slug", "maxResultCount" }) public ResponseEntity<String> listExperiments(@ApiParam(value = "slug") @RequestParam("slug") String modelSlug, @ApiParam(value = "maxResultCount") @RequestParam("maxResultCount") int maxResultCount) { - LOGGER.info("List experiments"); + + UserActionLogging.LogAction("List experiments", " modelSlug : "+ modelSlug); if (maxResultCount <= 0 && (modelSlug == null || "".equals(modelSlug))) { return new ResponseEntity<>("You must provide at least a slug or a limit of result", @@ -323,7 +335,7 @@ public class ExperimentApi { @ApiOperation(value = "list my experiments", response = Experiment.class, responseContainer = "List") @RequestMapping(method = RequestMethod.GET, params = { "mine" }) public ResponseEntity<String> listMyExperiments(@ApiParam(value = "mine") @RequestParam("mine") boolean mine) { - LOGGER.info("List my experiments"); + UserActionLogging.LogAction("List my experiments", " mine : "+ mine); return doListExperiments(true, null); } @@ -361,8 +373,8 @@ public class ExperimentApi { try { experimentUuid = UUID.fromString(uuid); } catch (IllegalArgumentException iae) { - LOGGER.trace("Invalid UUID", iae); - LOGGER.warn("An invalid Experiment UUID was received !"); + //LOGGER.trace("Invalid UUID", iae); + //LOGGER.warn("An invalid Experiment UUID was received !"); return ResponseEntity.badRequest().body("Invalid Experiment UUID"); } @@ -373,8 +385,8 @@ public class ExperimentApi { experiment.setShared(shared); experimentRepository.save(experiment); - - LOGGER.info("Experiment updated (marked as shared)"); + + UserActionLogging.LogAction("Experiment updated (marked as shared)", ""); return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); } @@ -383,7 +395,7 @@ public class ExperimentApi { experiment.setFinished(new Date()); experimentRepository.save(experiment); - LOGGER.info("Experiment updated (finished)"); + UserActionLogging.LogAction("Experiment updated (finished)",""); } private HashMap<String, String> makeObject(String name, String value) { @@ -395,7 +407,6 @@ public class ExperimentApi { } private Experiment saveExperiment(ExperimentQuery expQuery) { - LOGGER.info("saveExperiment"); Experiment experiment = new Experiment(); experiment.setUuid(UUID.randomUUID()); @@ -408,7 +419,7 @@ public class ExperimentApi { experiment.setModel(modelRepository.findOne(expQuery.getModel())); experimentRepository.save(experiment); - LOGGER.info("Experiment saved"); + UserActionLogging.LogAction("Saved an experiment", " id : "+experiment.getUuid()); return experiment; } diff --git a/src/main/java/eu/hbp/mip/controllers/FilesAPI.java b/src/main/java/eu/hbp/mip/controllers/FilesAPI.java index d79717062874418824d305a908926f1c61075255..5acdb38ca88a851cb96a3c375c51165b1e157531 100644 --- a/src/main/java/eu/hbp/mip/controllers/FilesAPI.java +++ b/src/main/java/eu/hbp/mip/controllers/FilesAPI.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import eu.hbp.mip.utils.UserActionLogging; import java.time.LocalDateTime; @@ -26,8 +27,7 @@ import java.time.LocalDateTime; @Api(value = "/protected", description = "the protected files API") public class FilesAPI { - private static final Logger LOGGER = LoggerFactory.getLogger(FilesAPI.class); - + @Autowired private UserInfo userInfo; @@ -36,12 +36,12 @@ public class FilesAPI { public ResponseEntity<Void> getProtectedFile( @ApiParam(value = "filename", required = true) @PathVariable("filename") String filename ) { - LOGGER.info("Get protected file"); + UserActionLogging.LogAction("Get protected file", " filename : " + filename); String filepath = "/protected/" + filename; String user = userInfo.getUser().getUsername(); String time = LocalDateTime.now().toString(); - LOGGER.info("User " + user + " downloaded " + filepath + " at "+ time); + UserActionLogging.LogAction("User " + user + " downloaded " + filepath, ""); HttpHeaders headers = new HttpHeaders(); headers.add("X-Accel-Redirect", filepath); diff --git a/src/main/java/eu/hbp/mip/controllers/JWTApi.java b/src/main/java/eu/hbp/mip/controllers/JWTApi.java index a3d939bbba3eb5c5a8666497be9f5c6d6414e446..a1cb6afd55431bb859170b52c9daa7007ca69c42 100644 --- a/src/main/java/eu/hbp/mip/controllers/JWTApi.java +++ b/src/main/java/eu/hbp/mip/controllers/JWTApi.java @@ -13,14 +13,13 @@ import org.springframework.web.bind.annotation.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import eu.hbp.mip.utils.JWTUtil; +import eu.hbp.mip.utils.UserActionLogging; @RestController @RequestMapping(value = "/jwt", produces = { TEXT_PLAIN_VALUE }) @Api(value = "/jwt", description = "the jwt API") public class JWTApi { - private static final Logger LOGGER = LoggerFactory.getLogger(JWTApi.class); - @Autowired private UserInfo userInfo; @@ -31,7 +30,7 @@ public class JWTApi { @RequestMapping(method = RequestMethod.POST) public ResponseEntity<String> createJWT() { - LOGGER.info("Create a JSON Web Token"); + UserActionLogging.LogAction("Create a JSON Web Token", ""); User user = userInfo.getUser(); String token = JWTUtil.getJWT(jwtSecret, user.getEmail()); diff --git a/src/main/java/eu/hbp/mip/controllers/MethodsApi.java b/src/main/java/eu/hbp/mip/controllers/MethodsApi.java index fe7e8cd4535ac8af92603be12d40fad2bd264a74..f88f6795156f566b4b4e6e70288a5e4d535a67da 100644 --- a/src/main/java/eu/hbp/mip/controllers/MethodsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/MethodsApi.java @@ -15,14 +15,14 @@ import java.io.IOException; import eu.hbp.mip.utils.JWTUtil; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import org.springframework.beans.factory.annotation.Autowired; +import eu.hbp.mip.utils.UserActionLogging; @RestController @RequestMapping(value = "/methods", produces = { APPLICATION_JSON_VALUE }) @Api(value = "/methods", description = "the methods API") public class MethodsApi { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodsApi.class); - + private static final Gson gson = new Gson(); @Value("#{'${services.exareme.algorithmsUrl:http://localhost:9090/mining/algorithms.json}'}") @@ -40,7 +40,7 @@ public class MethodsApi { @ApiOperation(value = "List Exareme algorithms and validations", response = String.class) @RequestMapping(value = "/exareme", method = RequestMethod.GET) public ResponseEntity<Object> getExaremeAlgorithms() { - LOGGER.info("List Exareme algorithms and validations"); + UserActionLogging.LogAction("List Exareme algorithms and validations", ""); try { StringBuilder response = new StringBuilder(); @@ -57,7 +57,7 @@ public class MethodsApi { @ApiOperation(value = "List Galaxy workflows", response = String.class) @RequestMapping(value = "/workflows", method = RequestMethod.GET) public ResponseEntity<Object> getWorkflows() { - LOGGER.info("List Galaxy workflows"); + UserActionLogging.LogAction("List Galaxy workflows", ""); try { User user = userInfo.getUser(); diff --git a/src/main/java/eu/hbp/mip/controllers/MiningApi.java b/src/main/java/eu/hbp/mip/controllers/MiningApi.java index c289856a0a69dadeec7e889fc66bf4c231190661..919fb5a2c021e0ced6366fe3685a8ae00a3f8962 100644 --- a/src/main/java/eu/hbp/mip/controllers/MiningApi.java +++ b/src/main/java/eu/hbp/mip/controllers/MiningApi.java @@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import eu.hbp.mip.utils.UserActionLogging; import java.util.*; import java.io.IOException; @@ -34,7 +35,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/mining", description = "the mining API") public class MiningApi { - private static final Logger LOGGER = LoggerFactory.getLogger(MiningApi.class); private static final Gson gson = new Gson(); @Autowired @@ -46,7 +46,7 @@ public class MiningApi { @ApiOperation(value = "Create an histogram on Exareme", response = String.class) @RequestMapping(value = "/exareme", method = RequestMethod.POST) public ResponseEntity runExaremeMining(@RequestBody List<HashMap<String, String>> queryList) { - LOGGER.info("Run an histogram"); + UserActionLogging.LogAction("Run an histogram", ""); String query = gson.toJson(queryList); String url = miningExaremeQueryUrl + "/" + "HISTOGRAMS"; @@ -64,7 +64,7 @@ public class MiningApi { @ApiOperation(value = "Create an descriptive statistic on Exareme", response = String.class) @RequestMapping(value = "/exareme-stats", method = RequestMethod.POST) public ResponseEntity runExaremeDescriptiveStats(@RequestBody List<HashMap<String, String>> queryList) { - LOGGER.info("Run descriptive stats"); + UserActionLogging.LogAction("Run descriptive stats", ""); String query = gson.toJson(queryList); String url = miningExaremeQueryUrl + "/" + "DESCRIPTIVE_STATS"; diff --git a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java index 56bc1ce10bf5c4f322349720b69d48f6b14f61fe..02ee9ac6b25b353876566a7261a7e6deba962574 100644 --- a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java @@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import eu.hbp.mip.utils.UserActionLogging; import java.io.IOException; import java.util.*; @@ -28,7 +29,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/models", description = "the models API") public class ModelsApi { - private static final Logger LOGGER = LoggerFactory.getLogger(ModelsApi.class); @Autowired private UserInfo userInfo; @@ -54,7 +54,7 @@ public class ModelsApi { @ApiParam(value = "Only ask own models") @RequestParam(value = "own", required = false) Boolean own, @ApiParam(value = "Only ask published models") @RequestParam(value = "valid", required = false) Boolean valid ) { - LOGGER.info("Get models"); + UserActionLogging.LogAction("Get models",""); User user = userInfo.getUser(); @@ -98,7 +98,7 @@ public class ModelsApi { @RequestBody @ApiParam(value = "Model to create", required = true) Model model ) { - LOGGER.info("Create a model"); + UserActionLogging.LogAction("Create a model",""); User user = userInfo.getUser(); @@ -129,7 +129,7 @@ public class ModelsApi { } modelRepository.save(model); - LOGGER.info("Model saved (also saved model.config and model.query)"); + UserActionLogging.LogAction("Model saved (also saved model.config and model.query)"," id : " + model.getSlug()); return ResponseEntity.status(HttpStatus.CREATED).body(model); } @@ -165,7 +165,7 @@ public class ModelsApi { slug = new Slugify().slugify(title); } catch (IOException e) { slug = ""; // Should never happen - LOGGER.trace("Cannot slugify title", e); + //LOGGER.trace("Cannot slugify title", e); } return slug; } @@ -192,7 +192,7 @@ public class ModelsApi { public ResponseEntity<Model> getAModel( @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug ) { - LOGGER.info("Get a model"); + UserActionLogging.LogAction("Get a model", " id : " + slug); User user = userInfo.getUser(); @@ -200,7 +200,7 @@ public class ModelsApi { if(model == null) { - LOGGER.warn("Cannot find model : " + slug); + //LOGGER.warn("Cannot find model : " + slug); return ResponseEntity.badRequest().body(null); } @@ -224,7 +224,7 @@ public class ModelsApi { @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @RequestBody @ApiParam(value = "Model to update", required = true) Model model ) { - LOGGER.info("Update a model"); + UserActionLogging.LogAction("Update a model", " id : "+ slug); User user = userInfo.getUser(); Model oldModel = modelRepository.findOne(slug); @@ -269,7 +269,7 @@ public class ModelsApi { datasetRepository.save(model.getDataset()); modelRepository.save(model); - LOGGER.info("Model updated (also saved/updated model.config and model.query)"); + UserActionLogging.LogAction("Model updated (also saved/updated model.config and model.query)", " id : "+ slug); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java b/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java index 59511de85016213a66eb576e8ea7f8410d5d6b0f..27f635d3278e9a2990489b4a3c01bd0d9851c34a 100644 --- a/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java +++ b/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java @@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import eu.hbp.mip.utils.UserActionLogging; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @@ -28,6 +29,8 @@ public class PathologiesApi { @RequestMapping(name = "/pathologies", method = RequestMethod.GET) public String getPathologies() { + UserActionLogging.LogAction("load the pathologies", ""); + return loadPathologies(); } diff --git a/src/main/java/eu/hbp/mip/controllers/SecurityApi.java b/src/main/java/eu/hbp/mip/controllers/SecurityApi.java index 08c6f04107098fee2284b1c783c31bcb5152a5c4..0f93c437ea8477000e1881815cce984eca36f3f8 100644 --- a/src/main/java/eu/hbp/mip/controllers/SecurityApi.java +++ b/src/main/java/eu/hbp/mip/controllers/SecurityApi.java @@ -18,6 +18,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.security.access.prepost.PreAuthorize; +import eu.hbp.mip.utils.UserActionLogging; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; @@ -30,8 +31,6 @@ import java.util.Base64; @RestController public class SecurityApi { - private static final Logger LOGGER = LoggerFactory.getLogger(SecurityApi.class); - private static final Gson gson = new Gson(); @Autowired @@ -46,7 +45,8 @@ public class SecurityApi { @RequestMapping(path = "/user", method = RequestMethod.GET) public Object user(Principal principal, HttpServletResponse response) { ObjectMapper mapper = new ObjectMapper(); - + + UserActionLogging.LogAction("get user from /user",""); try { String userJSON = mapper.writeValueAsString(userInfo.getUser()); Cookie cookie = new Cookie("user", URLEncoder.encode(userJSON, "UTF-8")); @@ -54,7 +54,7 @@ public class SecurityApi { cookie.setPath("/"); response.addCookie(cookie); } catch (JsonProcessingException | UnsupportedEncodingException e) { - LOGGER.trace("Cannot read user json", e); + //LOGGER.trace("Cannot read user json", e); } if (!securityConfiguration.isAuthentication()) { @@ -77,6 +77,9 @@ public class SecurityApi { user.setAgreeNDA(agreeNDA); userRepository.save(user); } + + UserActionLogging.LogAction("user agreeNDA",""); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -110,7 +113,8 @@ public class SecurityApi { JsonObject object = new JsonObject(); object.addProperty("authorization", stringEncoded); object.addProperty("context", galaxyContext); - + UserActionLogging.LogAction("get galaxy information",""); + return ResponseEntity.ok(gson.toJson(object)); } diff --git a/src/main/java/eu/hbp/mip/controllers/StatsApi.java b/src/main/java/eu/hbp/mip/controllers/StatsApi.java index d09c032bc75659c18100a4f58ca3965c2e4b4933..a92adecde01cb383ce4c677b2476b27afa862437 100644 --- a/src/main/java/eu/hbp/mip/controllers/StatsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/StatsApi.java @@ -3,7 +3,7 @@ */ package eu.hbp.mip.controllers; - +import eu.hbp.mip.utils.UserActionLogging; import eu.hbp.mip.model.GeneralStats; import eu.hbp.mip.repositories.ArticleRepository; import eu.hbp.mip.repositories.UserRepository; @@ -25,8 +25,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/stats", description = "the stats API") public class StatsApi { - private static final Logger LOGGER = LoggerFactory.getLogger(StatsApi.class); - + @Autowired private UserRepository userRepository; @@ -37,7 +36,7 @@ public class StatsApi { @ApiOperation(value = "Get general statistics", response = GeneralStats.class) @RequestMapping(method = RequestMethod.GET) public ResponseEntity<GeneralStats> getGeneralStatistics() { - LOGGER.info("Get statistics (count on users, articles and variables)"); + UserActionLogging.LogAction("Get statistics (count on users, articles and variables)",""); GeneralStats stats = new GeneralStats(); diff --git a/src/main/java/eu/hbp/mip/controllers/UsersApi.java b/src/main/java/eu/hbp/mip/controllers/UsersApi.java index 89767017e0557b231e200006f8e330d9ca44ee9c..ed3104eb807ab844c25f20df69fac2c200ed0bf2 100644 --- a/src/main/java/eu/hbp/mip/controllers/UsersApi.java +++ b/src/main/java/eu/hbp/mip/controllers/UsersApi.java @@ -4,6 +4,7 @@ package eu.hbp.mip.controllers; +import eu.hbp.mip.utils.UserActionLogging; import io.swagger.annotations.*; import eu.hbp.mip.model.User; import eu.hbp.mip.repositories.UserRepository; @@ -23,8 +24,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(value = "/users", description = "the users API") public class UsersApi { - private static final Logger LOGGER = LoggerFactory.getLogger(UsersApi.class); - @Autowired private UserRepository userRepository; @@ -33,7 +32,7 @@ public class UsersApi { public ResponseEntity<User> getAUser( @ApiParam(value = "username", required = true) @PathVariable("username") String username ) { - LOGGER.info("Get a user"); + UserActionLogging.LogAction("Get a user",""); return ResponseEntity.ok(userRepository.findOne(username)); } diff --git a/src/main/java/eu/hbp/mip/utils/UserActionLogging.java b/src/main/java/eu/hbp/mip/utils/UserActionLogging.java new file mode 100644 index 0000000000000000000000000000000000000000..745fc24a6ca53951c1f43cd9db2f6fa5965a73d4 --- /dev/null +++ b/src/main/java/eu/hbp/mip/utils/UserActionLogging.java @@ -0,0 +1,23 @@ +package eu.hbp.mip.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.context.SecurityContextHolder; + +import java.time.LocalTime; + +public class UserActionLogging { + + + private static final Logger LOGGER = LoggerFactory.getLogger(UserActionLogging.class); + + public static void LogAction(String actionName, String actionIdInfo) + { + LOGGER.info( LocalTime.now()+" User : " + + SecurityContextHolder.getContext().getAuthentication().getName() + + " called enpoint " + actionName + + " info " + + actionIdInfo); + } + +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000000000000000000000000000000000000..3843fbca8ed514ad3269299ec31302e2d5825f50 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,14 @@ +<configuration> + <appender name="FILE1" class="ch.qos.logback.core.FileAppender"> + <file>logs/log1.txt</file> + <append>true</append> + <encoder> + <pattern>%msg%n</pattern> + </encoder> + </appender> + + + <logger name="eu.hbp.mip.utils" level="INFO" additivity="false"> + <appender-ref ref="FILE1" /> + </logger> +</configuration> \ No newline at end of file