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"/>
</attributes>
</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">
<attributes>
<attribute name="maven.pomderived" value="true"/>
@ -31,10 +36,9 @@
<attribute name="optional" value="true"/>
</attributes>
</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>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

View File

@ -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

View File

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

View File

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

View File

@ -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

View File

@ -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<Member> 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<Member> members = new ArrayList<Member>();
logger.info("Reading users from ACLs");
if (item instanceof SharedFolder) {
List<ACL> listACL = shClient.open(folderId).asFolder().getAcls();
if (listACL == null) {
throw new Exception("The item with " + folderId + " has not a valid ACLs");
}
members = new ArrayList<Member>(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<String> 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<String> 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("]");

View File

@ -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("]");

View File

@ -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<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) {
e.printStackTrace();