Added user action log and versioning for communication.
This commit is contained in:
@@ -19,6 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.annotation.RequestScope;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -55,12 +57,26 @@ public class LoggingUtil {
|
||||
if (userActionRequest.getRequest() instanceof CachedBodyHttpServletRequest cachedRequest) {
|
||||
requestBody = cachedRequest.getCachedBodyAsString();
|
||||
}
|
||||
// Decode the raw URI to handle encoded placeholders like %7BcommentId%7D
|
||||
String rawUrl = userActionRequest.getRequest().getRequestURI();
|
||||
String decodedUrl = URLDecoder.decode(rawUrl, StandardCharsets.UTF_8);
|
||||
|
||||
// Append query parameters if they exist
|
||||
if (userActionRequest.getRequest().getQueryString() != null) {
|
||||
decodedUrl += "?" + userActionRequest.getRequest().getQueryString();
|
||||
}
|
||||
|
||||
// Use the decoded URL as-is (optional normalization step if needed)
|
||||
String normalizedUrl = normalizeUrl(decodedUrl);
|
||||
|
||||
// Set the normalized URL in the user action log
|
||||
userAction.setActionType(userActionRequest.getActionType().getValue());
|
||||
userAction.setUserId(userId);
|
||||
userAction.setActionContext(userActionRequest.getActionContext().getValue());
|
||||
userAction.setMethodType(userActionRequest.getRequest().getMethod());
|
||||
userAction.setHubId(userEntity.getHub().getId());
|
||||
userAction.setUrl(userActionRequest.getRequest().getRequestURI());
|
||||
// userAction.setUrl(userActionRequest.getRequest().getRequestURI());
|
||||
userAction.setUrl(normalizedUrl);
|
||||
userAction.setLoginAttemptId(loginAttemptId);
|
||||
userAction.setIpAddress(IpAddressUtils.getClientIp(userActionRequest.getRequest()));
|
||||
userAction.setRequestBody(requestBody);
|
||||
@@ -74,7 +90,18 @@ public class LoggingUtil {
|
||||
return userAction;
|
||||
}
|
||||
|
||||
// @Transactional
|
||||
private String normalizeUrl(String url) {
|
||||
|
||||
url = url.replaceAll("(?<!:)//+", "/");
|
||||
if (url.length() > 1 && url.endsWith("/")) {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
url = URLDecoder.decode(url, StandardCharsets.UTF_8);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
// @Transactional
|
||||
// public UserActionEntity updateUserAction(HttpServletResponse response, UserActionEntity userAction) {
|
||||
// try {
|
||||
// String requestBody = null;
|
||||
|
||||
Reference in New Issue
Block a user