#24476 #10

Merged
fabio.sinibaldi merged 9 commits from #24476 into master 2023-01-30 17:44:47 +01:00
5 changed files with 42 additions and 8 deletions
Showing only changes of commit 9ba3559a15 - Show all commits

View File

@ -2,15 +2,23 @@ package org.gcube.application.geoportal.clients;
import org.bson.Document; import org.bson.Document;
import org.gcube.application.cms.tests.TokenSetter; 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.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.rest.UseCaseDescriptorsI;
import org.gcube.application.geoportal.common.utils.tests.GCubeTest; import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors; import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
public class UCDTests{ public class UCDTests{
@ -26,6 +34,7 @@ public class UCDTests{
@Test @Test
public void query() throws Exception { public void query() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
UseCaseDescriptorsI client =getClient(); UseCaseDescriptorsI client =getClient();
QueryRequest request = new QueryRequest(); QueryRequest request = new QueryRequest();
// All // All
@ -40,6 +49,7 @@ public class UCDTests{
@Test @Test
public void getByIdAll() throws Exception { public void getByIdAll() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
UseCaseDescriptorsI client =getClient(); UseCaseDescriptorsI client =getClient();
QueryRequest request = new QueryRequest(); QueryRequest request = new QueryRequest();
@ -57,8 +67,26 @@ public class UCDTests{
@Test @Test
public void getById() throws Exception { public void getById() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
UseCaseDescriptorsI client =getClient(); UseCaseDescriptorsI client =getClient();
System.out.println(client.getById("profiledConcessioni")); 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 @JsonIgnore
public DataAccessPolicy getMatching(User u){ public DataAccessPolicy getMatching(User u){
// TODO Evaluate higher permits
DataAccessPolicy defaultPolicy = null; DataAccessPolicy defaultPolicy = null;
if(dataAccessPolicies!=null) if(dataAccessPolicies!=null)
for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) { for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) {

View File

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

View File

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