Skip to content

Commit

Permalink
fix(api) cors headers were not taking the system table values into ac…
Browse files Browse the repository at this point in the history
…count

#26503
  • Loading branch information
wezell committed Oct 1, 2024
1 parent 324de85 commit 931c97e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions dotCMS/src/main/java/com/dotcms/rest/api/CorsFilter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotcms.rest.api;

import io.vavr.Lazy;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
Expand Down Expand Up @@ -28,9 +29,9 @@ public class CorsFilter implements ContainerResponseFilter {

final public static String CORS_PREFIX = "api.cors";
final public static String CORS_DEFAULT = "default";
final private Map<String, List<String[]>> headerMap;
final private Lazy<Map<String, List<String[]>>> headerMap = Lazy.of(this::loadHeaders);

public CorsFilter() {
public Map<String, List<String[]>> loadHeaders() {
Map<String, List<String[]>> loadingMap = new HashMap<>();
final List<String> props = Config.subsetContainsAsList(CORS_PREFIX);
props.forEach(key -> {
Expand All @@ -45,9 +46,14 @@ public CorsFilter() {
loadingMap.put(mapping, keys);

});
this.headerMap = ImmutableMap.copyOf(loadingMap);
return ImmutableMap.copyOf(loadingMap);
}







@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
Expand All @@ -71,7 +77,7 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont


protected List<String[]> getHeaders(final String mapping) {
List<String[]> corsHeaders = headerMap.containsKey(mapping) ? headerMap.get(mapping) : headerMap.get(CORS_DEFAULT);
List<String[]> corsHeaders = headerMap.get().containsKey(mapping) ? headerMap.get().get(mapping) : headerMap.get().get(CORS_DEFAULT);
return corsHeaders != null ? corsHeaders : ImmutableList.of() ;

}
Expand Down Expand Up @@ -100,4 +106,3 @@ else if (c == '-') {


}

3 changes: 3 additions & 0 deletions dotCMS/src/main/java/com/dotmarketing/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ public static String envKey(final String theKey) {
public static List<String> subsetContainsAsList(final String containsString){
final List<String> fullListProps = new ArrayList<String>();
props.getKeys().forEachRemaining(fullListProps::add);
if(null != systemTableConfigSource && enableSystemTableConfigSource){
systemTableConfigSource.getPropertyNames().forEach(fullListProps::add);
}

//List with all system env props that contains the pattern
final String envContainsString = envKey(containsString);
Expand Down

0 comments on commit 931c97e

Please sign in to comment.