diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java index 1c8336f3c361b1eef5cd7a6e649984bb6e605c2e..53a4677e4efe06cb480f77aad903da2db8e5cbb3 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/AuthorizationFilter.java @@ -30,6 +30,8 @@ import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValida import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import jakarta.servlet.http.HttpServletRequest; import java.util.Arrays; @@ -51,6 +53,7 @@ public class AuthorizationFilter { private ICache<String, Groups> cache; public boolean hasAnyPermission(String... requiredRoles) { + requestInfoExt.checkHeaders(getRequest()); DpsHeaders dpsHeaders = requestInfoExt.getHeaders(); if (StringUtils.isBlank(dpsHeaders.getAuthorization())) throw new AppException(302, "Redirect", "No credentials sent on request."); @@ -59,8 +62,9 @@ public class AuthorizationFilter { requestInfoExt.assignPartitionIdIfNotInHeader(); } - String path = request.getServletPath(); - if ("GET".equals(request.getMethod()) && + HttpServletRequest request = getRequest(); + String path = request != null ? request.getServletPath() : ""; + if (request != null && "GET".equals(request.getMethod()) && (path.equals("/swagger-ui.html") || path.equals("/info"))) { return true; } @@ -112,4 +116,9 @@ public class AuthorizationFilter { requestInfoExt.setHeaders(dpsHeaders); return authorizationResponse; } + + private HttpServletRequest getRequest() { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + return attributes != null ? attributes.getRequest() : null; + } } diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/di/RequestInfoExt.java b/notification-core/src/main/java/org/opengroup/osdu/notification/di/RequestInfoExt.java index 3ae35d2ce14d02069624179f9d85961b714cd7a1..51bb18d27990484ebbbf313855d124b62a8c464b 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/di/RequestInfoExt.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/di/RequestInfoExt.java @@ -68,4 +68,14 @@ public class RequestInfoExt extends RequestInfo { headers.put(DpsHeaders.DATA_PARTITION_ID, tenant); } } + + public void checkHeaders(HttpServletRequest request) { + if (request != null) { + Map<String, String> headersFromRequest = Collections + .list(request.getHeaderNames()) + .stream() + .collect(Collectors.toMap(h -> h, request::getHeader)); + this.setHeaders(DpsHeaders.createFromMap(headersFromRequest)); + } + } }