From 1d24ded2219896ad99a610766361af6763b3c1b9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 2 May 2022 14:27:02 +0200 Subject: [PATCH] fixed the method getSharedFolderMembers --- .classpath | 12 ++- .settings/org.eclipse.jdt.core.prefs | 6 +- .settings/org.eclipse.wst.common.component | 18 ++-- ....eclipse.wst.common.project.facet.core.xml | 2 +- CHANGELOG.md | 2 +- .../server/StorageHubClientService.java | 97 +++++++++++++------ .../storagehubwrapper/shared/Member.java | 43 ++++++-- src/test/java/WorkspaceInstance.java | 10 +- 8 files changed, 137 insertions(+), 53 deletions(-) diff --git a/.classpath b/.classpath index 02c8f44..8d06719 100644 --- a/.classpath +++ b/.classpath @@ -13,7 +13,12 @@ - + + + + + + @@ -31,10 +36,9 @@ - + - - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index d405e9c..5f32a47 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,7 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error @@ -9,4 +9,4 @@ org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.processAnnotations=enabled org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 79b1c51..448872e 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,19 +1,25 @@ - + + - + + - + + - + + - + + - + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index 54a5299..f4bf050 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4f81a..7e0848f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ 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). -## [v1.2.0-SNAPSHOT] - 2022-04-28 +## [v1.2.0-SNAPSHOT] - 2022-05-02 #### Enhancements diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java index 8f0ac62..c9f9468 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -10,6 +10,7 @@ import java.util.Set; import org.apache.commons.lang.Validate; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.client.dsl.FileContainer; import org.gcube.common.storagehub.client.dsl.FolderContainer; @@ -19,7 +20,6 @@ import org.gcube.common.storagehub.client.dsl.ListResolver; import org.gcube.common.storagehub.client.dsl.ListResolverTyped; import org.gcube.common.storagehub.client.dsl.OpenResolver; import org.gcube.common.storagehub.client.dsl.StorageHubClient; -import org.gcube.common.storagehub.client.dsl.Util; import org.gcube.common.storagehub.client.plugins.AbstractPlugin; import org.gcube.common.storagehub.client.proxies.ItemManagerClient; import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient; @@ -155,6 +155,7 @@ public class StorageHubClientService { * @param id the id * @param withAccounting the with accounting * @param withMapProperties the with map properties + * @param includeHidden the include hidden * @return the children * @throws Exception the exception */ @@ -231,11 +232,12 @@ public class StorageHubClientService { } /** - * - * @param folderId - * @param relativePath - * @return - * @throws Exception + * Gets the item by path. + * + * @param folderId the folder id + * @param relativePath the relative path + * @return the item by path + * @throws Exception the exception */ public Item getItemByPath(String folderId, String relativePath) throws Exception { setContextProviders(scope, authorizationToken); @@ -575,37 +577,72 @@ public class StorageHubClientService { setContextProviders(scope, authorizationToken); Item item = getItem(folderId, false, true); - List members = null; - if (item instanceof SharedFolder) { - SharedFolder sharedFolder = (SharedFolder) item; - String vreGroupName = null; - if (sharedFolder.isVreFolder()) { - vreGroupName = Util.getVREGroupFromContext(scope); - logger.info("vreGroupName is: " + vreGroupName); - } + List members = new ArrayList(); - logger.info("Reading users from ACLs"); + if (item instanceof SharedFolder) { List listACL = shClient.open(folderId).asFolder().getAcls(); - if (listACL == null) { - throw new Exception("The item with " + folderId + " has not a valid ACLs"); - } - members = new ArrayList(listACL.size()); + logger.info("Reading users from ACLs"); for (ACL acl : listACL) { - Member member = new Member(acl.getPricipal(), Member.TYPE.USER); - if (vreGroupName != null && item.getTitle() != null && item.getTitle().compareTo(vreGroupName) == 0) { + logger.trace("acl princial is: " + acl.getPricipal()); + Member member = new Member(acl.getPricipal(), acl.getPricipal(), Member.TYPE.USER); + if (isGroupName(acl.getPricipal())) { + logger.info("pricipal: " + acl.getPricipal() + " is a group"); member.setMemberType(TYPE.GROUP); + // gcube-devsec-devVRE -> devVRE that is the groupName + member.setName(acl.getPricipal().substring(acl.getPricipal().lastIndexOf("-") + 1, + acl.getPricipal().length())); } + members.add(member); + logger.debug("added member: " + member); } } else { throw new Exception("The item with " + folderId + " is not a Shared Folder"); } - logger.info("Returning " + members.size() + " user/s"); + logger.info("Returning " + members.size() + " member/s"); return members; } + /** + * Checks if is group name. + * + * @param pricipal the pricipal + * @return true, if is group name E.g. with the input 'gcube-devNext-NextNext' + * returns true + */ + private boolean isGroupName(String pricipal) { + + if (pricipal == null || pricipal.isEmpty()) + return false; + + String theScope = getScopeFromVREGroupName(pricipal); + 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 scope != null; + + } + + /** + * Gets the scope from VRE group name. + * + * @param context the context + * @return the scope from VRE group name. Eg. with the input + * 'gcube-devNext-NextNext' returns '/gcube/devNext/NextNext' + */ + public static String getScopeFromVREGroupName(String context) { + String entireScopeName = context.replaceAll("^/(.*)/?$", "$1").replaceAll("-", "/"); + return entireScopeName; + } + /** * Find by name. * @@ -928,8 +965,8 @@ public class StorageHubClientService { /** * Sets the Folder As Hidden or visible . * - * @param itemId the folder id - * @param hide true to set hide, false to set visible + * @param folderId the folder id + * @param hide true to set hide, false to set visible * @throws Exception the exception */ public void setFolderAsHidden(String folderId, boolean hide) throws Exception { @@ -943,10 +980,13 @@ public class StorageHubClientService { } /** - * + * Share folder. + * * @param folderId the folder id to share * @param users the users to share * @param type the permission + * @return the workspace shared folder + * @throws Exception the exception */ public WorkspaceSharedFolder shareFolder(String folderId, Set users, ACLType type) throws Exception { Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null"); @@ -977,9 +1017,12 @@ public class StorageHubClientService { } /** - * + * Unshare folder. + * * @param folderId the folder id to share * @param users the users to share + * @return the workspace shared folder + * @throws Exception the exception */ public WorkspaceSharedFolder unshareFolder(String folderId, Set users) throws Exception { Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null"); @@ -1064,7 +1107,7 @@ public class StorageHubClientService { builder.append("StorageHubClientService [scope="); builder.append(scope); builder.append(", authorizationToken="); - builder.append(authorizationToken.substring(0, authorizationToken.length() - 5) + "XXXXX"); + builder.append(authorizationToken.substring(0, authorizationToken.length() - 8) + "XXXXXXXX"); builder.append(", itemManagerClient="); builder.append(shClient); builder.append("]"); diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/Member.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/Member.java index c5b2b9b..c2a6e66 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/shared/Member.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/Member.java @@ -28,7 +28,8 @@ public class Member implements Serializable { } private String identity; - private TYPE memberType; + private String name; + private TYPE memberType = TYPE.USER; /** * Instantiates a new member. @@ -37,21 +38,41 @@ public class Member implements Serializable { } - public Member(String identity, TYPE memberType) { + /** + * Instantiates a new member. + * + * @param identity the identity is the username of a User or the name of a + * Group. In general is key to identify he/she/it in the in + * the infrastructure + * @param name the name is the name of a User or the name of a Group + * @param memberType the member type + */ + public Member(String identity, String name, TYPE memberType) { super(); this.identity = identity; + this.name = name; this.memberType = memberType; } /** * Gets the identity. * - * @return the identity + * @return the login in case of user and the groupName stored in SHUB (e.g. + * gcube-devsec-devVRE) in case of group */ public String getIdentity() { return identity; } + /** + * Gets the name. + * + * @return the login in case of user and the groupName in case of group + */ + public String getName() { + return name; + } + /** * Gets the member type. * @@ -70,6 +91,15 @@ public class Member implements Serializable { this.identity = identity; } + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + /** * Sets the member type. * @@ -79,16 +109,13 @@ public class Member implements Serializable { this.memberType = memberType; } - /** - * To string. - * - * @return the string - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("Member [identity="); builder.append(identity); + builder.append(", name="); + builder.append(name); builder.append(", memberType="); builder.append(memberType); builder.append("]"); diff --git a/src/test/java/WorkspaceInstance.java b/src/test/java/WorkspaceInstance.java index c7e1c8f..857501e 100644 --- a/src/test/java/WorkspaceInstance.java +++ b/src/test/java/WorkspaceInstance.java @@ -6,6 +6,7 @@ import java.util.Map; import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; import org.gcube.common.storagehubwrapper.server.WorkspaceStorageHubClientService; import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.common.storagehubwrapper.shared.Member; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; @@ -170,11 +171,14 @@ public class WorkspaceInstance { System.out.println("Getting getSharedFolderMembers"); try { - String sharedFolderId = "b679c6fe-894c-4c4c-aebc-4155321a373a"; + String sharedFolderId = "7e3c6636-927c-4139-9fcc-64986ea70cbf"; //devNext + sharedFolderId = "c141d53d-4cae-4bfc-a6f7-9b8bbd8c0e2b"; //NextNext + SCOPE = "/gcube"; + TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"; storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN); - List listLogins = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId); + List listMembers = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId); - System.out.println("List: " + listLogins); + System.out.println("List: " + listMembers); } catch (Exception e) { e.printStackTrace();