diff --git a/README.md b/README.md index fcd9066..e925e2f 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,21 @@ mvn spring-boot:run Once started, navigate to http://127.0.0.1:8080 or http://localhost:8080/ in your web browser. Alternatively, access GCP-hosted version at https://ase-team-project-141125434285.europe-west1.run.app -## Client Program Repository + +## Viewing Log +- Open the GCP project hosting our project [here](https://console.cloud.google.com/welcome?authuser=0&hl=en&project=ageless-answer-474618-u4) +- Navigate to **Monitoring → Logs Explorer** +- Use the time selection tool on the top right to set timeframe of logs you want to view +- In the query textbox, enter the following query: `textPayload:"CLIENT_LOG:"` +Following these instructions will show you a list of all API endpoint calls made as well as their time and the IP address of the client. + +## Client Program -View our client repository here: https://github.com/hc8756/ASE-Team-Project-Client +View our client repository here: https://github.com/hc8756/ASE-Team-Project-Client + +This is an example of a client for general users. It allows the user to log in or create an account before viewing their homepage. The homepage contains a list of the user's transactions which can be added to and edited by the viewer. It also shows a user analyitics of their weekly and monthly budgets. + +A hypothetical second client is one for banking institutions. This client would be different in that they would have a view of multiple accounts rather than only one. They would also have limited write permissions to an account's transactions. They would use our service primarily to view and manage their own users. ## API Documentation diff --git a/src/main/java/dev/ase/teamproject/filter/LoggerFilter.java b/src/main/java/dev/ase/teamproject/filter/LoggerFilter.java new file mode 100644 index 0000000..5abe743 --- /dev/null +++ b/src/main/java/dev/ase/teamproject/filter/LoggerFilter.java @@ -0,0 +1,38 @@ +package dev.ase.teamproject.filter; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.time.Instant; +import org.springframework.stereotype.Component; + +/** + * Logs all incoming API requests with client IP, method, endpoint, and timestamp. + */ +@Component +public class LoggerFilter implements Filter { + + /** {@inheritDoc} */ + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + HttpServletRequest httpRequest = (HttpServletRequest) request; + + String clientIp = httpRequest.getHeader("X-Forwarded-For"); + if (clientIp == null || clientIp.isEmpty()) { + clientIp = request.getRemoteAddr(); + } + + // Simple log format: IP | METHOD | ENDPOINT | TIMESTAMP + System.out.println("CLIENT_LOG: " + clientIp + " | " + + httpRequest.getMethod() + " " + + httpRequest.getRequestURI() + " | " + + Instant.now()); + + chain.doFilter(request, response); + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a20b927..54aa22a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,6 +6,7 @@ spring.datasource.username=postgres spring.datasource.password=PpNN%MKLMy&^*i3 spring.jpa.hibernate.ddl-auto=none +spring.main.allow-bean-definition-overriding=true spring.sql.init.mode=never # Cloud Run settings