You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "JohnAlva (via GitHub)" <gi...@apache.org> on 2025/06/30 22:00:41 UTC
[PR] FINERACT-2314: Geolocation tracking [fineract]
JohnAlva opened a new pull request, #4825:
URL: https://github.com/apache/fineract/pull/4825
## Description
FINERACT-2314: Geolocation tracking
Ignore if these details are present on the associated [Apache Fineract JIRA ticket](https://github.com/apache/fineract/pull/1284).
## Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
- [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
- [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
- [ ] Create/update unit or integration tests for verifying the changes made.
- [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
- [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
- [ ] Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)
FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "IOhacker (via GitHub)" <gi...@apache.org>.
IOhacker commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3028292940
@adamsaghy content hsa been added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3051567892
@JohnAlva LGTM, but testing is still missing!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "IOhacker (via GitHub)" <gi...@apache.org>.
IOhacker merged PR #4825:
URL: https://github.com/apache/fineract/pull/4825
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2258394669
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java:
##########
@@ -597,4 +599,15 @@ public void checkForUnsupportedParameters(final Type typeOfMap, final String jso
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, requestDataParameters);
}
+ public String getClientIp() {
+ ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ String clientIp = "";
+ if (attrs != null) {
+ Object ipAttr = attrs.getRequest().getAttribute("IP");
+ if (ipAttr != null) {
+ clientIp = ipAttr.toString();
+ }
+ }
+ return clientIp;
Review Comment:
It was implemented as a filter because it is considered an optional value. This allows the system user to decide whether or not they want to capture the IP address.
If it were implemented as a Utils class, the IP capture would be executed automatically at all times, without the possibility of skipping it.
Additionally, we believe it is not necessary to create an additional class solely for this purpose, as it would require more development effort for a functionality that can remain optional more easily through a filter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198804250
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.debug("Found Client IP in header : {}", clientIpAddress);
Review Comment:
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3085254697
@adamsaghy Thanks for the reminder! I’ll make sure to add proper tests to verify the new logic behaves as expected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198794144
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
Review Comment:
The change was made from `log.debug` to `log.trace` to avoid log spam. However, Adamsaghy had previously indicated to use `log.debug`, but the level was ultimately adjusted to `trace`, as you requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198801003
##########
fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java:
##########
@@ -162,6 +166,7 @@ public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final Js
.transactionId(command.getTransactionId()) //
.creditBureauId(command.getCreditBureauId()) //
.organisationCreditBureauId(command.getOrganisationCreditBureauId()) //
+ .clientIp(ClientIpHolder.getClientIp()) //
Review Comment:
That's where it stores and saves the value of the IP.
What should we do in that case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2212696773
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
Thank you for the detailed comments, but please make sure you are split them into separate lines and please drop the `//`.
Example:
```
X-Forwarded-For: Standard header used by proxies,
Proxy-Client-IP: Used by some Apache proxies,
...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193430787
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+@ConditionalOnProperty("fineract.geolocation.enabled")
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.debug("Found Client IP in header : {}", clientIpAddress);
+ ClientIpHolder.setClientIp(clientIpAddress);
+ }
+ filterChain.doFilter(request, response);
+ } catch (Exception e) {
Review Comment:
This try - catch is way too broad! You should move the `filterChain.doFilter(request, response)` call outside as this will catch and hide any exceptions that might come from any other filters!
Do we need the catch for anything? I think it should be removed all together!
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+@ConditionalOnProperty("fineract.geolocation.enabled")
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.debug("Found Client IP in header : {}", clientIpAddress);
+ ClientIpHolder.setClientIp(clientIpAddress);
+ }
+ filterChain.doFilter(request, response);
+ } catch (Exception e) {
Review Comment:
This try - catch is way too broad! You should move the `filterChain.doFilter(request, response)` call outside as this will catch and hide any exceptions that might come from any other filters!
Do we need the catch case for anything? I think it should be removed all together!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314 - IP Tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2191894462
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
@JohnAlva Can you please advise on this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193581852
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
@JohnAlva These articules only talks about "X-Forwarded-For"... what about the rest of them???
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180493446
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.geolocation.enabled=${FINERACT_GEOLOCATION_ENABLED:true}
Review Comment:
I dont think we should enabled this by default... but i can be convinced...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180479671
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.info("Found Client IP in header : {}", clientIpAddress);
+ ClientIpHolder.setClientIp(clientIpAddress);
+ }
+ filterChain.doFilter(request, response);
+ } catch (Exception e) {
+ e.printStackTrace();
Review Comment:
Please have correct error handling! "e.printStackTrace" is incorrect and easily hide exceptions that propagate from other filters!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "04Gomez (via GitHub)" <gi...@apache.org>.
04Gomez commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2201435794
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/ClientIpHolder.java:
##########
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+public final class ClientIpHolder {
Review Comment:
@galovics
Hi, can you help us with an example of how it can be done?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "04Gomez (via GitHub)" <gi...@apache.org>.
04Gomez commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2202063164
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/ClientIpHolder.java:
##########
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+public final class ClientIpHolder {
Review Comment:
Hi, @galovics
Done, we have eliminated that action leaving it with a single thread.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198803725
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2259529962
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java:
##########
@@ -597,4 +599,15 @@ public void checkForUnsupportedParameters(final Type typeOfMap, final String jso
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, requestDataParameters);
}
+ public String getClientIp() {
+ ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ String clientIp = "";
+ if (attrs != null) {
+ Object ipAttr = attrs.getRequest().getAttribute("IP");
+ if (ipAttr != null) {
+ clientIp = ipAttr.toString();
+ }
+ }
+ return clientIp;
Review Comment:
@Shelaslifter Fetching data from `RequestContextHolder.getRequestAttributes()` has nothing to do with JsonCommand class. Please Move this while logic into a utility class as @galovics recommended.
We should not mix business logics together...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3097630873
> Hi @adamsaghy, Is there an existing example of the test you’re referring to? It would help us a lot. Thanks!
I will be on leave for the rest of the week, but example for integration test: AuditIntegrationTest (i believe this is fetching the content of the `m_portfolio_command_source` table.
Also for E2E test, we might not yet created any AUDIT related one, but you can take a look at any of them and see how it works...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2214078118
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java:
##########
@@ -115,6 +116,9 @@ public class SecurityConfig {
@Autowired
private IdempotencyStoreHelper idempotencyStoreHelper;
+ @Autowired(required = false)
+ private GeolocationHeaderFilter geolocationHeaderFilter;
Review Comment:
Good point — renamed to CallerIpTrackingFilter for clarity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2192963703
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
Review Comment:
Thanks, I've changed it to 'CALLER IP'.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193538775
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.info("Found Client IP in header : {}", clientIpAddress);
+ ClientIpHolder.setClientIp(clientIpAddress);
Review Comment:
In a typical multi-threaded server application (e.g., Spring Boot app), each HTTP request is handled by a thread (possibly from a thread pool). If you want to track the client IP address throughout the processing of that request (e.g., across multiple service layers), storing it in a ThreadLocal variable allows you to:
Access the IP anywhere in the call stack without passing it as a parameter.
Keep data isolated per request/thread.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193557323
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
We have used the IP headers precedence based on these documents:
https://www.rfc-editor.org/rfc/rfc7239.txt
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2192991858
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.geolocation.enabled=${FINERACT_GEOLOCATION_ENABLED:true}
Review Comment:
We've set it to false instead, as it seems more appropriate for this case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180491479
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
Review Comment:
You can make it a conditional Spring bean which only registers if it was enabled:
`@ConditionalOnProperty("fineract.geolocation.enabled")`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180481064
##########
fineract-provider/src/main/java/org/apache/fineract/commands/service/AuditReadPlatformServiceImpl.java:
##########
@@ -158,13 +159,14 @@ public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final in
final String clientName = rs.getString("clientName");
final String loanAccountNo = rs.getString("loanAccountNo");
final String savingsAccountNo = rs.getString("savingsAccountNo");
+ final String ip = (rs.getString("ip") != null) ? rs.getString("ip") : "SN/IP";
Review Comment:
what does "SN/IP" means?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "04Gomez (via GitHub)" <gi...@apache.org>.
04Gomez commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2201455777
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.geolocation.enabled=${FINERACT_GEOLOCATION_ENABLED:false}
Review Comment:
@galovics
The necessary modifications have already been made, leaving it as Client IP Tracking
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3081544760
@galovics Hey, could you help us review the commit and let us know if you have any comments?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2261874622
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java:
##########
@@ -597,4 +599,15 @@ public void checkForUnsupportedParameters(final Type typeOfMap, final String jso
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, requestDataParameters);
}
+ public String getClientIp() {
+ ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ String clientIp = "";
+ if (attrs != null) {
+ Object ipAttr = attrs.getRequest().getAttribute("IP");
+ if (ipAttr != null) {
+ clientIp = ipAttr.toString();
+ }
+ }
+ return clientIp;
Review Comment:
@adamsaghy hi, the IpAddressUtils.java class was created, and the JsonCommand was removed from the class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180474884
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
How was the priority order of the IP header candidates decided?
Is there a specific reason for the ordering, or is it based on best practice or precedent?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3155846986
@galovics Hi, could you please help us review the commit and share any feedback or comments you may have? Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "galovics (via GitHub)" <gi...@apache.org>.
galovics commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2240800301
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java:
##########
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.fineract.integrationtests.common.AuditHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class IpTrackingIntegrationTest {
+
+ private AuditHelper auditHelper;
+ private static final String EXPECTED_LOCAL_IP = "127.0.0.1";
+ private RequestSpecification requestSpec;
+ private ResponseSpecification responseSpec;
+ private ResponseSpecification responseSpecForSearch;
+
+ @BeforeEach
+ public void setup() {
+ Utils.initializeRESTAssured();
+ this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+ this.requestSpec.header("Fineract-Platform-TenantId", "default");
+ this.requestSpec.auth().basic("mifos", "password");
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.responseSpecForSearch = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.auditHelper = new AuditHelper(this.requestSpec, this.responseSpec);
+ }
+
+ @Test
+ public void capturesIpAddressWhenCreatingClient() throws Exception {
+ List<HashMap<String, Object>> auditsRecieved;
+
+ // given
+ final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
+ ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
+ auditsRecieved = auditHelper.getAuditDetails(clientId, "CREATE", "CLIENT");
+
+ // when
+ String ip = auditsRecieved.get(0).get("ip").toString();
+
+ // then
+ if (!ip.isEmpty()) {
+ assertEquals(EXPECTED_LOCAL_IP, ip);
+ } else {
+ assertEquals("", ip);
+ }
Review Comment:
How can there be an IF in the assertion? This seems to be wrong.
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.client-ip-tracking.enabled"=${FINERACT_CLIENT-IP-TRACKING_ENABLED:false}
Review Comment:
Use underscores in the env var name.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java:
##########
@@ -597,4 +599,15 @@ public void checkForUnsupportedParameters(final Type typeOfMap, final String jso
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, requestDataParameters);
}
+ public String getClientIp() {
+ ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ String clientIp = "";
+ if (attrs != null) {
+ Object ipAttr = attrs.getRequest().getAttribute("IP");
+ if (ipAttr != null) {
+ clientIp = ipAttr.toString();
+ }
+ }
+ return clientIp;
Review Comment:
I meant the utility method here.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/CallerIpTrackingFilter.java:
##########
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty("fineract.client-ip-tracking.enabled")
+@RequiredArgsConstructor
+@Slf4j
+public class CallerIpTrackingFilter extends OncePerRequestFilter {
Review Comment:
I don't get the whole filter approach.
If this is truly just extracting the IP info from the servlet request, why don't you simply create a utility method for it in a utility class and use it when needed? Why do you change the attributes of the request?
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java:
##########
@@ -50,6 +50,8 @@ public class FineractProperties {
private FineractCorrelationProperties correlation;
+ private FineractGeolocationProperties geolocation;
Review Comment:
You changed the property name, it's not geolocation anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2243268343
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/CallerIpTrackingFilter.java:
##########
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty("fineract.client-ip-tracking.enabled")
+@RequiredArgsConstructor
+@Slf4j
+public class CallerIpTrackingFilter extends OncePerRequestFilter {
Review Comment:
It was implemented as a filter because it is considered an optional value. This allows the system user to decide whether or not they want to capture the IP address.
If it were implemented as a Utils class, the IP capture would be executed automatically at all times, without the possibility of skipping it.
Additionally, we believe it is not necessary to create an additional class solely for this purpose, as it would require more development effort for a functionality that can remain optional more easily through a filter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2259543477
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
+fineract.security.two-factor.enabled=false
Review Comment:
I think we should raise an another PR to resolve this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2192998140
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java:
##########
@@ -165,7 +166,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.addFilterBefore(tenantAwareBasicAuthenticationFilter(), SecurityContextHolderFilter.class) //
.addFilterAfter(requestResponseFilter(), ExceptionTranslationFilter.class) //
.addFilterAfter(correlationHeaderFilter(), RequestResponseFilter.class) //
- .addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class); //
+ .addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class) //
+ .addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class) //
+ .addFilterAfter(geolocationHeaderFilter(), RequestResponseFilter.class); //
Review Comment:
We've added a function to handle the filters when they are disabled. Specifically, we implemented this for the geolocation filter, as it was not previously disabled, and we have now included this functionality.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193431936
##########
fineract-provider/src/main/java/org/apache/fineract/commands/service/AuditReadPlatformServiceImpl.java:
##########
@@ -158,13 +159,14 @@ public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final in
final String clientName = rs.getString("clientName");
final String loanAccountNo = rs.getString("loanAccountNo");
final String savingsAccountNo = rs.getString("savingsAccountNo");
+ final String ip = (rs.getString("ip") != null) ? rs.getString("ip") : "No IP assigned";
Review Comment:
Keep it NULL instead please!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314 - IP Tracking [fineract]
Posted by "Tedyyy-Albur (via GitHub)" <gi...@apache.org>.
Tedyyy-Albur commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3033721488
@adamsaghy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2214090882
##########
fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java:
##########
@@ -224,4 +230,15 @@ public void updateForAudit(final CommandProcessingResult result) {
this.subResourceExternalId = result.getSubResourceExternalId();
this.loanExternalId = result.getLoanExternalId();
}
+
+ private static String getClientIp() {
Review Comment:
I’ve moved the getClientIp() logic out of the JPA entity and placed it inside the JsonCommand class. Let me know if any other changes are needed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2212691119
##########
fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java:
##########
@@ -224,4 +230,15 @@ public void updateForAudit(final CommandProcessingResult result) {
this.subResourceExternalId = result.getSubResourceExternalId();
this.loanExternalId = result.getLoanExternalId();
}
+
+ private static String getClientIp() {
Review Comment:
Please move this logic outside of the JPA entity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193907341
##########
fineract-provider/src/main/java/org/apache/fineract/commands/service/AuditReadPlatformServiceImpl.java:
##########
@@ -158,13 +159,14 @@ public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final in
final String clientName = rs.getString("clientName");
final String loanAccountNo = rs.getString("loanAccountNo");
final String savingsAccountNo = rs.getString("savingsAccountNo");
+ final String ip = (rs.getString("ip") != null) ? rs.getString("ip") : "No IP assigned";
Review Comment:
Removed the fallback value—ip now stays null when the column is null.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198773466
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
Review Comment:
The "static" keyword was removed and changed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "04Gomez (via GitHub)" <gi...@apache.org>.
04Gomez commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2201435794
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/ClientIpHolder.java:
##########
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+public final class ClientIpHolder {
Review Comment:
@galovics
Hi, can you help us with an example of how it can be done?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "04Gomez (via GitHub)" <gi...@apache.org>.
04Gomez commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3075730667
@galovics Hi, can you help us Review the commit?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314 - IP Tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3037013865
@adamsaghy Hi Adam
we already fixed the conflict,
could you help us to review please?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2259540922
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
+fineract.security.two-factor.enabled=false
Review Comment:
@JohnAlva Seems there is a bug here as we have `fineract.security.2fa.enabled=false` but not have `fineract.security.two-factor.enabled`, but in Fineract properties the field name is `twoFactor`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2258401417
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
Apologies for the delayed response, the change has already been made.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2258394669
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java:
##########
@@ -597,4 +599,15 @@ public void checkForUnsupportedParameters(final Type typeOfMap, final String jso
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, requestDataParameters);
}
+ public String getClientIp() {
+ ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ String clientIp = "";
+ if (attrs != null) {
+ Object ipAttr = attrs.getRequest().getAttribute("IP");
+ if (ipAttr != null) {
+ clientIp = ipAttr.toString();
+ }
+ }
+ return clientIp;
Review Comment:
It was implemented as a filter because it is considered an optional value. This allows the system user to decide whether or not they want to capture the IP address.
If it were implemented as a Utils class, the IP capture would be executed automatically at all times, without the possibility of skipping it.
Additionally, we believe it is not necessary to create an additional class solely for this purpose, as it would require more development effort for a functionality that can remain optional more easily through a filter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2254803479
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java:
##########
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.fineract.integrationtests.common.AuditHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class IpTrackingIntegrationTest {
+
+ private AuditHelper auditHelper;
+ private static final String EXPECTED_LOCAL_IP = "127.0.0.1";
+ private RequestSpecification requestSpec;
+ private ResponseSpecification responseSpec;
+ private ResponseSpecification responseSpecForSearch;
+
+ @BeforeEach
+ public void setup() {
+ Utils.initializeRESTAssured();
+ this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+ this.requestSpec.header("Fineract-Platform-TenantId", "default");
+ this.requestSpec.auth().basic("mifos", "password");
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.responseSpecForSearch = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.auditHelper = new AuditHelper(this.requestSpec, this.responseSpec);
+ }
+
+ @Test
+ public void capturesIpAddressWhenCreatingClient() throws Exception {
+ List<HashMap<String, Object>> auditsRecieved;
+
+ // given
+ final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
+ ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
+ auditsRecieved = auditHelper.getAuditDetails(clientId, "CREATE", "CLIENT");
+
+ // when
+ String ip = auditsRecieved.get(0).get("ip").toString();
+
+ // then
+ if (!ip.isEmpty()) {
+ assertEquals(EXPECTED_LOCAL_IP, ip);
+ } else {
+ assertEquals("", ip);
+ }
Review Comment:
I have already made the correction by removing the if inside the assertion, as you suggested. Now the assertion is directly performed after verifying that the IP is not empty.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2259548471
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java:
##########
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.fineract.integrationtests.common.AuditHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class IpTrackingIntegrationTest {
Review Comment:
Would you mind to write a negative test case, where functionality is not enabled, so there will be no IP fetched and stored?
Also Please make sure, all of the IP header options are tested one by one... ;)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3028465238
@JohnAlva Please rebase your PR and make sure you run the spotlessApply and checkstyle on the PR before it got committed:
`./gradlew spotlessApply spotbugsMain spotbugsTest checkstyleMain checkstyleTest`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180477627
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.info("Found Client IP in header : {}", clientIpAddress);
+ ClientIpHolder.setClientIp(clientIpAddress);
Review Comment:
Is there a reason to store in thread local the ip address?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180475582
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
Review Comment:
"SEND IP" you mean "CALLER IP"?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193911505
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java:
##########
@@ -227,6 +230,10 @@ public TenantAwareBasicAuthenticationFilter tenantAwareBasicAuthenticationFilter
return filter;
}
+ public GeolocationHeaderFilter geolocationHeaderFilter() {
+ return new GeolocationHeaderFilter(fineractProperties);
Review Comment:
Replaced manual creation with lazy autowiring using @Autowired(required = false). The filter is now only added if the bean is present.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193897547
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
Review Comment:
Converted to Spring bean (@Component) and conditional on enabled=false. No manual instantiation anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2212704240
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java:
##########
@@ -115,6 +116,9 @@ public class SecurityConfig {
@Autowired
private IdempotencyStoreHelper idempotencyStoreHelper;
+ @Autowired(required = false)
+ private GeolocationHeaderFilter geolocationHeaderFilter;
Review Comment:
Would `CallerIpTrackingFilter` naming make more sense here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193427824
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
Review Comment:
`@ConditionalOnProperty("fineract.geolocation.enabled")` only works if this class is a Sprint Bean (which is not at the moment).
Please make sure `GeolocationHeaderFilter` is a Spring Bean and new instance is not created manually:
No `new GeolocationHeaderFilter()` anywhere!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3071088992
Hi, @galovics, Do you have any comments to add?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2205862066
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
Done, comments added as requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2258399982
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java:
##########
@@ -597,4 +599,15 @@ public void checkForUnsupportedParameters(final Type typeOfMap, final String jso
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, requestDataParameters);
}
+ public String getClientIp() {
+ ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ String clientIp = "";
+ if (attrs != null) {
+ Object ipAttr = attrs.getRequest().getAttribute("IP");
+ if (ipAttr != null) {
+ clientIp = ipAttr.toString();
+ }
+ }
+ return clientIp;
Review Comment:
As mentioned, the filter keeps IP tracking optional. Using a utility class would make capture automatic, with no option to skip. Creating a separate class for this would add unnecessary overhead, as the filter already fulfills the required functionality.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3090068611
> @adamsaghy Just checking—do you need any input on the test scenarios or coverage, or are you all set?
I am not sure what you mean... 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2241299683
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.client-ip-tracking.enabled"=${FINERACT_CLIENT-IP-TRACKING_ENABLED:false}
Review Comment:
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2201381553
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
+fineract.security.two-factor.enabled=false
Review Comment:
For the two-factor.enabled and geoLocation.enabled properties:
These were explicitly added to the application-test.properties file because certain tests were failing when the values were not defined.
Although the default fallback is false, the tests seem to require these values to be explicitly set to avoid unexpected behavior.
Let me know if you'd prefer a different approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314 - IP Tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3046294257
@adamsaghy Hello, Can you help us review again, and about the change of tests we don't work on those.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314 - IP Tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3047968727
@JohnAlva Please use the correct PR title and commit message naming convention:
`FINERACT-2314 - IP Tracking` -> `FINERACT-2314: IP tracking`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193000739
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
Review Comment:
We've added the conditional Spring bean as requested. It's now correctly registered with @ConditionalOnProperty("fineract.geolocation.enabled")
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3028179943
@JohnAlva @IOhacker Would you mind to provide some description for this PR? The FINERACT story is empty :(
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314 - IP Tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3035963617
> @adamsaghy
@Tedyyy-Albur ???
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180493446
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.geolocation.enabled=${FINERACT_GEOLOCATION_ENABLED:true}
Review Comment:
I dont think we should enabled this by default...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3053305757
@adamsaghy Do you have any model/reference/template for creating the test class?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193433578
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java:
##########
@@ -227,6 +230,10 @@ public TenantAwareBasicAuthenticationFilter tenantAwareBasicAuthenticationFilter
return filter;
}
+ public GeolocationHeaderFilter geolocationHeaderFilter() {
+ return new GeolocationHeaderFilter(fineractProperties);
Review Comment:
Dont create it manually. Autowire this lazily instead!
```
@Autowired(required = false)`
private GeolocationHeaderFilter geolocationHeaderFilter;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2192964653
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.info("Found Client IP in header : {}", clientIpAddress);
Review Comment:
Thanks, I've changed the log level to DEBUG.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193905779
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+@ConditionalOnProperty("fineract.geolocation.enabled")
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.debug("Found Client IP in header : {}", clientIpAddress);
+ ClientIpHolder.setClientIp(clientIpAddress);
+ }
+ filterChain.doFilter(request, response);
+ } catch (Exception e) {
Review Comment:
Thanks for the heads-up! I removed the broad catch—now filterChain.doFilter() is only inside a try {…} finally to guarantee ClientIpHolder.clear(), and any exceptions propagate normally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "galovics (via GitHub)" <gi...@apache.org>.
galovics commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2196829655
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
Review Comment:
Shouldn't be static.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
Review Comment:
During development we run fineract in debug mode. This will spam the logs for sure. I'd change this to trace level.
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.geolocation.enabled=${FINERACT_GEOLOCATION_ENABLED:false}
Review Comment:
This is not geolocation. I'm not even sure why we are calling it "geolocation" something.
It's simply client ip tracking, nothing else.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.debug("Found Client IP in header : {}", clientIpAddress);
Review Comment:
Trace level.
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
Review Comment:
Why is this needed? by default the application.properties falls back to a false value.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
Review Comment:
"unknown"? I'd rather not hardcode this unless we have a good reason to.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
Review Comment:
I'd rather not use the string version of this but use the typed version. We have many "XYZCondition" classes.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
Review Comment:
I don't really get this check. Isn't the conditional on the bean handles this?
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
Review Comment:
Same, trace level.
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/ClientIpHolder.java:
##########
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+public final class ClientIpHolder {
Review Comment:
I suggest not doing it this way. One more threadlocal is just an extra we don't need. Why can't we get the IP simply where we are saving the command?
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
Review Comment:
big no. This must be explained one by one why a specific header is used. Please put the comments in the code so everybody understands the purpose.
##########
fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java:
##########
@@ -162,6 +166,7 @@ public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final Js
.transactionId(command.getTransactionId()) //
.creditBureauId(command.getCreditBureauId()) //
.organisationCreditBureauId(command.getOrganisationCreditBureauId()) //
+ .clientIp(ClientIpHolder.getClientIp()) //
Review Comment:
Woah, this is really not good.
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
+fineract.security.two-factor.enabled=false
Review Comment:
why the two-factor.enabled change?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198782859
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
Review Comment:
The code was updated to avoid the "unknown" value and an `isEmpty()` was added to handle any empty value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2241299388
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java:
##########
@@ -50,6 +50,8 @@ public class FineractProperties {
private FineractCorrelationProperties correlation;
+ private FineractGeolocationProperties geolocation;
Review Comment:
Done, I have changed the name to ipTracking.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3160787126
@galovics Hey, would you mind reviewing the commit and providing any feedback or thoughts you might have? Appreciate it!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3090747605
Hi @adamsaghy,
Is there an existing example of the test you’re referring to? It would help us a lot. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2193006169
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.info("Found Client IP in header : {}", clientIpAddress);
+ ClientIpHolder.setClientIp(clientIpAddress);
+ }
+ filterChain.doFilter(request, response);
+ } catch (Exception e) {
+ e.printStackTrace();
Review Comment:
We've implemented the correct error handling as requested. Instead of e.printStackTrace(), we've ensured that the exception is properly logged, and any exceptions are now handled in a way that doesn't hide issues from other filters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3089976106
@adamsaghy Just checking—do you need any input on the test scenarios or coverage, or are you all set?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2259543477
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
+fineract.security.two-factor.enabled=false
Review Comment:
I think we should raise an another PR to resolve this.
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
+fineract.security.two-factor.enabled=false
Review Comment:
@JohnAlva Seems there is a bug here as we have `fineract.security.2fa.enabled=false` but not have `fineract.security.two-factor.enabled`, but in Fineract properties the field name is `twoFactor`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2259567950
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
+fineract.security.two-factor.enabled=false
Review Comment:
@JohnAlva It's provided via "2fa", and so far those tests were running just fine.. PLease remove the `fineract.security.two-factor.enabled=false`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2261881427
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java:
##########
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.fineract.integrationtests.common.AuditHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class IpTrackingIntegrationTest {
Review Comment:
The one for the headers was already added, and the functionality was moved to IpAddressUtils.java.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180476789
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("SEND IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
+ if (geolocationProperties.isEnabled()) {
+ handleClientIp(request, response, filterChain, geolocationProperties);
+ } else {
+ filterChain.doFilter(request, response);
+ }
+
+ }
+
+ private void handleClientIp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain,
+ FineractProperties.FineractGeolocationProperties geolocationProperties) throws IOException, ServletException {
+ try {
+ String clientIpAddress = getClientIpAddress(request);
+ if (StringUtils.isNotBlank(clientIpAddress)) {
+ log.info("Found Client IP in header : {}", clientIpAddress);
Review Comment:
Please change the log level to DEBUG
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180492880
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java:
##########
@@ -165,7 +166,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.addFilterBefore(tenantAwareBasicAuthenticationFilter(), SecurityContextHolderFilter.class) //
.addFilterAfter(requestResponseFilter(), ExceptionTranslationFilter.class) //
.addFilterAfter(correlationHeaderFilter(), RequestResponseFilter.class) //
- .addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class); //
+ .addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class) //
+ .addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class) //
+ .addFilterAfter(geolocationHeaderFilter(), RequestResponseFilter.class); //
Review Comment:
You can decide to not register this filter if the functionality is disabled... See example: `loanCOBFilterHelper`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: Geolocation tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2180493446
##########
fineract-provider/src/main/resources/application.properties:
##########
@@ -62,6 +62,7 @@ fineract.correlation.enabled=${FINERACT_LOGGING_HTTP_CORRELATION_ID_ENABLED:fals
fineract.correlation.header-name=${FINERACT_LOGGING_HTTP_CORRELATION_ID_HEADER_NAME:X-Correlation-ID}
fineract.job.stuck-retry-threshold=${FINERACT_JOB_STUCK_RETRY_THRESHOLD:5}
+fineract.geolocation.enabled=${FINERACT_GEOLOCATION_ENABLED:true}
Review Comment:
I dont think we should enabled this by default... but i can be convinced...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314 - IP Tracking [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3037184793
@JohnAlva the PR in conflicted state. the tests are failed and there are great many open questions on it!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2192970822
##########
fineract-provider/src/main/java/org/apache/fineract/commands/service/AuditReadPlatformServiceImpl.java:
##########
@@ -158,13 +159,14 @@ public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final in
final String clientName = rs.getString("clientName");
final String loanAccountNo = rs.getString("loanAccountNo");
final String savingsAccountNo = rs.getString("savingsAccountNo");
+ final String ip = (rs.getString("ip") != null) ? rs.getString("ip") : "SN/IP";
Review Comment:
I've changed it to 'NO IP' for better understanding
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "04Gomez (via GitHub)" <gi...@apache.org>.
04Gomez commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2201440356
##########
fineract-provider/src/test/resources/application-test.properties:
##########
@@ -20,6 +20,8 @@
fineract.node-id=1
fineract.security.basicauth.enabled=true
+fineract.geolocation.enabled=false
Review Comment:
@galovics
If we remove this, during the test execution it fails because it gets it as a null value, so, in addition, false is added to complete the test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "Shelaslifter (via GitHub)" <gi...@apache.org>.
Shelaslifter commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198885295
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
Review Comment:
Done, we have made the change as you requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on code in PR #4825:
URL: https://github.com/apache/fineract/pull/4825#discussion_r2198949915
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/filters/GeolocationHeaderFilter.java:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.infrastructure.core.filters;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.fineract.infrastructure.core.config.FineractProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+@Component
+@ConditionalOnProperty(prefix = "fineract.geolocation", name = "enabled", havingValue = "false", matchIfMissing = false)
+@RequiredArgsConstructor
+@Slf4j
+public class GeolocationHeaderFilter extends OncePerRequestFilter {
+
+ private final FineractProperties fineractProperties;
+
+ private static final String[] IP_HEADER_CANDIDATES = { "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP",
+ "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", "HTTP_FORWARDED_FOR",
+ "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR" };
+
+ public static String getClientIpAddress(HttpServletRequest request) {
+ for (String header : IP_HEADER_CANDIDATES) {
+ String ip = request.getHeader(header);
+ if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
+ log.debug("CALLER IP : {}", ip);
+ return ip;
+ }
+ }
+ log.debug("getRemoteAddr method : {}", request.getRemoteAddr());
+ return request.getRemoteAddr();
+ }
+
+ @Override
+ protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
+ throws IOException, ServletException {
+ FineractProperties.FineractGeolocationProperties geolocationProperties = fineractProperties.getGeolocation();
Review Comment:
You're right — since the bean is already conditionally loaded with @ConditionalOnProperty, the internal check was redundant. I've removed it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2314: IP tracking [fineract]
Posted by "JohnAlva (via GitHub)" <gi...@apache.org>.
JohnAlva commented on PR #4825:
URL: https://github.com/apache/fineract/pull/4825#issuecomment-3053822839
@adamsaghy Do you have any comments or feedback?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org