Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@

package com.iemr.admin.controller.version;

import java.util.Map;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
Expand All @@ -46,14 +43,7 @@ public class VersionController {
private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

private static final String UNKNOWN_VALUE = "unknown";
private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

private static final String UNKNOWN_VALUE = "unknown";

@Operation(summary = "Get version information")
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, String>> versionInformation() {
Map<String, String> response = new LinkedHashMap<>();
@Operation(summary = "Get version information")
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, String>> versionInformation() {
Expand All @@ -65,34 +55,17 @@ public ResponseEntity<Map<String, String>> versionInformation() {
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
Properties gitProperties = loadGitProperties();
response.put("buildTimestamp", gitProperties.getProperty("git.build.time", UNKNOWN_VALUE));
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
} catch (Exception e) {
logger.error("Failed to load version information", e);
response.put("buildTimestamp", UNKNOWN_VALUE);
response.put("version", UNKNOWN_VALUE);
response.put("branch", UNKNOWN_VALUE);
response.put("commitHash", UNKNOWN_VALUE);
logger.error("Failed to load version information", e);
response.put("buildTimestamp", UNKNOWN_VALUE);
response.put("version", UNKNOWN_VALUE);
response.put("branch", UNKNOWN_VALUE);
response.put("commitHash", UNKNOWN_VALUE);
}
logger.info("version Controller End");
return ResponseEntity.ok(response);
return ResponseEntity.ok(response);
}

private Properties loadGitProperties() throws IOException {
Properties properties = new Properties();
try (InputStream input = getClass().getClassLoader()
.getResourceAsStream("git.properties")) {
if (input != null) {
properties.load(input);
private Properties loadGitProperties() throws IOException {
Properties properties = new Properties();
try (InputStream input = getClass().getClassLoader()
Expand All @@ -102,6 +75,5 @@ private Properties loadGitProperties() throws IOException {
}
}
return properties;
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class JwtUserIdValidationFilter implements Filter {
private static final String HEALTH_ENDPOINT = "/health";
private static final String VERSION_ENDPOINT = "/version";

private static final String HEALTH_ENDPOINT = "/health";
private static final String VERSION_ENDPOINT = "/version";

private final JwtAuthenticationUtil jwtAuthenticationUtil;
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
private final String allowedOrigins;
Expand Down Expand Up @@ -52,17 +49,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
return;
}

String path = request.getRequestURI();
String contextPath = request.getContextPath();

// FIRST: Check for health and version endpoints - skip ALL processing
if (path.equals(HEALTH_ENDPOINT) || path.equals(VERSION_ENDPOINT) ||
path.equals(contextPath + HEALTH_ENDPOINT) || path.equals(contextPath + VERSION_ENDPOINT)) {
logger.info("Skipping JWT validation for monitoring endpoint: {}", path);
filterChain.doFilter(servletRequest, servletResponse);
return;
}

String origin = request.getHeader("Origin");
String method = request.getMethod();
String uri = request.getRequestURI();
Expand Down Expand Up @@ -91,11 +77,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
return;
}
}

// Determine request path/context for later checks
String path = request.getRequestURI();
String contextPath = request.getContextPath();


// Set CORS headers and handle OPTIONS request only if origin is valid and allowed
if (origin != null && isOriginAllowed(origin)) {
addCorsHeaders(response, origin);
Expand Down Expand Up @@ -141,9 +123,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
|| path.startsWith(contextPath + "/user/refreshToken")
|| path.startsWith(contextPath + "/public")
|| path.equals(contextPath + HEALTH_ENDPOINT)
|| path.equals(contextPath + VERSION_ENDPOINT)) {
|| path.startsWith(contextPath + "/public")
|| path.equals(contextPath + HEALTH_ENDPOINT)
|| path.equals(contextPath + VERSION_ENDPOINT)) {
logger.info("Skipping filter for path: " + path);
filterChain.doFilter(servletRequest, servletResponse);
Expand Down
Loading