From 93b727c223840a6f108b9bd7edb4c199815d06a5 Mon Sep 17 00:00:00 2001 From: Ravi Shanigarapu Date: Mon, 27 Jan 2025 16:41:07 +0530 Subject: [PATCH 1/6] Grievance runtime issues --- src/main/environment/common_test.properties | 2 +- .../com/iemr/common/repository/grievance/GrievanceDataRepo.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties index 41cb9b70..37c898e2 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -13,7 +13,7 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver secondary.datasource.username= secondary.datasource.password= secondary.datasource.url= -secondary.datasource.driver-class-name=com.mysql.jdbc.Drive +secondary.datasource.driver-class-name=com.mysql.jdbc.Driver encDbUserName=zFlYsp9Z0s+lRvLM15A3g/Ba0w8VGs/1usuW7EsGF3k= encDbPass=JGGAGn5wTlrbTLUHY+5BzfBa0w8VGs/1usuW7EsGF3k= diff --git a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java index 40a1b6f4..b874dac4 100644 --- a/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java +++ b/src/main/java/com/iemr/common/repository/grievance/GrievanceDataRepo.java @@ -33,7 +33,7 @@ List findGrievancesInDateRangeAndLanguage( @Modifying - @Query("UPDATE GrievanceDetails g SET g.isAllocated = true, g.userid = :userId WHERE g.grievanceid = :grievanceId") + @Query("UPDATE GrievanceDetails g SET g.isAllocated = true, g.userid = :userId WHERE g.grievanceId = :grievanceId") @Transactional public int allocateGrievance(@Param("grievanceId") Long grievanceId, @Param("userId") Integer userId); From 5e02c35183514a69ca5905eb0e881671c872f7e9 Mon Sep 17 00:00:00 2001 From: Ravi Shanigarapu Date: Mon, 27 Jan 2025 18:08:00 +0530 Subject: [PATCH 2/6] Dissable swagger in prod environment --- src/main/environment/common_ci.properties | 3 +++ src/main/environment/common_dev.properties | 3 +++ src/main/environment/common_example.properties | 3 +++ src/main/environment/common_test.properties | 3 +++ src/main/environment/common_uat.properties | 3 +++ .../com/iemr/common/utils/http/HTTPRequestInterceptor.java | 6 ++++++ 6 files changed, 21 insertions(+) diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index 86cc945c..78b8c590 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -152,3 +152,6 @@ grievanceUserName = @env.GRIEVANCE_USERNAME@ grievancePassword = @env.GRIEVANCE_PASSWORD@ grievanceUserAuthenticate = @env.GRIEVANCE_USER_AUTHENTICATE@ grievanceDataSyncDuration = @env.GRIEVANCE_DATA_SYNC_DURATION@ + +springdoc.api-docs.enabled=false +springdoc.swagger-ui.enabled=false \ No newline at end of file diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties index 0ee3e6cd..018a1244 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -181,3 +181,6 @@ grievancePassword = grievanceUserAuthenticate = grievanceDataSyncDuration = + +springdoc.api-docs.enabled=true +springdoc.swagger-ui.enabled=true \ No newline at end of file diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index 1f1e272b..7eb75168 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -125,3 +125,6 @@ grievancePassword = grievanceUserAuthenticate = grievanceDataSyncDuration = + +springdoc.api-docs.enabled=true +springdoc.swagger-ui.enabled=true \ No newline at end of file diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties index 37c898e2..b95d4495 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -182,3 +182,6 @@ grievancePassword = grievanceUserAuthenticate = grievanceDataSyncDuration = + +springdoc.api-docs.enabled=true +springdoc.swagger-ui.enabled=true \ No newline at end of file diff --git a/src/main/environment/common_uat.properties b/src/main/environment/common_uat.properties index bb8b53de..c90d7d5a 100644 --- a/src/main/environment/common_uat.properties +++ b/src/main/environment/common_uat.properties @@ -154,3 +154,6 @@ grievancePassword = grievanceUserAuthenticate = grievanceDataSyncDuration = + +springdoc.api-docs.enabled=true +springdoc.swagger-ui.enabled=true \ No newline at end of file diff --git a/src/main/java/com/iemr/common/utils/http/HTTPRequestInterceptor.java b/src/main/java/com/iemr/common/utils/http/HTTPRequestInterceptor.java index 7038cdb7..a31b2a2b 100644 --- a/src/main/java/com/iemr/common/utils/http/HTTPRequestInterceptor.java +++ b/src/main/java/com/iemr/common/utils/http/HTTPRequestInterceptor.java @@ -88,9 +88,15 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons case "userLogout": case "swagger-ui.html": case "index.html": + case "index.css": case "swagger-initializer.js": case "swagger-config": + case "swagger-ui-bundle.js": + case "swagger-ui.css": case "ui": + case "swagger-ui-standalone-preset.js": + case "favicon-32x32.png": + case "favicon-16x16.png": case "swagger-resources": case "api-docs": case "updateBenCallIdsInPhoneBlock": From 465d68fd16b6e2c0e8cd5b0eba43d28dc27ec2aa Mon Sep 17 00:00:00 2001 From: Ravi Shanigarapu Date: Mon, 10 Feb 2025 18:43:44 +0530 Subject: [PATCH 3/6] Login Issue --- .../iemr/common/controller/users/IEMRAdminController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iemr/common/controller/users/IEMRAdminController.java b/src/main/java/com/iemr/common/controller/users/IEMRAdminController.java index 0c0aaac7..c05436e1 100644 --- a/src/main/java/com/iemr/common/controller/users/IEMRAdminController.java +++ b/src/main/java/com/iemr/common/controller/users/IEMRAdminController.java @@ -152,8 +152,9 @@ public String userAuthenticate( JSONObject serviceRoleMap = new JSONObject(); JSONArray serviceRoleList = new JSONArray(); JSONObject previlegeObj = new JSONObject(); - if (m_User.getUserName() != null && (m_User.getDoLogout() == null || m_User.getDoLogout() == false) - && (m_User.getWithCredentials() != null || m_User.getWithCredentials() == true)) { + if (m_User.getUserName() != null + && (m_User.getDoLogout() == null || !m_User.getDoLogout()) + && (m_User.getWithCredentials() != null && m_User.getWithCredentials())) { String tokenFromRedis = getConcurrentCheckSessionObjectAgainstUser( m_User.getUserName().trim().toLowerCase()); if (tokenFromRedis != null) { From effa7c90cf070bb8b9876c5e0ca80b17036690bb Mon Sep 17 00:00:00 2001 From: Ravi Shanigarapu Date: Fri, 21 Feb 2025 12:36:50 +0530 Subject: [PATCH 4/6] Cors issue --- .../com/iemr/common/utils/CookieUtil.java | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/iemr/common/utils/CookieUtil.java b/src/main/java/com/iemr/common/utils/CookieUtil.java index 7fb103f5..50d91f2d 100644 --- a/src/main/java/com/iemr/common/utils/CookieUtil.java +++ b/src/main/java/com/iemr/common/utils/CookieUtil.java @@ -25,15 +25,45 @@ public Optional getCookieValue(HttpServletRequest request, String cookie } public void addJwtTokenToCookie(String Jwttoken, HttpServletResponse response, HttpServletRequest request) { - // Create a new cookie with the JWT token - Cookie cookie = new Cookie("Jwttoken", Jwttoken); - cookie.setHttpOnly(true); // Prevent JavaScript access for security - cookie.setMaxAge(60 * 60 * 24); // 1 day expiration time - cookie.setPath("/"); // Make the cookie available for the entire application - if ("https".equalsIgnoreCase(request.getScheme())) { - cookie.setSecure(true); // Secure flag only on HTTPS - } - response.addCookie(cookie); // Add the cookie to the response + // Create a new cookie with the JWT token + Cookie cookie = new Cookie("Jwttoken", Jwttoken); + + // Make the cookie HttpOnly to prevent JavaScript access for security + cookie.setHttpOnly(true); + + // Set the Max-Age (expiry time) in seconds (1 day) + cookie.setMaxAge(60 * 60 * 24); // 1 day expiration + + // Set the path to "/" so the cookie is available across the entire application + cookie.setPath("/"); + + // Set the SameSite attribute for cross-site request handling (if needed) + String sameSite = "None"; // Allow cross-site cookies (can be 'Strict', 'Lax', or 'None') + if ("https".equalsIgnoreCase(request.getScheme())) { + // Set Secure flag for HTTPS connection and SameSite=None for cross-site support + cookie.setSecure(true); // Enable cookie only on HTTPS + } else { + cookie.setSecure(false); // No need for Secure flag on HTTP connections + } + + // Add the cookie to the response + response.addCookie(cookie); + + // Build the Set-Cookie header manually (to add SameSite attribute support) + StringBuilder cookieHeader = new StringBuilder(); + cookieHeader.append(cookie.getName()).append("=").append(cookie.getValue()) + .append("; Path=").append(cookie.getPath()) + .append("; Max-Age=").append(cookie.getMaxAge()) + .append("; HttpOnly"); + + // Add SameSite and Secure attributes manually if needed + cookieHeader.append("; SameSite=").append(sameSite); + if (cookie.getSecure()) { + cookieHeader.append("; Secure"); + } + + // Set the custom Set-Cookie header + response.addHeader("Set-Cookie", cookieHeader.toString()); } public String getJwtTokenFromCookie(HttpServletRequest request) { From dd1dd21d7dea4d9678cc41e9ff68d008e43a1ace Mon Sep 17 00:00:00 2001 From: Ravi Shanigarapu Date: Fri, 21 Feb 2025 16:04:23 +0530 Subject: [PATCH 5/6] SEtSEcure as true --- src/main/java/com/iemr/common/utils/CookieUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/common/utils/CookieUtil.java b/src/main/java/com/iemr/common/utils/CookieUtil.java index 50d91f2d..d075391d 100644 --- a/src/main/java/com/iemr/common/utils/CookieUtil.java +++ b/src/main/java/com/iemr/common/utils/CookieUtil.java @@ -43,7 +43,7 @@ public void addJwtTokenToCookie(String Jwttoken, HttpServletResponse response, H // Set Secure flag for HTTPS connection and SameSite=None for cross-site support cookie.setSecure(true); // Enable cookie only on HTTPS } else { - cookie.setSecure(false); // No need for Secure flag on HTTP connections + cookie.setSecure(true); // No need for Secure flag on HTTP connections } // Add the cookie to the response From d2ae95f6b631d73e4da6f73318007b74322ba155 Mon Sep 17 00:00:00 2001 From: Ravi Shanigarapu Date: Fri, 21 Feb 2025 16:42:52 +0530 Subject: [PATCH 6/6] removed unwanted code --- src/main/java/com/iemr/common/utils/CookieUtil.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/iemr/common/utils/CookieUtil.java b/src/main/java/com/iemr/common/utils/CookieUtil.java index d075391d..55fec9f5 100644 --- a/src/main/java/com/iemr/common/utils/CookieUtil.java +++ b/src/main/java/com/iemr/common/utils/CookieUtil.java @@ -39,13 +39,7 @@ public void addJwtTokenToCookie(String Jwttoken, HttpServletResponse response, H // Set the SameSite attribute for cross-site request handling (if needed) String sameSite = "None"; // Allow cross-site cookies (can be 'Strict', 'Lax', or 'None') - if ("https".equalsIgnoreCase(request.getScheme())) { - // Set Secure flag for HTTPS connection and SameSite=None for cross-site support - cookie.setSecure(true); // Enable cookie only on HTTPS - } else { - cookie.setSecure(true); // No need for Secure flag on HTTP connections - } - + cookie.setSecure(true); // Add the cookie to the response response.addCookie(cookie);