Skip to content
Snippets Groups Projects
Commit 2e18c021 authored by jerrypan44's avatar jerrypan44 Committed by JerryPan44
Browse files

adding logging support for API calls

parent 45a32a79
Branches
Tags
1 merge request!7Features/keycloak integration
Showing
with 137 additions and 120 deletions
...@@ -66,30 +66,15 @@ ...@@ -66,30 +66,15 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot-starter-actuator.version}</version> <version>${spring-boot-starter-actuator.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
...@@ -99,22 +84,11 @@ ...@@ -99,22 +84,11 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.security.oauth</groupId> <groupId>org.springframework.security.oauth</groupId>
...@@ -146,12 +120,6 @@ ...@@ -146,12 +120,6 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -4,6 +4,7 @@ import eu.hbp.mip.model.UserInfo; ...@@ -4,6 +4,7 @@ import eu.hbp.mip.model.UserInfo;
import eu.hbp.mip.utils.CORSFilter; import eu.hbp.mip.utils.CORSFilter;
import eu.hbp.mip.utils.CustomLoginUrlAuthenticationEntryPoint; import eu.hbp.mip.utils.CustomLoginUrlAuthenticationEntryPoint;
import eu.hbp.mip.utils.HTTPUtil; import eu.hbp.mip.utils.HTTPUtil;
import eu.hbp.mip.utils.UserActionLogging;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -10,6 +10,7 @@ import eu.hbp.mip.model.Article; ...@@ -10,6 +10,7 @@ import eu.hbp.mip.model.Article;
import eu.hbp.mip.model.User; import eu.hbp.mip.model.User;
import eu.hbp.mip.model.UserInfo; import eu.hbp.mip.model.UserInfo;
import eu.hbp.mip.repositories.ArticleRepository; import eu.hbp.mip.repositories.ArticleRepository;
import eu.hbp.mip.utils.UserActionLogging;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -30,8 +31,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; ...@@ -30,8 +31,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(value = "/articles", description = "the articles API") @Api(value = "/articles", description = "the articles API")
public class ArticlesApi { public class ArticlesApi {
private static final Logger LOGGER = LoggerFactory.getLogger(ArticlesApi.class);
@Autowired @Autowired
private UserInfo userInfo; private UserInfo userInfo;
...@@ -44,8 +43,6 @@ public class ArticlesApi { ...@@ -44,8 +43,6 @@ public class ArticlesApi {
@ApiParam(value = "Only ask own articles") @RequestParam(value = "own", required = false) Boolean own, @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 @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(); User user = userInfo.getUser();
Iterable<Article> articles; Iterable<Article> articles;
...@@ -69,6 +66,7 @@ public class ArticlesApi { ...@@ -69,6 +66,7 @@ public class ArticlesApi {
} }
} }
} }
UserActionLogging.LogAction("Get articles", "id : Get All articles");
return ResponseEntity.ok(articles); return ResponseEntity.ok(articles);
} }
...@@ -80,7 +78,6 @@ public class ArticlesApi { ...@@ -80,7 +78,6 @@ public class ArticlesApi {
public ResponseEntity<Void> addAnArticle( public ResponseEntity<Void> addAnArticle(
@RequestBody @ApiParam(value = "Article to create", required = true) @Valid Article article @RequestBody @ApiParam(value = "Article to create", required = true) @Valid Article article
) { ) {
LOGGER.info("Create an article");
User user = userInfo.getUser(); User user = userInfo.getUser();
...@@ -111,7 +108,7 @@ public class ArticlesApi { ...@@ -111,7 +108,7 @@ public class ArticlesApi {
slug = new Slugify().slugify(article.getTitle()); slug = new Slugify().slugify(article.getTitle());
} catch (IOException e) { } catch (IOException e) {
slug = ""; slug = "";
LOGGER.trace("Cannot slugify title", e); //LOGGER.trace("Cannot slugify title", e);
} }
boolean alreadyExists = true; boolean alreadyExists = true;
...@@ -130,8 +127,7 @@ public class ArticlesApi { ...@@ -130,8 +127,7 @@ public class ArticlesApi {
} }
articleRepository.save(article); articleRepository.save(article);
LOGGER.info("Article saved"); UserActionLogging.LogAction("Created article", "id : " + article.getSlug());
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);
} }
...@@ -141,7 +137,7 @@ public class ArticlesApi { ...@@ -141,7 +137,7 @@ public class ArticlesApi {
public ResponseEntity<Article> getAnArticle( public ResponseEntity<Article> getAnArticle(
@ApiParam(value = "slug", required = true) @PathVariable("slug") String slug @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(); User user = userInfo.getUser();
Article article; Article article;
...@@ -149,7 +145,7 @@ public class ArticlesApi { ...@@ -149,7 +145,7 @@ public class ArticlesApi {
if(article == null) if(article == null)
{ {
LOGGER.warn("Cannot find article : " + slug); //LOGGER.warn("Cannot find article : " + slug);
return ResponseEntity.badRequest().body(null); return ResponseEntity.badRequest().body(null);
} }
...@@ -169,7 +165,7 @@ public class ArticlesApi { ...@@ -169,7 +165,7 @@ public class ArticlesApi {
@ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug,
@RequestBody @ApiParam(value = "Article to update", required = true) @Valid Article article @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(); User user = userInfo.getUser();
...@@ -201,7 +197,6 @@ public class ArticlesApi { ...@@ -201,7 +197,6 @@ public class ArticlesApi {
articleRepository.save(article); articleRepository.save(article);
LOGGER.info("Article updated");
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
......
...@@ -20,6 +20,7 @@ import org.springframework.http.HttpStatus; ...@@ -20,6 +20,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import eu.hbp.mip.utils.JWTUtil; import eu.hbp.mip.utils.JWTUtil;
import eu.hbp.mip.utils.UserActionLogging;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
...@@ -33,7 +34,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; ...@@ -33,7 +34,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(value = "/experiments", description = "the experiments API") @Api(value = "/experiments", description = "the experiments API")
public class ExperimentApi { 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(); private static final Gson gson = new Gson();
...@@ -61,7 +62,7 @@ public class ExperimentApi { ...@@ -61,7 +62,7 @@ public class ExperimentApi {
@ApiOperation(value = "Create an experiment on Exareme", response = Experiment.class) @ApiOperation(value = "Create an experiment on Exareme", response = Experiment.class)
@RequestMapping(value = "/exareme", method = RequestMethod.POST) @RequestMapping(value = "/exareme", method = RequestMethod.POST)
public ResponseEntity<String> runExaremeExperiment(@RequestBody ExperimentQuery expQuery) { public ResponseEntity<String> runExaremeExperiment(@RequestBody ExperimentQuery expQuery) {
LOGGER.info("send ExaremeExperiment"); //LOGGER.info("send ExaremeExperiment");
Experiment experiment = saveExperiment(expQuery); Experiment experiment = saveExperiment(expQuery);
...@@ -87,8 +88,8 @@ public class ExperimentApi { ...@@ -87,8 +88,8 @@ public class ExperimentApi {
experiment.setHasError(code >= 400); experiment.setHasError(code >= 400);
experiment.setHasServerError(code >= 500); experiment.setHasServerError(code >= 500);
} catch (IOException e) { } catch (IOException e) {
LOGGER.trace("Invalid UUID", e); //LOGGER.trace("Invalid UUID", e);
LOGGER.warn("Exareme experiment failed to run properly !"); //LOGGER.warn("Exareme experiment failed to run properly !");
experiment.setHasError(true); experiment.setHasError(true);
experiment.setHasServerError(true); experiment.setHasServerError(true);
experiment.setResult(e.getMessage()); experiment.setResult(e.getMessage());
...@@ -96,13 +97,14 @@ public class ExperimentApi { ...@@ -96,13 +97,14 @@ public class ExperimentApi {
finishExperiment(experiment); finishExperiment(experiment);
}).start(); }).start();
UserActionLogging.LogAction("create ExaremeExperiment", "no info");
return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK);
} }
@ApiOperation(value = "Create a workflow", response = Experiment.class) @ApiOperation(value = "Create a workflow", response = Experiment.class)
@RequestMapping(value = "/workflow", method = RequestMethod.POST) @RequestMapping(value = "/workflow", method = RequestMethod.POST)
public ResponseEntity<String> runWorkflow(@RequestBody ExperimentQuery expQuery) { public ResponseEntity<String> runWorkflow(@RequestBody ExperimentQuery expQuery) {
LOGGER.info("send Workflow");
Experiment experiment = saveExperiment(expQuery); Experiment experiment = saveExperiment(expQuery);
...@@ -132,7 +134,7 @@ public class ExperimentApi { ...@@ -132,7 +134,7 @@ public class ExperimentApi {
experiment.setHasError(code >= 400); experiment.setHasError(code >= 400);
experiment.setHasServerError(code >= 500); experiment.setHasServerError(code >= 500);
} catch (IOException e) { } catch (IOException e) {
LOGGER.trace("Invalid UUID", e); //LOGGER.trace("Invalid UUID", e);
experiment.setHasError(true); experiment.setHasError(true);
experiment.setHasServerError(true); experiment.setHasServerError(true);
experiment.setResult(e.getMessage()); experiment.setResult(e.getMessage());
...@@ -140,6 +142,8 @@ public class ExperimentApi { ...@@ -140,6 +142,8 @@ public class ExperimentApi {
finishExperiment(experiment); finishExperiment(experiment);
}).start(); }).start();
UserActionLogging.LogAction("create workflow", "no info");
return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK);
} }
...@@ -147,15 +151,14 @@ public class ExperimentApi { ...@@ -147,15 +151,14 @@ public class ExperimentApi {
@RequestMapping(value = "/{uuid}", method = RequestMethod.GET) @RequestMapping(value = "/{uuid}", method = RequestMethod.GET)
public ResponseEntity<String> getExperiment( public ResponseEntity<String> getExperiment(
@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { @ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) {
LOGGER.info("Get an experiment");
Experiment experiment; Experiment experiment;
UUID experimentUuid; UUID experimentUuid;
try { try {
experimentUuid = UUID.fromString(uuid); experimentUuid = UUID.fromString(uuid);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
LOGGER.trace("Invalid UUID", iae); //LOGGER.trace("Invalid UUID", iae);
LOGGER.warn("An invalid Experiment UUID was received ! " + uuid); //LOGGER.warn("An invalid Experiment UUID was received ! " + uuid);
return ResponseEntity.badRequest().body("Invalid Experiment UUID"); return ResponseEntity.badRequest().body("Invalid Experiment UUID");
} }
...@@ -165,6 +168,8 @@ public class ExperimentApi { ...@@ -165,6 +168,8 @@ public class ExperimentApi {
return new ResponseEntity<>("Not found", HttpStatus.NOT_FOUND); return new ResponseEntity<>("Not found", HttpStatus.NOT_FOUND);
} }
UserActionLogging.LogAction("Get an experiment ", " uuid : "+ uuid);
return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK); return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK);
} }
...@@ -172,7 +177,8 @@ public class ExperimentApi { ...@@ -172,7 +177,8 @@ public class ExperimentApi {
@RequestMapping(value = "/workflow/status/{historyId}", method = RequestMethod.GET) @RequestMapping(value = "/workflow/status/{historyId}", method = RequestMethod.GET)
public ResponseEntity<String> getWorkflowStatus( public ResponseEntity<String> getWorkflowStatus(
@ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId) { @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; String url = workflowUrl + "/getWorkflowStatus/" + historyId;
try { try {
...@@ -186,6 +192,7 @@ public class ExperimentApi { ...@@ -186,6 +192,7 @@ public class ExperimentApi {
} catch (IOException e) { } catch (IOException e) {
return ResponseEntity.status(500).body(e.getMessage()); return ResponseEntity.status(500).body(e.getMessage());
} }
} }
// TODO: factorize workflow results // TODO: factorize workflow results
...@@ -193,7 +200,7 @@ public class ExperimentApi { ...@@ -193,7 +200,7 @@ public class ExperimentApi {
@RequestMapping(value = "/workflow/results/{historyId}", method = RequestMethod.GET) @RequestMapping(value = "/workflow/results/{historyId}", method = RequestMethod.GET)
public ResponseEntity<String> getWorkflowResults( public ResponseEntity<String> getWorkflowResults(
@ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId) { @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; String url = workflowUrl + "/getWorkflowResults/" + historyId;
try { try {
...@@ -214,7 +221,8 @@ public class ExperimentApi { ...@@ -214,7 +221,8 @@ public class ExperimentApi {
public ResponseEntity<String> getWorkflowResultBody( public ResponseEntity<String> getWorkflowResultBody(
@ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId, @ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId,
@ApiParam(value = "resultId", required = true) @PathVariable("resultId") String resultId) { @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; String url = workflowUrl + "/getWorkflowResultsBody/" + historyId + "/contents/" + resultId;
try { try {
...@@ -235,7 +243,7 @@ public class ExperimentApi { ...@@ -235,7 +243,7 @@ public class ExperimentApi {
public ResponseEntity<String> getWorkflowResultsDetails( public ResponseEntity<String> getWorkflowResultsDetails(
@ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId, @ApiParam(value = "historyId", required = true) @PathVariable("historyId") String historyId,
@ApiParam(value = "resultId", required = true) @PathVariable("resultId") String resultId) { @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; String url = workflowUrl + "/getWorkflowResultsDetails/" + historyId + "/contents/" + resultId;
try { try {
...@@ -255,7 +263,8 @@ public class ExperimentApi { ...@@ -255,7 +263,8 @@ public class ExperimentApi {
@RequestMapping(value = "/{uuid}/markAsViewed", method = RequestMethod.GET) @RequestMapping(value = "/{uuid}/markAsViewed", method = RequestMethod.GET)
public ResponseEntity<String> markExperimentAsViewed( public ResponseEntity<String> markExperimentAsViewed(
@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { @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; Experiment experiment;
UUID experimentUuid; UUID experimentUuid;
...@@ -263,8 +272,8 @@ public class ExperimentApi { ...@@ -263,8 +272,8 @@ public class ExperimentApi {
try { try {
experimentUuid = UUID.fromString(uuid); experimentUuid = UUID.fromString(uuid);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
LOGGER.trace("Invalid UUID", iae); //LOGGER.trace("Invalid UUID", iae);
LOGGER.warn("An invalid Experiment UUID was received !"); //LOGGER.warn("An invalid Experiment UUID was received !");
return ResponseEntity.badRequest().body("Invalid Experiment UUID"); return ResponseEntity.badRequest().body("Invalid Experiment UUID");
} }
...@@ -274,7 +283,7 @@ public class ExperimentApi { ...@@ -274,7 +283,7 @@ public class ExperimentApi {
experiment.setResultsViewed(true); experiment.setResultsViewed(true);
experimentRepository.save(experiment); 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); return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK);
} }
...@@ -283,7 +292,8 @@ public class ExperimentApi { ...@@ -283,7 +292,8 @@ public class ExperimentApi {
@RequestMapping(value = "/{uuid}/markAsShared", method = RequestMethod.GET) @RequestMapping(value = "/{uuid}/markAsShared", method = RequestMethod.GET)
public ResponseEntity<String> markExperimentAsShared( public ResponseEntity<String> markExperimentAsShared(
@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { @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); return doMarkExperimentAsShared(uuid, true);
} }
...@@ -292,7 +302,7 @@ public class ExperimentApi { ...@@ -292,7 +302,7 @@ public class ExperimentApi {
@RequestMapping(value = "/{uuid}/markAsUnshared", method = RequestMethod.GET) @RequestMapping(value = "/{uuid}/markAsUnshared", method = RequestMethod.GET)
public ResponseEntity<String> markExperimentAsUnshared( public ResponseEntity<String> markExperimentAsUnshared(
@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) { @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); return doMarkExperimentAsShared(uuid, false);
} }
...@@ -301,7 +311,8 @@ public class ExperimentApi { ...@@ -301,7 +311,8 @@ public class ExperimentApi {
@RequestMapping(method = RequestMethod.GET, params = { "maxResultCount" }) @RequestMapping(method = RequestMethod.GET, params = { "maxResultCount" })
public ResponseEntity<String> listExperiments( public ResponseEntity<String> listExperiments(
@ApiParam(value = "maxResultCount") @RequestParam int maxResultCount) { @ApiParam(value = "maxResultCount") @RequestParam int maxResultCount) {
LOGGER.info("List experiments");
UserActionLogging.LogAction("List experiments", " maxResultCount : "+ maxResultCount);
return doListExperiments(false, null); return doListExperiments(false, null);
} }
...@@ -310,7 +321,8 @@ public class ExperimentApi { ...@@ -310,7 +321,8 @@ public class ExperimentApi {
@RequestMapping(method = RequestMethod.GET, params = { "slug", "maxResultCount" }) @RequestMapping(method = RequestMethod.GET, params = { "slug", "maxResultCount" })
public ResponseEntity<String> listExperiments(@ApiParam(value = "slug") @RequestParam("slug") String modelSlug, public ResponseEntity<String> listExperiments(@ApiParam(value = "slug") @RequestParam("slug") String modelSlug,
@ApiParam(value = "maxResultCount") @RequestParam("maxResultCount") int maxResultCount) { @ApiParam(value = "maxResultCount") @RequestParam("maxResultCount") int maxResultCount) {
LOGGER.info("List experiments");
UserActionLogging.LogAction("List experiments", " modelSlug : "+ modelSlug);
if (maxResultCount <= 0 && (modelSlug == null || "".equals(modelSlug))) { if (maxResultCount <= 0 && (modelSlug == null || "".equals(modelSlug))) {
return new ResponseEntity<>("You must provide at least a slug or a limit of result", return new ResponseEntity<>("You must provide at least a slug or a limit of result",
...@@ -323,7 +335,7 @@ public class ExperimentApi { ...@@ -323,7 +335,7 @@ public class ExperimentApi {
@ApiOperation(value = "list my experiments", response = Experiment.class, responseContainer = "List") @ApiOperation(value = "list my experiments", response = Experiment.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, params = { "mine" }) @RequestMapping(method = RequestMethod.GET, params = { "mine" })
public ResponseEntity<String> listMyExperiments(@ApiParam(value = "mine") @RequestParam("mine") boolean 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); return doListExperiments(true, null);
} }
...@@ -361,8 +373,8 @@ public class ExperimentApi { ...@@ -361,8 +373,8 @@ public class ExperimentApi {
try { try {
experimentUuid = UUID.fromString(uuid); experimentUuid = UUID.fromString(uuid);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
LOGGER.trace("Invalid UUID", iae); //LOGGER.trace("Invalid UUID", iae);
LOGGER.warn("An invalid Experiment UUID was received !"); //LOGGER.warn("An invalid Experiment UUID was received !");
return ResponseEntity.badRequest().body("Invalid Experiment UUID"); return ResponseEntity.badRequest().body("Invalid Experiment UUID");
} }
...@@ -374,7 +386,7 @@ public class ExperimentApi { ...@@ -374,7 +386,7 @@ public class ExperimentApi {
experiment.setShared(shared); experiment.setShared(shared);
experimentRepository.save(experiment); 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); return new ResponseEntity<>(gsonOnlyExposed.toJson(experiment.jsonify()), HttpStatus.OK);
} }
...@@ -383,7 +395,7 @@ public class ExperimentApi { ...@@ -383,7 +395,7 @@ public class ExperimentApi {
experiment.setFinished(new Date()); experiment.setFinished(new Date());
experimentRepository.save(experiment); experimentRepository.save(experiment);
LOGGER.info("Experiment updated (finished)"); UserActionLogging.LogAction("Experiment updated (finished)","");
} }
private HashMap<String, String> makeObject(String name, String value) { private HashMap<String, String> makeObject(String name, String value) {
...@@ -395,7 +407,6 @@ public class ExperimentApi { ...@@ -395,7 +407,6 @@ public class ExperimentApi {
} }
private Experiment saveExperiment(ExperimentQuery expQuery) { private Experiment saveExperiment(ExperimentQuery expQuery) {
LOGGER.info("saveExperiment");
Experiment experiment = new Experiment(); Experiment experiment = new Experiment();
experiment.setUuid(UUID.randomUUID()); experiment.setUuid(UUID.randomUUID());
...@@ -408,7 +419,7 @@ public class ExperimentApi { ...@@ -408,7 +419,7 @@ public class ExperimentApi {
experiment.setModel(modelRepository.findOne(expQuery.getModel())); experiment.setModel(modelRepository.findOne(expQuery.getModel()));
experimentRepository.save(experiment); experimentRepository.save(experiment);
LOGGER.info("Experiment saved"); UserActionLogging.LogAction("Saved an experiment", " id : "+experiment.getUuid());
return experiment; return experiment;
} }
......
...@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import eu.hbp.mip.utils.UserActionLogging;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -26,7 +27,6 @@ import java.time.LocalDateTime; ...@@ -26,7 +27,6 @@ import java.time.LocalDateTime;
@Api(value = "/protected", description = "the protected files API") @Api(value = "/protected", description = "the protected files API")
public class FilesAPI { public class FilesAPI {
private static final Logger LOGGER = LoggerFactory.getLogger(FilesAPI.class);
@Autowired @Autowired
private UserInfo userInfo; private UserInfo userInfo;
...@@ -36,12 +36,12 @@ public class FilesAPI { ...@@ -36,12 +36,12 @@ public class FilesAPI {
public ResponseEntity<Void> getProtectedFile( public ResponseEntity<Void> getProtectedFile(
@ApiParam(value = "filename", required = true) @PathVariable("filename") String filename @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 filepath = "/protected/" + filename;
String user = userInfo.getUser().getUsername(); String user = userInfo.getUser().getUsername();
String time = LocalDateTime.now().toString(); String time = LocalDateTime.now().toString();
LOGGER.info("User " + user + " downloaded " + filepath + " at "+ time); UserActionLogging.LogAction("User " + user + " downloaded " + filepath, "");
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("X-Accel-Redirect", filepath); headers.add("X-Accel-Redirect", filepath);
......
...@@ -13,14 +13,13 @@ import org.springframework.web.bind.annotation.*; ...@@ -13,14 +13,13 @@ import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import eu.hbp.mip.utils.JWTUtil; import eu.hbp.mip.utils.JWTUtil;
import eu.hbp.mip.utils.UserActionLogging;
@RestController @RestController
@RequestMapping(value = "/jwt", produces = { TEXT_PLAIN_VALUE }) @RequestMapping(value = "/jwt", produces = { TEXT_PLAIN_VALUE })
@Api(value = "/jwt", description = "the jwt API") @Api(value = "/jwt", description = "the jwt API")
public class JWTApi { public class JWTApi {
private static final Logger LOGGER = LoggerFactory.getLogger(JWTApi.class);
@Autowired @Autowired
private UserInfo userInfo; private UserInfo userInfo;
...@@ -31,7 +30,7 @@ public class JWTApi { ...@@ -31,7 +30,7 @@ public class JWTApi {
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public ResponseEntity<String> createJWT() { public ResponseEntity<String> createJWT() {
LOGGER.info("Create a JSON Web Token"); UserActionLogging.LogAction("Create a JSON Web Token", "");
User user = userInfo.getUser(); User user = userInfo.getUser();
String token = JWTUtil.getJWT(jwtSecret, user.getEmail()); String token = JWTUtil.getJWT(jwtSecret, user.getEmail());
......
...@@ -15,13 +15,13 @@ import java.io.IOException; ...@@ -15,13 +15,13 @@ import java.io.IOException;
import eu.hbp.mip.utils.JWTUtil; import eu.hbp.mip.utils.JWTUtil;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import eu.hbp.mip.utils.UserActionLogging;
@RestController @RestController
@RequestMapping(value = "/methods", produces = { APPLICATION_JSON_VALUE }) @RequestMapping(value = "/methods", produces = { APPLICATION_JSON_VALUE })
@Api(value = "/methods", description = "the methods API") @Api(value = "/methods", description = "the methods API")
public class MethodsApi { public class MethodsApi {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodsApi.class);
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
...@@ -40,7 +40,7 @@ public class MethodsApi { ...@@ -40,7 +40,7 @@ public class MethodsApi {
@ApiOperation(value = "List Exareme algorithms and validations", response = String.class) @ApiOperation(value = "List Exareme algorithms and validations", response = String.class)
@RequestMapping(value = "/exareme", method = RequestMethod.GET) @RequestMapping(value = "/exareme", method = RequestMethod.GET)
public ResponseEntity<Object> getExaremeAlgorithms() { public ResponseEntity<Object> getExaremeAlgorithms() {
LOGGER.info("List Exareme algorithms and validations"); UserActionLogging.LogAction("List Exareme algorithms and validations", "");
try { try {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
...@@ -57,7 +57,7 @@ public class MethodsApi { ...@@ -57,7 +57,7 @@ public class MethodsApi {
@ApiOperation(value = "List Galaxy workflows", response = String.class) @ApiOperation(value = "List Galaxy workflows", response = String.class)
@RequestMapping(value = "/workflows", method = RequestMethod.GET) @RequestMapping(value = "/workflows", method = RequestMethod.GET)
public ResponseEntity<Object> getWorkflows() { public ResponseEntity<Object> getWorkflows() {
LOGGER.info("List Galaxy workflows"); UserActionLogging.LogAction("List Galaxy workflows", "");
try { try {
User user = userInfo.getUser(); User user = userInfo.getUser();
......
...@@ -23,6 +23,8 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -23,6 +23,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import eu.hbp.mip.utils.UserActionLogging;
import java.util.*; import java.util.*;
import java.io.IOException; import java.io.IOException;
...@@ -37,7 +39,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; ...@@ -37,7 +39,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(value = "/mining", description = "the mining API") @Api(value = "/mining", description = "the mining API")
public class MiningApi { public class MiningApi {
private static final Logger LOGGER = LoggerFactory.getLogger(MiningApi.class);
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@Autowired @Autowired
...@@ -49,7 +50,7 @@ public class MiningApi { ...@@ -49,7 +50,7 @@ public class MiningApi {
@ApiOperation(value = "Create an histogram on Exareme", response = String.class) @ApiOperation(value = "Create an histogram on Exareme", response = String.class)
@RequestMapping(value = "/exareme", method = RequestMethod.POST) @RequestMapping(value = "/exareme", method = RequestMethod.POST)
public ResponseEntity runExaremeMining(@RequestBody List<HashMap<String, String>> queryList) { 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 query = gson.toJson(queryList);
String url = miningExaremeQueryUrl + "/" + "HISTOGRAMS"; String url = miningExaremeQueryUrl + "/" + "HISTOGRAMS";
...@@ -67,7 +68,7 @@ public class MiningApi { ...@@ -67,7 +68,7 @@ public class MiningApi {
@ApiOperation(value = "Create an descriptive statistic on Exareme", response = String.class) @ApiOperation(value = "Create an descriptive statistic on Exareme", response = String.class)
@RequestMapping(value = "/exareme-stats", method = RequestMethod.POST) @RequestMapping(value = "/exareme-stats", method = RequestMethod.POST)
public ResponseEntity runExaremeDescriptiveStats(@RequestBody List<HashMap<String, String>> queryList) { 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 query = gson.toJson(queryList);
String url = miningExaremeQueryUrl + "/" + "DESCRIPTIVE_STATS"; String url = miningExaremeQueryUrl + "/" + "DESCRIPTIVE_STATS";
......
...@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import eu.hbp.mip.utils.UserActionLogging;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
...@@ -28,7 +29,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; ...@@ -28,7 +29,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(value = "/models", description = "the models API") @Api(value = "/models", description = "the models API")
public class ModelsApi { public class ModelsApi {
private static final Logger LOGGER = LoggerFactory.getLogger(ModelsApi.class);
@Autowired @Autowired
private UserInfo userInfo; private UserInfo userInfo;
...@@ -54,7 +54,7 @@ public class ModelsApi { ...@@ -54,7 +54,7 @@ public class ModelsApi {
@ApiParam(value = "Only ask own models") @RequestParam(value = "own", required = false) Boolean own, @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 @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(); User user = userInfo.getUser();
...@@ -98,7 +98,7 @@ public class ModelsApi { ...@@ -98,7 +98,7 @@ public class ModelsApi {
@RequestBody @ApiParam(value = "Model to create", required = true) Model model @RequestBody @ApiParam(value = "Model to create", required = true) Model model
) { ) {
LOGGER.info("Create a model"); UserActionLogging.LogAction("Create a model","");
User user = userInfo.getUser(); User user = userInfo.getUser();
...@@ -129,7 +129,7 @@ public class ModelsApi { ...@@ -129,7 +129,7 @@ public class ModelsApi {
} }
modelRepository.save(model); 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); return ResponseEntity.status(HttpStatus.CREATED).body(model);
} }
...@@ -165,7 +165,7 @@ public class ModelsApi { ...@@ -165,7 +165,7 @@ public class ModelsApi {
slug = new Slugify().slugify(title); slug = new Slugify().slugify(title);
} catch (IOException e) { } catch (IOException e) {
slug = ""; // Should never happen slug = ""; // Should never happen
LOGGER.trace("Cannot slugify title", e); //LOGGER.trace("Cannot slugify title", e);
} }
return slug; return slug;
} }
...@@ -192,7 +192,7 @@ public class ModelsApi { ...@@ -192,7 +192,7 @@ public class ModelsApi {
public ResponseEntity<Model> getAModel( public ResponseEntity<Model> getAModel(
@ApiParam(value = "slug", required = true) @PathVariable("slug") String slug @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(); User user = userInfo.getUser();
...@@ -200,7 +200,7 @@ public class ModelsApi { ...@@ -200,7 +200,7 @@ public class ModelsApi {
if(model == null) if(model == null)
{ {
LOGGER.warn("Cannot find model : " + slug); //LOGGER.warn("Cannot find model : " + slug);
return ResponseEntity.badRequest().body(null); return ResponseEntity.badRequest().body(null);
} }
...@@ -224,7 +224,7 @@ public class ModelsApi { ...@@ -224,7 +224,7 @@ public class ModelsApi {
@ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug,
@RequestBody @ApiParam(value = "Model to update", required = true) Model model @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(); User user = userInfo.getUser();
Model oldModel = modelRepository.findOne(slug); Model oldModel = modelRepository.findOne(slug);
...@@ -269,7 +269,7 @@ public class ModelsApi { ...@@ -269,7 +269,7 @@ public class ModelsApi {
datasetRepository.save(model.getDataset()); datasetRepository.save(model.getDataset());
modelRepository.save(model); 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); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
......
...@@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream; ...@@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import eu.hbp.mip.utils.UserActionLogging;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
...@@ -28,6 +29,8 @@ public class PathologiesApi { ...@@ -28,6 +29,8 @@ public class PathologiesApi {
@RequestMapping(name = "/pathologies", method = RequestMethod.GET) @RequestMapping(name = "/pathologies", method = RequestMethod.GET)
public String getPathologies() { public String getPathologies() {
UserActionLogging.LogAction("load the pathologies", "");
return loadPathologies(); return loadPathologies();
} }
......
...@@ -18,6 +18,7 @@ import org.springframework.http.HttpStatus; ...@@ -18,6 +18,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import eu.hbp.mip.utils.UserActionLogging;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -30,8 +31,6 @@ import java.util.Base64; ...@@ -30,8 +31,6 @@ import java.util.Base64;
@RestController @RestController
public class SecurityApi { public class SecurityApi {
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityApi.class);
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@Autowired @Autowired
...@@ -47,6 +46,7 @@ public class SecurityApi { ...@@ -47,6 +46,7 @@ public class SecurityApi {
public Object user(Principal principal, HttpServletResponse response) { public Object user(Principal principal, HttpServletResponse response) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
UserActionLogging.LogAction("get user from /user","");
try { try {
String userJSON = mapper.writeValueAsString(userInfo.getUser()); String userJSON = mapper.writeValueAsString(userInfo.getUser());
Cookie cookie = new Cookie("user", URLEncoder.encode(userJSON, "UTF-8")); Cookie cookie = new Cookie("user", URLEncoder.encode(userJSON, "UTF-8"));
...@@ -54,7 +54,7 @@ public class SecurityApi { ...@@ -54,7 +54,7 @@ public class SecurityApi {
cookie.setPath("/"); cookie.setPath("/");
response.addCookie(cookie); response.addCookie(cookie);
} catch (JsonProcessingException | UnsupportedEncodingException e) { } catch (JsonProcessingException | UnsupportedEncodingException e) {
LOGGER.trace("Cannot read user json", e); //LOGGER.trace("Cannot read user json", e);
} }
if (!securityConfiguration.isAuthentication()) { if (!securityConfiguration.isAuthentication()) {
...@@ -77,6 +77,9 @@ public class SecurityApi { ...@@ -77,6 +77,9 @@ public class SecurityApi {
user.setAgreeNDA(agreeNDA); user.setAgreeNDA(agreeNDA);
userRepository.save(user); userRepository.save(user);
} }
UserActionLogging.LogAction("user agreeNDA","");
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
...@@ -110,6 +113,7 @@ public class SecurityApi { ...@@ -110,6 +113,7 @@ public class SecurityApi {
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
object.addProperty("authorization", stringEncoded); object.addProperty("authorization", stringEncoded);
object.addProperty("context", galaxyContext); object.addProperty("context", galaxyContext);
UserActionLogging.LogAction("get galaxy information","");
return ResponseEntity.ok(gson.toJson(object)); return ResponseEntity.ok(gson.toJson(object));
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
package eu.hbp.mip.controllers; package eu.hbp.mip.controllers;
import eu.hbp.mip.utils.UserActionLogging;
import eu.hbp.mip.model.GeneralStats; import eu.hbp.mip.model.GeneralStats;
import eu.hbp.mip.repositories.ArticleRepository; import eu.hbp.mip.repositories.ArticleRepository;
import eu.hbp.mip.repositories.UserRepository; import eu.hbp.mip.repositories.UserRepository;
...@@ -25,7 +25,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; ...@@ -25,7 +25,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(value = "/stats", description = "the stats API") @Api(value = "/stats", description = "the stats API")
public class StatsApi { public class StatsApi {
private static final Logger LOGGER = LoggerFactory.getLogger(StatsApi.class);
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;
...@@ -37,7 +36,7 @@ public class StatsApi { ...@@ -37,7 +36,7 @@ public class StatsApi {
@ApiOperation(value = "Get general statistics", response = GeneralStats.class) @ApiOperation(value = "Get general statistics", response = GeneralStats.class)
@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public ResponseEntity<GeneralStats> getGeneralStatistics() { 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(); GeneralStats stats = new GeneralStats();
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package eu.hbp.mip.controllers; package eu.hbp.mip.controllers;
import eu.hbp.mip.utils.UserActionLogging;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import eu.hbp.mip.model.User; import eu.hbp.mip.model.User;
import eu.hbp.mip.repositories.UserRepository; import eu.hbp.mip.repositories.UserRepository;
...@@ -23,8 +24,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; ...@@ -23,8 +24,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Api(value = "/users", description = "the users API") @Api(value = "/users", description = "the users API")
public class UsersApi { public class UsersApi {
private static final Logger LOGGER = LoggerFactory.getLogger(UsersApi.class);
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;
...@@ -33,7 +32,7 @@ public class UsersApi { ...@@ -33,7 +32,7 @@ public class UsersApi {
public ResponseEntity<User> getAUser( public ResponseEntity<User> getAUser(
@ApiParam(value = "username", required = true) @PathVariable("username") String username @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)); return ResponseEntity.ok(userRepository.findOne(username));
} }
......
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);
}
}
<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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment