Skip to content

Commit

Permalink
MID-8464: fix for redirect to oidc server
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 3, 2023
1 parent 598850a commit 5cbb71b
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.catalina.connector.OutputBuffer;
import org.apache.catalina.connector.Response;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -69,26 +70,40 @@ public void setHeader(String name, String value) {
} else if (StringUtils.isBlank(contextPath)) {
if (value.startsWith("/")) {
value = publicUrlPrefix + value;
} else {
} else if (isUrlThisApplication(value)){
String partAfterSchema = value.substring(value.indexOf("://") + 3);
value = publicUrlPrefix + partAfterSchema.substring(partAfterSchema.indexOf("/"));
}
} else if (value.contains(contextPath + "/")) {
if (value.startsWith(contextPath)) {
value = publicUrlPrefix + value.substring(contextPath.length());
} else if (value.startsWith("/")){
} else if (value.startsWith("/")) {
value = publicUrlPrefix + value;
} else {
} else if (isUrlThisApplication(value)) {
String partAfterHostname = value.substring(value.indexOf("://") + 3);
partAfterHostname = partAfterHostname.substring(partAfterHostname.indexOf("/"));
value = publicUrlPrefix + partAfterHostname.substring(partAfterHostname.indexOf(contextPath) + contextPath.length());
value = publicUrlPrefix +
partAfterHostname.substring(
partAfterHostname.indexOf(contextPath) + contextPath.length());
}
}
}
}
super.setHeader(name, value);
}

private boolean isUrlThisApplication(String url) {
if (StringUtils.isEmpty(url)) {
return true;
}

String applicationUrl = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString();
if (StringUtils.isEmpty(applicationUrl)) {
return true;
}
return url.startsWith(applicationUrl);
}

private String getPublicUrlPrefix() {
try {
PrismObject<SystemConfigurationType> systemConfig = systemObjectCache.getSystemConfiguration(new OperationResult("load system configuration"));
Expand Down

0 comments on commit 5cbb71b

Please sign in to comment.