Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load static resources from default zone if zone not found #2828

Merged
merged 3 commits into from
Apr 16, 2024
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 @@ -12,6 +12,7 @@
*******************************************************************************/
package org.cloudfoundry.identity.uaa.zone;

import org.cloudfoundry.identity.uaa.util.UaaUrlUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
Expand All @@ -36,6 +37,7 @@
public class IdentityZoneResolvingFilter extends OncePerRequestFilter implements InitializingBean {

private final IdentityZoneProvisioning dao;
private final Set<String> staticResources = Set.of("/resources/", "/vendor/font-awesome/");
private Set<String> defaultZoneHostnames = new HashSet<>();
private Logger logger = LoggerFactory.getLogger(getClass());

Expand Down Expand Up @@ -63,7 +65,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}
if (identityZone == null) {
// skip filter to static resources in order to serve images and css in case of invalid zones
boolean isStaticResource = request.getRequestURI().startsWith("/uaa/resources/");
boolean isStaticResource = staticResources.stream().anyMatch(UaaUrlUtils.getRequestPath(request)::startsWith);
if(isStaticResource) {
filterChain.doFilter(request, response);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,26 @@ void doNotThrowException_InCase_RetrievingZoneFails() throws Exception {
}

@Test
public void serveStaticContent_InCase_RetrievingZoneFails() throws Exception {
void serveStaticContent_InCase_RetrievingZoneFails_local() throws Exception {
checkStaticContent("/uaa", "/resources/css/application.css");
checkStaticContent("/uaa", "/vendor/font-awesome/css/font-awesome.min.css");
}

@Test
void serveStaticContent_InCase_RetrievingZoneFails() throws Exception {
checkStaticContent(null, "/resources/css/application.css");
checkStaticContent(null, "/vendor/font-awesome/css/font-awesome.min.css");
}

private void checkStaticContent(String context, String path) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
String incomingSubdomain = "not_a_zone";
String uaaHostname = "uaa.mycf.com";
String incomingHostname = incomingSubdomain+"."+uaaHostname;
request.setServerName(incomingHostname);
request.setRequestURI("/uaa/resources/css/application.css");
request.setRequestURI(context + path);
request.setContextPath(context);
request.setServletPath(path);
MockHttpServletResponse response = new MockHttpServletResponse();

MockFilterChain filterChain = new MockFilterChain() {
Expand Down
Loading