Skip to content

Commit

Permalink
Feat: add missing CF header in public case
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbet committed Feb 17, 2025
1 parent f3ce733 commit c43529a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public abstract class AbstractPolicyEnforcer implements PolicyEnforcer {
public static final String ORGANIZATION_NAME = "organization.name";
public static final String USER_ID = "user.id";
public static final String USER_EMAIL = "user.emaild";
// This filter is used to protect private collection in public endpoint
public static final String DUMMY_COLUMN_FILTER = "dummy:*";

private final Logger LOGGER = LoggerFactory.getLogger(AbstractPolicyEnforcer.class);
protected ArlasAuthConfiguration authConf;
Expand Down Expand Up @@ -214,7 +216,7 @@ public void filter(ContainerRequestContext ctx, String method, String path, Stri
logUAM(LOGGER::debug, ALLOWED, "public (no token): " + log);
}
// use a dummy CF in order to bypass the CFUtil and give access to public collections
ctx.getHeaders().add(COLUMN_FILTER, "*:*");
ctx.getHeaders().add(COLUMN_FILTER, DUMMY_COLUMN_FILTER);
}
return;
}
Expand Down Expand Up @@ -281,6 +283,7 @@ public void filter(ContainerRequestContext ctx, String method, String path, Stri
}
if (isPublic) {
putDecision(getDecisionCacheKey(ctx, method, fullPath, accessToken), Boolean.TRUE);
ctx.getHeaders().add(COLUMN_FILTER, DUMMY_COLUMN_FILTER);
logUAM(LOGGER::debug, ALLOWED, "public (with token): " + log);
return;
}
Expand All @@ -290,6 +293,7 @@ public void filter(ContainerRequestContext ctx, String method, String path, Stri
logUAM(LOGGER::warn, DENIED,"unauthorized (invalid token): " + log);
ctx.abortWith(Response.status(UNAUTHORIZED).build());
} else {
ctx.getHeaders().add(COLUMN_FILTER, DUMMY_COLUMN_FILTER);
logUAM(LOGGER::debug, ALLOWED,"public (invalid token): " + log);
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ public Response importCollections(
Set<String> allowedCollections = ColumnFilterUtil.getAllowedCollections(Optional.ofNullable(columnFilter));
for (CollectionReference collection : collections) {
for (String c : allowedCollections) {
// In case of collection/* POST is public, we import only public collection, because of dummy column filter ctx.getHeaders().add(COLUMN_FILTER, "dummy:*");
if ((c.endsWith("*") && collection.collectionName.startsWith(c.substring(0, c.indexOf("*"))))
|| collection.collectionName.equals(c)) {
|| collection.collectionName.equals(c) || collection.params.collectionOrganisations.isPublic) {
try {
savedCollections.add(save(collection.collectionName, collection.params, true, organisations));
} catch (Exception e) {
Expand Down Expand Up @@ -531,6 +532,8 @@ public CollectionReference save(String collection, CollectionReferenceParameters
})

public Response delete(
@Parameter(hidden = true)
@HeaderParam(value = ARLAS_ORGANISATION) String organisations,
@Parameter(name = "collection",
description = "collection",
required = true)
Expand All @@ -547,6 +550,8 @@ public Response delete(
if (collection != null && collection.equals(META_COLLECTION_NAME)) {
throw new NotAllowedException("Forbidden operation on '" + META_COLLECTION_NAME + "'");
}
CollectionReference collectionReference = collectionReferenceService.getCollectionReference(collection,Optional.ofNullable(organisations));
collectionReferenceService.checkIfAllowedForOrganisations(collectionReference, Optional.ofNullable(organisations), true);
collectionReferenceService.deleteCollectionReference(collection);
return ResponseFormatter.getSuccessResponse("Collection " + collection + " deleted.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -153,6 +154,10 @@ public void loadCsw(long sleepAfter) throws IOException {
params.rasterTileURL = DataSetTool.DATASET_TILE_URL;
params.dublinCoreElementName=dublinCoreElementName;
params.inspire = new Inspire();
params.collectionOrganisations = new CollectionOrganisations();
params.collectionOrganisations.isPublic = true;
params.collectionOrganisations.owner="";
params.collectionOrganisations.sharedWith = new ArrayList<>();
params.inspire.lineage = DataSetTool.DATASET_INSPIRE_LINEAGE;
params.inspire.topicCategories = Arrays.asList(DataSetTool.DATASET_INSPIRE_TOPIC_CATEGORY);
String url = arlasPath + "collections/" + dublinCoreElementName.title.split(" ")[0].toLowerCase();
Expand Down

0 comments on commit c43529a

Please sign in to comment.