This commit is contained in:
Fabio Sinibaldi 2023-01-30 12:01:56 +01:00
parent b8cb4e86f0
commit 9ba3559a15
5 changed files with 42 additions and 8 deletions

View File

@ -2,15 +2,23 @@ package org.gcube.application.geoportal.clients;
import org.bson.Document;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.model.document.accounting.User;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.DataAccessPolicy;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.rest.UseCaseDescriptorsI;
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicLong;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
public class UCDTests{
@ -26,6 +34,7 @@ public class UCDTests{
@Test
public void query() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
UseCaseDescriptorsI client =getClient();
QueryRequest request = new QueryRequest();
// All
@ -40,6 +49,7 @@ public class UCDTests{
@Test
public void getByIdAll() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
UseCaseDescriptorsI client =getClient();
QueryRequest request = new QueryRequest();
@ -57,8 +67,26 @@ public class UCDTests{
@Test
public void getById() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
UseCaseDescriptorsI client =getClient();
System.out.println(client.getById("profiledConcessioni"));
}
@Test
public void checkPolicies() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
UseCaseDescriptorsI client =getClient();
UseCaseDescriptor ucd = client.getById("profiledConcessioni");
System.out.println(Serialization.write(ucd));
User u = new User();
u.setRoles(new HashSet<>());
u.getRoles().addAll(Arrays.asList("Members","Data-Manager"));
DataAccessPolicy p = ucd.getMatching(u);
System.out.println("Evaluated policy : "+Serialization.write(p));
assertEquals(p.getPolicy().getRead(), DataAccessPolicy.Policy.Type.any);
assertEquals(p.getPolicy().getWrite(), DataAccessPolicy.Policy.Type.any);
}
}

View File

@ -121,6 +121,8 @@ public class UseCaseDescriptor implements Serializable {
@JsonIgnore
public DataAccessPolicy getMatching(User u){
// TODO Evaluate higher permits
DataAccessPolicy defaultPolicy = null;
if(dataAccessPolicies!=null)
for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) {

View File

@ -19,11 +19,15 @@
}
},
"_dataAccessPolicies": [
{"_policy" : {"_read" : "own", "_write" : "own"}, "_roles":[]},
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Guest"],
"_enforcer": {"_filter" : "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"PUBLISHED\"}}"}},
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Editor"]},
{"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["Admin"]}
{"_policy": {"_read": "any","_write": "any"},
"_roles": ["Data-Manager"]},
{"_policy": {"_read": "own","_write": "own"},
"_roles": ["Data-Editor"]},
{"_policy": {"_read": "any","_write": "none"},
"_roles": ["Member"],
"_enforcer": {"_filter": "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"Published\"}}"}},
{"_policy": {"_read": "none","_write": "none"},
"_roles": []}
],
"_relationshipDefinitions" : [

View File

@ -53,7 +53,7 @@ public class ExportConcessioniAsProjects {
File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1669889538860");
// select only cluster
// dir = new File(dir,"cluster_1");
dir = new File(dir,"61d5ec7495184b186ad0c2e4");