From 23d6ec662b80e12f0a7d0dfc29dfd0431e852bb0 Mon Sep 17 00:00:00 2001 From: hc8756 <54907855+hc8756@users.noreply.github.com> Date: Mon, 1 Dec 2025 15:09:04 -0500 Subject: [PATCH 1/2] merged in main --- .../ase/teamproject/filter/LoggerFilter.java | 32 +++++++++++++++++++ src/main/resources/application.properties | 1 + 2 files changed, 33 insertions(+) create mode 100644 src/main/java/dev/ase/teamproject/filter/LoggerFilter.java 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..09c411b --- /dev/null +++ b/src/main/java/dev/ase/teamproject/filter/LoggerFilter.java @@ -0,0 +1,32 @@ +package dev.ase.teamproject.filter; + +import jakarta.servlet.*; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.time.Instant; + +@Component +public class LoggerFilter implements Filter { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + HttpServletRequest httpRequest = (HttpServletRequest) request; + + // Get client IP from X-Forwarded-For (Cloud Run) or remote address + 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()); + + // Continue with the request + 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 From 5799b2099fdc230d9959305aff8398c95f1d6c35 Mon Sep 17 00:00:00 2001 From: hc8756 <54907855+hc8756@users.noreply.github.com> Date: Tue, 2 Dec 2025 17:46:48 -0500 Subject: [PATCH 2/2] updated readme --- README.md | 16 ++++++- .../ase/teamproject/filter/LoggerFilter.java | 48 +++++++++++-------- 2 files changed, 41 insertions(+), 23 deletions(-) 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 index 09c411b..5abe743 100644 --- a/src/main/java/dev/ase/teamproject/filter/LoggerFilter.java +++ b/src/main/java/dev/ase/teamproject/filter/LoggerFilter.java @@ -1,32 +1,38 @@ package dev.ase.teamproject.filter; -import jakarta.servlet.*; +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 org.springframework.stereotype.Component; 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; - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - HttpServletRequest httpRequest = (HttpServletRequest) request; - - // Get client IP from X-Forwarded-For (Cloud Run) or remote address - 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()); - - // Continue with the request - chain.doFilter(request, response); + 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