fixed the method getSharedFolderMembers

This commit is contained in:
Francesco Mangiacrapa 2022-05-02 14:27:02 +02:00
parent 4081445ef7
commit 1d24ded221
8 changed files with 137 additions and 53 deletions

View File

@ -13,7 +13,12 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/test/resources"/> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -31,10 +36,9 @@
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> <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="module" value="true"/> <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"/>

View File

@ -1,7 +1,7 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 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.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11 org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,19 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="storagehub-client-wrapper"> <wb-module deploy-name="storagehub-client-wrapper">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/> <wb-resource deploy-path="/" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/.apt_generated"/> <wb-resource deploy-path="/" source-path="/.apt_generated"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<installed facet="jst.utility" version="1.0"/> <installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="11"/> <installed facet="java" version="1.8"/>
</faceted-project> </faceted-project>

View File

@ -3,7 +3,7 @@
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.0-SNAPSHOT] - 2022-04-28 ## [v1.2.0-SNAPSHOT] - 2022-05-02
#### Enhancements #### Enhancements

View File

@ -10,6 +10,7 @@ import java.util.Set;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; 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.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.FileContainer; import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer; 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.ListResolverTyped;
import org.gcube.common.storagehub.client.dsl.OpenResolver; import org.gcube.common.storagehub.client.dsl.OpenResolver;
import org.gcube.common.storagehub.client.dsl.StorageHubClient; 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.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient; import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient; import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
@ -155,6 +155,7 @@ public class StorageHubClientService {
* @param id the id * @param id the id
* @param withAccounting the with accounting * @param withAccounting the with accounting
* @param withMapProperties the with map properties * @param withMapProperties the with map properties
* @param includeHidden the include hidden
* @return the children * @return the children
* @throws Exception the exception * @throws Exception the exception
*/ */
@ -231,11 +232,12 @@ public class StorageHubClientService {
} }
/** /**
* Gets the item by path.
* *
* @param folderId * @param folderId the folder id
* @param relativePath * @param relativePath the relative path
* @return * @return the item by path
* @throws Exception * @throws Exception the exception
*/ */
public Item getItemByPath(String folderId, String relativePath) throws Exception { public Item getItemByPath(String folderId, String relativePath) throws Exception {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
@ -575,37 +577,72 @@ public class StorageHubClientService {
setContextProviders(scope, authorizationToken); setContextProviders(scope, authorizationToken);
Item item = getItem(folderId, false, true); Item item = getItem(folderId, false, true);
List<Member> members = null; List<Member> members = new ArrayList<Member>();
if (item instanceof SharedFolder) {
SharedFolder sharedFolder = (SharedFolder) item;
String vreGroupName = null;
if (sharedFolder.isVreFolder()) {
vreGroupName = Util.getVREGroupFromContext(scope);
logger.info("vreGroupName is: " + vreGroupName);
}
logger.info("Reading users from ACLs"); if (item instanceof SharedFolder) {
List<ACL> listACL = shClient.open(folderId).asFolder().getAcls(); List<ACL> listACL = shClient.open(folderId).asFolder().getAcls();
if (listACL == null) { logger.info("Reading users from ACLs");
throw new Exception("The item with " + folderId + " has not a valid ACLs");
}
members = new ArrayList<Member>(listACL.size());
for (ACL acl : listACL) { for (ACL acl : listACL) {
Member member = new Member(acl.getPricipal(), Member.TYPE.USER); logger.trace("acl princial is: " + acl.getPricipal());
if (vreGroupName != null && item.getTitle() != null && item.getTitle().compareTo(vreGroupName) == 0) { 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); 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 { } else {
throw new Exception("The item with " + folderId + " is not a Shared Folder"); 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; 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. * Find by name.
* *
@ -928,7 +965,7 @@ public class StorageHubClientService {
/** /**
* Sets the Folder As Hidden or visible . * Sets the Folder As Hidden or visible .
* *
* @param itemId the folder id * @param folderId the folder id
* @param hide true to set hide, false to set visible * @param hide true to set hide, false to set visible
* @throws Exception the exception * @throws Exception the exception
*/ */
@ -943,10 +980,13 @@ public class StorageHubClientService {
} }
/** /**
* Share folder.
* *
* @param folderId the folder id to share * @param folderId the folder id to share
* @param users the users to share * @param users the users to share
* @param type the permission * @param type the permission
* @return the workspace shared folder
* @throws Exception the exception
*/ */
public WorkspaceSharedFolder shareFolder(String folderId, Set<String> users, ACLType type) throws Exception { public WorkspaceSharedFolder shareFolder(String folderId, Set<String> users, ACLType type) throws Exception {
Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null"); 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 folderId the folder id to share
* @param users the users to share * @param users the users to share
* @return the workspace shared folder
* @throws Exception the exception
*/ */
public WorkspaceSharedFolder unshareFolder(String folderId, Set<String> users) throws Exception { public WorkspaceSharedFolder unshareFolder(String folderId, Set<String> users) throws Exception {
Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null"); Validate.notNull(folderId, "Bad request to setFolderAsHidden the folderId is null");
@ -1064,7 +1107,7 @@ public class StorageHubClientService {
builder.append("StorageHubClientService [scope="); builder.append("StorageHubClientService [scope=");
builder.append(scope); builder.append(scope);
builder.append(", authorizationToken="); 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(", itemManagerClient=");
builder.append(shClient); builder.append(shClient);
builder.append("]"); builder.append("]");

View File

@ -28,7 +28,8 @@ public class Member implements Serializable {
} }
private String identity; private String identity;
private TYPE memberType; private String name;
private TYPE memberType = TYPE.USER;
/** /**
* Instantiates a new member. * 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(); super();
this.identity = identity; this.identity = identity;
this.name = name;
this.memberType = memberType; this.memberType = memberType;
} }
/** /**
* Gets the identity. * 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() { public String getIdentity() {
return identity; 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. * Gets the member type.
* *
@ -70,6 +91,15 @@ public class Member implements Serializable {
this.identity = identity; this.identity = identity;
} }
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/** /**
* Sets the member type. * Sets the member type.
* *
@ -79,16 +109,13 @@ public class Member implements Serializable {
this.memberType = memberType; this.memberType = memberType;
} }
/**
* To string.
*
* @return the string
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("Member [identity="); builder.append("Member [identity=");
builder.append(identity); builder.append(identity);
builder.append(", name=");
builder.append(name);
builder.append(", memberType="); builder.append(", memberType=");
builder.append(memberType); builder.append(memberType);
builder.append("]"); builder.append("]");

View File

@ -6,6 +6,7 @@ import java.util.Map;
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;
import org.gcube.common.storagehubwrapper.shared.Member;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
@ -170,11 +171,14 @@ public class WorkspaceInstance {
System.out.println("Getting getSharedFolderMembers"); System.out.println("Getting getSharedFolderMembers");
try { 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); storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN);
List<String> listLogins = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId); List<Member> listMembers = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId);
System.out.println("List: " + listLogins); System.out.println("List: " + listMembers);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();