Browse Source
Merge pull request #14953 from dskarzh/fix/rest-authentication-client-ip
fix: respect forward_headers_strategy for client IP in audit logs
pull/14994/head
Viacheslav Klimov
6 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
1 additions and
9 deletions
-
application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationDetails.java
|
|
@ -29,18 +29,10 @@ public class RestAuthenticationDetails implements Serializable { |
|
|
private final Client userAgent; |
|
|
private final Client userAgent; |
|
|
|
|
|
|
|
|
public RestAuthenticationDetails(HttpServletRequest request) { |
|
|
public RestAuthenticationDetails(HttpServletRequest request) { |
|
|
this.clientAddress = getClientIP(request); |
|
|
this.clientAddress = request.getRemoteAddr(); |
|
|
this.userAgent = getUserAgent(request); |
|
|
this.userAgent = getUserAgent(request); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static String getClientIP(HttpServletRequest request) { |
|
|
|
|
|
String xfHeader = request.getHeader("X-Forwarded-For"); |
|
|
|
|
|
if (xfHeader == null) { |
|
|
|
|
|
return request.getRemoteAddr(); |
|
|
|
|
|
} |
|
|
|
|
|
return xfHeader.split(",")[0]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Client getUserAgent(HttpServletRequest request) { |
|
|
private static Client getUserAgent(HttpServletRequest request) { |
|
|
Parser uaParser = new Parser(); |
|
|
Parser uaParser = new Parser(); |
|
|
return uaParser.parse(request.getHeader("User-Agent")); |
|
|
return uaParser.parse(request.getHeader("User-Agent")); |
|
|
|