Fixing incident [#24597], revisited the getSharedFolderMembers
This commit is contained in:
parent
050c554845
commit
3e6207d7b9
|
@ -38,7 +38,7 @@
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="owner.project.facets" value="java"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.2.1-SNAPSHOT] - 2023-04-03
|
||||||
|
|
||||||
|
- [#24597] Fixed no notification sent for items 'updated" in the VRE Folder with '-' in the name
|
||||||
|
|
||||||
## [v1.2.0] - 2022-05-02
|
## [v1.2.0] - 2022-05-02
|
||||||
|
|
||||||
#### Enhancements
|
#### Enhancements
|
||||||
|
|
12
pom.xml
12
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>storagehub-client-wrapper</artifactId>
|
<artifactId>storagehub-client-wrapper</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.2.1-SNAPSHOT</version>
|
||||||
<name>storagehub-client-wrapper</name>
|
<name>storagehub-client-wrapper</name>
|
||||||
<description>This is a wrapper of storagehub-client library. It allows to interact with storagehub in a simplified way by exposing several utilities. Moreover, It exposes by another inteface java beans as defined in (the old) HL interfaces</description>
|
<description>This is a wrapper of storagehub-client library. It allows to interact with storagehub in a simplified way by exposing several utilities. Moreover, It exposes by another inteface java beans as defined in (the old) HL interfaces</description>
|
||||||
<scm>
|
<scm>
|
||||||
|
@ -57,10 +57,18 @@
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.14.8</version>
|
<version>1.14.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>storagehub-model</artifactId>
|
||||||
|
<!--<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>-->
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>storagehub-client-library</artifactId>
|
<artifactId>storagehub-client-library</artifactId>
|
||||||
|
<!--<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>-->
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -168,4 +176,4 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -580,17 +580,33 @@ public class StorageHubClientService {
|
||||||
List<Member> members = new ArrayList<Member>();
|
List<Member> members = new ArrayList<Member>();
|
||||||
|
|
||||||
if (item instanceof SharedFolder) {
|
if (item instanceof SharedFolder) {
|
||||||
|
SharedFolder sharedfolder = (SharedFolder) item;
|
||||||
|
|
||||||
|
String vreName = null;
|
||||||
|
if (sharedfolder.isVreFolder()) {
|
||||||
|
vreName = sharedfolder.getDisplayName(); // the displayName should matching the VRE Name
|
||||||
|
// this class is used?
|
||||||
|
if (sharedfolder instanceof VreFolder) {
|
||||||
|
VreFolder vreFolder = (VreFolder) sharedfolder;
|
||||||
|
vreName = vreFolder.getDisplayName(); // the displayName should matching the VRE Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String infra = WrapperUtility.getInfrastructureNameFromScope(scope);
|
||||||
|
logger.debug("Infrastructure is: " + infra);
|
||||||
|
logger.debug("vreName is: " + vreName);
|
||||||
List<ACL> listACL = shClient.open(folderId).asFolder().getAcls();
|
List<ACL> listACL = shClient.open(folderId).asFolder().getAcls();
|
||||||
logger.info("Reading users from ACLs");
|
logger.info("Reading users from ACLs");
|
||||||
for (ACL acl : listACL) {
|
for (ACL acl : listACL) {
|
||||||
logger.trace("acl princial is: " + acl.getPricipal());
|
logger.info("acl principal is: " + acl.getPricipal());
|
||||||
Member member = new Member(acl.getPricipal(), acl.getPricipal(), Member.TYPE.USER);
|
Member member = new Member(acl.getPricipal(), acl.getPricipal(), Member.TYPE.USER);
|
||||||
if (isGroupName(acl.getPricipal())) {
|
boolean isAGroup = isGroupName(acl.getPricipal(), infra, vreName);
|
||||||
logger.info("pricipal: " + acl.getPricipal() + " is a group");
|
if (isAGroup) {
|
||||||
member.setMemberType(TYPE.GROUP);
|
member.setMemberType(TYPE.GROUP);
|
||||||
// gcube-devsec-devVRE -> devVRE that is the groupName
|
// gcube-devsec-devVRE -> devVRE that is the groupName
|
||||||
member.setName(acl.getPricipal().substring(acl.getPricipal().lastIndexOf("-") + 1,
|
// the VRE Name should be the group name
|
||||||
acl.getPricipal().length()));
|
member.setName(vreName);
|
||||||
|
logger.info("pricipal: " + acl.getPricipal() + " is "+member.getMemberType()+": "+member.getName());
|
||||||
}
|
}
|
||||||
members.add(member);
|
members.add(member);
|
||||||
logger.debug("added member: " + member);
|
logger.debug("added member: " + member);
|
||||||
|
@ -609,22 +625,35 @@ public class StorageHubClientService {
|
||||||
* Checks if is group name.
|
* Checks if is group name.
|
||||||
*
|
*
|
||||||
* @param pricipal the pricipal
|
* @param pricipal the pricipal
|
||||||
|
* @param infrastructureName the infrastructur name
|
||||||
|
* @param vreName the vre name
|
||||||
* @return true, if is group name E.g. with the input 'gcube-devNext-NextNext'
|
* @return true, if is group name E.g. with the input 'gcube-devNext-NextNext'
|
||||||
* returns true
|
* returns true
|
||||||
*/
|
*/
|
||||||
private boolean isGroupName(String pricipal) {
|
private boolean isGroupName(String pricipal, String infrastructureName, String vreName) {
|
||||||
|
|
||||||
if (pricipal == null || pricipal.isEmpty())
|
if (pricipal == null || pricipal.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
String theScope = getScopeFromVREGroupName(pricipal);
|
if (vreName == null || vreName.isEmpty())
|
||||||
ScopeBean scope = null;
|
|
||||||
try {
|
|
||||||
scope = new ScopeBean(theScope);
|
|
||||||
logger.info("pricipal '" + pricipal + "' is a valid scope");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
logger.trace("principal '" + pricipal + "' is not a scope");
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
ScopeBean scope = null;
|
||||||
|
|
||||||
|
//Removing the first / from the infrastructure name. E.g /gcube -> gcube
|
||||||
|
infrastructureName = infrastructureName.replace(WrapperUtility.SCOPE_SEPARATOR, "");
|
||||||
|
if (principalContainsScopes(pricipal, infrastructureName, vreName)) {
|
||||||
|
String theScope = getScopeFromVREGroupName(pricipal, infrastructureName, vreName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
//Just to be sure of the format /RootVO/VO/VRE
|
||||||
|
scope = new ScopeBean(theScope);
|
||||||
|
logger.info("pricipal '" + pricipal + "' remapping as "+theScope+" should be a valid scope");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.trace("principal '" + pricipal + "' is not a scope");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return scope != null;
|
return scope != null;
|
||||||
|
@ -632,15 +661,55 @@ public class StorageHubClientService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the scope from VRE group name.
|
* Principal contains scopes.
|
||||||
*
|
*
|
||||||
* @param context the context
|
* @param principal the principal
|
||||||
* @return the scope from VRE group name. Eg. with the input
|
* @param infrastructurName the infrastructur name
|
||||||
* 'gcube-devNext-NextNext' returns '/gcube/devNext/NextNext'
|
* @param vreName the vre name
|
||||||
|
* @return true, if principal (as string) contains the RootVO and the VRE name.
|
||||||
*/
|
*/
|
||||||
public static String getScopeFromVREGroupName(String context) {
|
private static boolean principalContainsScopes(String principal, String infrastructurName, String vreName) {
|
||||||
String entireScopeName = context.replaceAll("^/(.*)/?$", "$1").replaceAll("-", "/");
|
|
||||||
return entireScopeName;
|
if (principal.contains(infrastructurName)) {
|
||||||
|
if (principal.contains(vreName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getScopeFromVREGroupName(String context, String infrastructurName, String vreName) {
|
||||||
|
|
||||||
|
if (vreName == null)
|
||||||
|
vreName = "";
|
||||||
|
|
||||||
|
logger.debug("vreName: " + vreName);
|
||||||
|
|
||||||
|
if (infrastructurName.startsWith("/"))
|
||||||
|
infrastructurName = infrastructurName.substring(1, infrastructurName.length());
|
||||||
|
|
||||||
|
logger.debug("infrastructurName: " + infrastructurName);
|
||||||
|
|
||||||
|
String voGroup = context.replaceAll(infrastructurName, "");
|
||||||
|
if (vreName != null) {
|
||||||
|
voGroup = voGroup.replaceAll(vreName, "").replaceAll("-", "");
|
||||||
|
}
|
||||||
|
String voName = voGroup.replaceAll("-", "");
|
||||||
|
logger.debug("voName: " + voName);
|
||||||
|
|
||||||
|
StringBuilder theScopeBuilder = new StringBuilder();
|
||||||
|
theScopeBuilder.append("/" + infrastructurName);
|
||||||
|
if (voName != null && !voName.isEmpty()) {
|
||||||
|
theScopeBuilder.append(WrapperUtility.SCOPE_SEPARATOR + voName);
|
||||||
|
}
|
||||||
|
if (vreName != null && !vreName.isEmpty()) {
|
||||||
|
theScopeBuilder.append(WrapperUtility.SCOPE_SEPARATOR + vreName);
|
||||||
|
}
|
||||||
|
String theScope = theScopeBuilder.toString();
|
||||||
|
logger.debug("Built scope: " + theScope);
|
||||||
|
return theScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,9 +12,13 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class WrapperUtility.
|
||||||
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 17, 2018
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 17, 2018
|
||||||
*/
|
*/
|
||||||
public class WrapperUtility {
|
public class WrapperUtility {
|
||||||
|
|
||||||
|
public static final String SCOPE_SEPARATOR = "/";
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(WrapperUtility.class);
|
private static Logger logger = LoggerFactory.getLogger(WrapperUtility.class);
|
||||||
|
|
||||||
|
@ -47,4 +51,35 @@ public class WrapperUtility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the infrastructure name from scope.
|
||||||
|
*
|
||||||
|
* @param scope the scope
|
||||||
|
* @return the infrastructure name from scope
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public static String getInfrastructureNameFromScope(String scope) throws Exception{
|
||||||
|
|
||||||
|
if(scope==null || scope.isEmpty()){
|
||||||
|
throw new Exception("Scope is null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!scope.startsWith(SCOPE_SEPARATOR)){
|
||||||
|
logger.warn("Input scope: "+scope+" not have / is a really scope?");
|
||||||
|
scope = SCOPE_SEPARATOR+scope;
|
||||||
|
logger.warn("Tentative as scope: "+scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] splitScope = scope.split(SCOPE_SEPARATOR);
|
||||||
|
|
||||||
|
String rootScope = SCOPE_SEPARATOR + splitScope[1];
|
||||||
|
|
||||||
|
if(rootScope.length()<2){
|
||||||
|
throw new Exception("Infrastructure name not found in "+scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootScope;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,10 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||||
import org.gcube.common.storagehubwrapper.server.WorkspaceStorageHubClientService;
|
import org.gcube.common.storagehubwrapper.server.WorkspaceStorageHubClientService;
|
||||||
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
||||||
|
@ -26,13 +30,15 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class WorkspaceInstance {
|
public class WorkspaceInstance {
|
||||||
|
|
||||||
// public static String SCOPE = "/gcube";
|
public static String SCOPE = "/gcube/devsec/devVRE";
|
||||||
public static String SCOPE = "/d4science.research-infrastructures.eu";
|
//public static String SCOPE = "/d4science.research-infrastructures.eu";
|
||||||
|
|
||||||
// public static String USERNAME = "massimiliano.assante";
|
// public static String USERNAME = "massimiliano.assante";
|
||||||
public static String USERNAME = "francesco.mangiacrapa";
|
public static String USERNAME = "francesco.mangiacrapa";
|
||||||
|
|
||||||
public static String TOKEN = System.getenv("TOKEN_gcube"); // YOU MUST SET THIS AS Environment variable
|
//public static String TOKEN = System.getenv("TOKEN_gcube"); // YOU MUST SET THIS AS Environment variable
|
||||||
|
|
||||||
|
public static String TOKEN = "";
|
||||||
|
|
||||||
public static String FIND_FILE_NAME = "francesco";
|
public static String FIND_FILE_NAME = "francesco";
|
||||||
public static String rootId = null;
|
public static String rootId = null;
|
||||||
|
@ -40,7 +46,7 @@ public class WorkspaceInstance {
|
||||||
|
|
||||||
private WorkspaceStorageHubClientService workspace;
|
private WorkspaceStorageHubClientService workspace;
|
||||||
|
|
||||||
// @Before
|
//@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
if (TOKEN == null) {
|
if (TOKEN == null) {
|
||||||
|
@ -48,6 +54,9 @@ public class WorkspaceInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Read TOKEN_gcube: " + TOKEN);
|
System.out.println("Read TOKEN_gcube: " + TOKEN);
|
||||||
|
|
||||||
|
ScopeProvider.instance.set(SCOPE);
|
||||||
|
SecurityTokenProvider.instance.set(TOKEN);
|
||||||
|
|
||||||
// METHOD 1
|
// METHOD 1
|
||||||
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN, false, false, true);
|
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN, false, false, true);
|
||||||
|
@ -110,6 +119,16 @@ public class WorkspaceInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void getVREFolder() throws Exception {
|
||||||
|
System.out.println("Get VRE Folder");
|
||||||
|
|
||||||
|
StorageHubClient shClient = new StorageHubClient();
|
||||||
|
FolderContainer vre= shClient.openVREFolder();
|
||||||
|
System.out.println("VRE folder: "+vre.getId() + " ACLs: "+vre.getAcls());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
public void getFilteredChildren() throws Exception {
|
public void getFilteredChildren() throws Exception {
|
||||||
|
@ -166,14 +185,18 @@ public class WorkspaceInstance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
@Test
|
||||||
public void getSharedFolderMembers() {
|
public void getSharedFolderMembers() {
|
||||||
System.out.println("Getting getSharedFolderMembers");
|
System.out.println("Getting getSharedFolderMembers");
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String sharedFolderId = "7e3c6636-927c-4139-9fcc-64986ea70cbf"; // devNext
|
//String sharedFolderId = "7e3c6636-927c-4139-9fcc-64986ea70cbf"; // devVRE (VRE Folder)
|
||||||
sharedFolderId = "c141d53d-4cae-4bfc-a6f7-9b8bbd8c0e2b"; //NextNext
|
String sharedFolderId = "f8275521-5da1-4501-8385-bb9c79055aa6"; // PROD - d4science.research-infrastructures.eu-D4OS-Blue-Cloud2026Project (VRE Folder)
|
||||||
|
//String sharedFolderId = "4d6f1fe9-8f04-45c9-a87e-ee6093553d77"; // PROD - AriadnePlus-LiDAR Dataset (simple Shared Folder)
|
||||||
|
//String sharedFolderId = "a4837a77-c1d0-4ea4-9f9d-c4bd5cf07e9a"; // PROD - Sample Reports and Templates (private Folder)
|
||||||
|
//sharedFolderId = "c141d53d-4cae-4bfc-a6f7-9b8bbd8c0e2b"; //NextNext
|
||||||
SCOPE = "/gcube";
|
SCOPE = "/gcube";
|
||||||
|
SCOPE = "/d4science.research-infrastructures.eu";
|
||||||
TOKEN = "";
|
TOKEN = "";
|
||||||
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN);
|
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN);
|
||||||
List<Member> listMembers = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId);
|
List<Member> listMembers = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId);
|
||||||
|
|
Loading…
Reference in New Issue