Merge remote-tracking branch 'origin/user_group_management'
Conflicts: pom.xml
This commit is contained in:
commit
73cf9007c1
8
pom.xml
8
pom.xml
|
@ -18,7 +18,7 @@
|
|||
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
<version>1.0.7</version>
|
||||
<version>1.0.8</version>
|
||||
<name>storagehub-client-library</name>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -54,7 +54,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-model</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
|
@ -64,12 +64,10 @@
|
|||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.24.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>2.24.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -79,7 +77,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-jaxrs-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
@ -10,6 +12,8 @@ public class StorageHubClient {
|
|||
|
||||
private WorkspaceManagerClient wsClient = AbstractPlugin.workspace().build();
|
||||
private ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||
private GroupManagerClient groupClient = AbstractPlugin.groups().build();
|
||||
private UserManagerClient userClient = AbstractPlugin.users().build();
|
||||
|
||||
public FolderContainer getWSRoot(){
|
||||
return new FolderContainer(itemclient, wsClient.getWorkspace());
|
||||
|
@ -33,6 +37,14 @@ public class StorageHubClient {
|
|||
return new ListResolver((onlyType, includeHidden, excludes) -> wsClient.getVreFolders(excludes), itemclient);
|
||||
}
|
||||
|
||||
public VREFolderManager getVreFolderManager(String vreTitle) {
|
||||
return new VREFolderManager(wsClient, groupClient, vreTitle);
|
||||
}
|
||||
|
||||
public VREFolderManager getVreFolderManager() {
|
||||
return new VREFolderManager(wsClient, groupClient, null);
|
||||
}
|
||||
|
||||
public FolderContainer openTrash() {
|
||||
return new FolderContainer(itemclient, wsClient.getTrashFolder());
|
||||
}
|
||||
|
@ -49,10 +61,15 @@ public class StorageHubClient {
|
|||
return wsClient.getTotalItemCount();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GenericItemContainer restoreThrashItem(String itemId) {
|
||||
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(itemId));
|
||||
}
|
||||
|
||||
public void createUserAccount(String userId) throws StorageHubException {
|
||||
userClient.createUser(userId);
|
||||
}
|
||||
|
||||
public void deleteUserAccount(String userId) throws StorageHubException {
|
||||
userClient.removeUser(userId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
@ -14,4 +18,11 @@ public class Util {
|
|||
return new FolderContainer(itemClient, (FolderItem)item);
|
||||
else return new GenericItemContainer(itemClient, item);
|
||||
}
|
||||
|
||||
public static String getVREGroupFromContext(String context) throws BackendGenericError{
|
||||
ScopeBean bean = new ScopeBean(context);
|
||||
if (!bean.is(Type.VRE)) throw new BackendGenericError(context+ " is not a VRE context");
|
||||
String entireScopeName= bean.toString().replaceAll("^/(.*)/?$", "$1").replaceAll("/", "-");
|
||||
return entireScopeName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
||||
public class VREFolderManager {
|
||||
|
||||
private WorkspaceManagerClient wsClient;
|
||||
private GroupManagerClient groupClient;
|
||||
|
||||
private String vreTitle;
|
||||
|
||||
public VREFolderManager(WorkspaceManagerClient wsClient, GroupManagerClient groupClient, String vreTitle) {
|
||||
super();
|
||||
this.wsClient = wsClient;
|
||||
this.groupClient = groupClient;
|
||||
this.vreTitle = vreTitle;
|
||||
}
|
||||
|
||||
public void removeUser(String userId) throws StorageHubException{
|
||||
groupClient.removeUserFromGroup(userId, vreTitle);
|
||||
}
|
||||
|
||||
public void addUser(String userId) throws StorageHubException{
|
||||
groupClient.addUserToGroup(userId, vreTitle);
|
||||
}
|
||||
|
||||
public List<String> getUsers() throws StorageHubException{
|
||||
return groupClient.getUsersOfGroup(vreTitle);
|
||||
}
|
||||
|
||||
/*private Item getVreFolder() {
|
||||
return wsClient.getVreFolder(Excludes.ALL.toArray(new String[0]));
|
||||
}*/
|
||||
|
||||
public void setAdmin(String userId) throws StorageHubException{
|
||||
groupClient.addAdmin(vreTitle, userId);
|
||||
}
|
||||
|
||||
public void removeAdmin(String userId) throws StorageHubException{
|
||||
groupClient.removeAdmin(vreTitle, userId);
|
||||
}
|
||||
|
||||
public List<String> getAdmins() throws StorageHubException{
|
||||
return groupClient.getAdmins(vreTitle);
|
||||
}
|
||||
|
||||
public void createVRE(AccessType accessType, String folderOwner) throws StorageHubException{
|
||||
groupClient.createGroup(vreTitle, accessType, folderOwner);
|
||||
}
|
||||
|
||||
public void removeVRE() throws StorageHubException{
|
||||
groupClient.removeGroup(vreTitle);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,14 @@
|
|||
package org.gcube.common.storagehub.client.plugins;
|
||||
|
||||
import org.gcube.common.authorization.library.policies.Users;
|
||||
import org.gcube.common.clients.Plugin;
|
||||
import org.gcube.common.clients.ProxyBuilder;
|
||||
import org.gcube.common.clients.ProxyBuilderImpl;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
|
||||
|
||||
|
@ -16,12 +19,22 @@ public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
|||
|
||||
private static final ItemManagerPlugin item_plugin = new ItemManagerPlugin();
|
||||
private static final WorkspaceManagerPlugin workspace_plugin = new WorkspaceManagerPlugin();
|
||||
private static final UserManagerPlugin user_plugin = new UserManagerPlugin();
|
||||
private static final GroupManagerPlugin group_plugin = new GroupManagerPlugin();
|
||||
|
||||
|
||||
public static ProxyBuilder<ItemManagerClient> item() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,ItemManagerClient>(item_plugin);
|
||||
}
|
||||
|
||||
public static ProxyBuilder<GroupManagerClient> groups() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,GroupManagerClient>(group_plugin);
|
||||
}
|
||||
|
||||
public static ProxyBuilder<UserManagerClient> users() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,UserManagerClient>(user_plugin);
|
||||
}
|
||||
|
||||
public static ProxyBuilder<WorkspaceManagerClient> workspace() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,WorkspaceManagerClient>(workspace_plugin);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.gcube.common.storagehub.client.plugins;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.ws.EndpointReference;
|
||||
|
||||
import org.gcube.common.calls.jaxrs.GcubeService;
|
||||
import org.gcube.common.calls.jaxrs.TargetFactory;
|
||||
import org.gcube.common.clients.config.ProxyConfig;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
||||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||
import org.gcube.common.storagehub.client.proxies.DefaultGroupManager;
|
||||
import org.gcube.common.storagehub.client.proxies.DefaultUserManager;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class GroupManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, GroupManagerClient> {
|
||||
|
||||
public GroupManagerPlugin() {
|
||||
super("storagehub/workspace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
return new DefaultGroupManager(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||
throws Exception {
|
||||
DOMResult result = new DOMResult();
|
||||
epr.writeTo(result);
|
||||
Node node =result.getNode();
|
||||
Node child=node.getFirstChild();
|
||||
String address = child.getTextContent();
|
||||
//GXWebTargetAdapterRequest request = GXWebTargetAdapterRequest.newRequest(address).path(this.name).path("items");
|
||||
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("groups");
|
||||
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||
requestAdapter.register(MyInputStreamProvider.class);
|
||||
requestAdapter.register(MultiPartFeature.class);
|
||||
return requestAdapter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.gcube.common.storagehub.client.plugins;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.ws.EndpointReference;
|
||||
|
||||
import org.gcube.common.calls.jaxrs.GcubeService;
|
||||
import org.gcube.common.calls.jaxrs.TargetFactory;
|
||||
import org.gcube.common.clients.config.ProxyConfig;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
||||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||
import org.gcube.common.storagehub.client.proxies.DefaultUserManager;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class UserManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, UserManagerClient> {
|
||||
|
||||
public UserManagerPlugin() {
|
||||
super("storagehub/workspace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
return new DefaultUserManager(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||
throws Exception {
|
||||
DOMResult result = new DOMResult();
|
||||
epr.writeTo(result);
|
||||
Node node =result.getNode();
|
||||
Node child=node.getFirstChild();
|
||||
String address = child.getTextContent();
|
||||
//GXWebTargetAdapterRequest request = GXWebTargetAdapterRequest.newRequest(address).path(this.name).path("items");
|
||||
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("users");
|
||||
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||
requestAdapter.register(MyInputStreamProvider.class);
|
||||
requestAdapter.register(MultiPartFeature.class);
|
||||
return requestAdapter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,333 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedHashMap;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
|
||||
public class DefaultGroupManager implements GroupManagerClient {
|
||||
|
||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
||||
|
||||
public DefaultGroupManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserToGroup(String userId, String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
||||
formData.add("userId", userId);
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("users").put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUserFromGroup(String userId, String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("users").path(userId).delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups() throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
|
||||
@Override
|
||||
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return response.getSource().readEntity(List.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<String> users = delegate.make(call);
|
||||
return users;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createGroup(String groupId, AccessType accessType, String folderOwner) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
||||
multipart.field("accessType", accessType, MediaType.APPLICATION_JSON_TYPE);
|
||||
multipart.field("group", groupId);
|
||||
multipart.field("folderOwner", folderOwner);
|
||||
|
||||
|
||||
GXInboundResponse response = myManager.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsersOfGroup(String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
|
||||
@Override
|
||||
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("users").get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return response.getSource().readEntity(List.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<String> users = delegate.make(call);
|
||||
return users;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void addAdmin(String groupId, String userId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
||||
formData.add("userId", userId);
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("admins").put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAdmin(String groupId, String userId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("admins").path(userId).delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAdmins(String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
|
||||
@Override
|
||||
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("admins").get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return response.getSource().readEntity(List.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<String> users = delegate.make(call);
|
||||
return users;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1007,9 +1007,8 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public String removeSharedFolderAdmin(String id, String user) throws StorageHubException {
|
||||
public String removeAdmin(String id, String user) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
@Override
|
||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
|
@ -1041,7 +1040,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedHashMap;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||
|
||||
public class DefaultUserManager implements UserManagerClient {
|
||||
|
||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
||||
|
||||
public DefaultUserManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUser(String userId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
MultivaluedMap<String, Object> formData = new MultivaluedHashMap<String, Object>();
|
||||
formData.add("user", userId);
|
||||
formData.add("password", userId+"pwd");
|
||||
|
||||
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUser(String userId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
try {
|
||||
|
||||
GXInboundResponse response = myManager.path(userId).delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsers() throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
|
||||
@Override
|
||||
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return response.getSource().readEntity(List.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<String> users = delegate.make(call);
|
||||
return users;
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
||||
public interface GroupManagerClient {
|
||||
|
||||
void addUserToGroup(String userId, String groupId) throws StorageHubException;
|
||||
|
||||
void removeUserFromGroup(String userId, String groupId) throws StorageHubException;
|
||||
|
||||
void removeGroup(String groupId) throws StorageHubException;
|
||||
|
||||
void createGroup(String groupId, AccessType accessType, String folderOwner) throws StorageHubException;
|
||||
|
||||
List<String> getUsersOfGroup(String groupId) throws StorageHubException;
|
||||
|
||||
List<String> getGroups() throws StorageHubException;
|
||||
|
||||
void addAdmin(String groupId, String userId) throws StorageHubException;
|
||||
|
||||
void removeAdmin(String groupId, String userId) throws StorageHubException;
|
||||
|
||||
List<String> getAdmins(String groupId) throws StorageHubException;
|
||||
|
||||
}
|
|
@ -49,9 +49,7 @@ public interface ItemManagerClient {
|
|||
|
||||
String changeACL(String id, String user, AccessType accessType) throws StorageHubException;
|
||||
|
||||
/*
|
||||
String removeSharedFolderAdmin(String id, String user) throws StorageHubException;
|
||||
*/
|
||||
String removeAdmin(String id, String user) throws StorageHubException;
|
||||
|
||||
@Deprecated
|
||||
void delete(String id) throws StorageHubException;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
||||
public interface UserManagerClient {
|
||||
|
||||
void createUser(String userId) throws StorageHubException;
|
||||
|
||||
void removeUser(String userId) throws StorageHubException;
|
||||
|
||||
List<String> getUsers() throws StorageHubException;
|
||||
|
||||
}
|
|
@ -75,7 +75,7 @@ public class AddUserToVRes {
|
|||
@Test
|
||||
public void add() throws Exception{
|
||||
String group = "pred4s-preprod-preVRE";
|
||||
URL addGroupUrl = new URL("http://storagehub.pre.d4science.net/storagehub/workspace/groups/"+group+"?gcube-token=a6cec25b-3844-4901-83f3-95eee83319ba-980114272");
|
||||
URL addGroupUrl = new URL("http://storagehub.pre.d4science.net/storagehub/workspace/groups/"+group+"?gcube-token=");
|
||||
|
||||
for (String user : PRE_VRE) {
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,9 @@ import java.io.FileOutputStream;
|
|||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
|
@ -17,6 +19,7 @@ import org.gcube.common.storagehub.client.dsl.FileContainer;
|
|||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
|
||||
import org.gcube.common.storagehub.model.Metadata;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
@ -24,17 +27,72 @@ import org.gcube.common.storagehub.model.items.Item;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.qos.logback.classic.pattern.Util;
|
||||
|
||||
|
||||
|
||||
public class Items {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp(){
|
||||
SecurityTokenProvider.instance.set("9bec07ef-5d19-42ad-8a56-0af28c9b08ed-98187548");
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allRound() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
VREFolderManager vreFolderMaanger = shc.getVreFolderManager(org.gcube.common.storagehub.client.dsl.Util.getVREGroupFromContext("/gcube/devsec/devVreLucio"));
|
||||
vreFolderMaanger.createVRE(AccessType.READ_ONLY, "lucio.lelii");
|
||||
/*vreFolderMaanger.addUser("lucio.lelii");
|
||||
vreFolderMaanger.addUser("massimiliano.assante");
|
||||
vreFolderMaanger.setAdmin("massimiliano.assante");*/
|
||||
vreFolderMaanger.removeVRE();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void creteAndREmoveUser() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.getVreFolderManager("gcube-devsec-devVRE").addUser("gCat");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUserFromVRE() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.getVreFolderManager().removeUser("andrea.rossi");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addUserFromVRE() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.getVreFolderManager().addUser("andrea.rossi");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getAdminsFromVRE() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
for (String user: shc.getVreFolderManager().getAdmins()) {
|
||||
System.out.println(user);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void removeAdminsFromVRE() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.getVreFolderManager().removeAdmin("vfloros");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addAdminToVRE() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.getVreFolderManager().setAdmin("vfloros");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyStatisticaManagerTrash() {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
@ -45,14 +103,26 @@ public class Items {
|
|||
public void forceDelete() throws Exception{
|
||||
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
/*
|
||||
shc.getWSRoot().newFolder("lucioFolderTestMeta","desclucio" );
|
||||
HashMap<String, Object> prop = new HashMap<>();
|
||||
prop.put("folderProp", "test2");
|
||||
prop.put("folderProp2", "test2");
|
||||
*/
|
||||
FolderContainer fc = shc.open("bfb0548b-92d0-47d4-a973-1253dc4694d1").asFolder();
|
||||
|
||||
List<ItemContainer<? extends Item>> children = fc.list().withMetadata().getContainers();
|
||||
|
||||
for (ItemContainer<? extends Item> cont : children) {
|
||||
Metadata m = cont.get().getMetadata();
|
||||
|
||||
for (Object v : m.getMap().values())
|
||||
System.out.println(v.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
long count = shc.getTotalItemCount();
|
||||
|
||||
long volume = shc.getTotalVolume();
|
||||
|
||||
System.out.println("items are "+count+" volume "+volume);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,15 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.Metadata;
|
||||
import org.gcube.common.storagehub.model.Paths;
|
||||
import org.gcube.common.storagehub.model.acls.ACL;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
||||
import org.gcube.common.storagehub.model.expressions.OrderField;
|
||||
|
@ -53,8 +56,19 @@ public class TestCall {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUp(){
|
||||
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUserFromGroup() throws StorageHubException {
|
||||
GroupManagerClient client = AbstractPlugin.groups().build();
|
||||
client.removeUserFromGroup("andrea.rossi", "gcube-devsec-devVRE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addUserToGroup() throws StorageHubException {
|
||||
GroupManagerClient client = AbstractPlugin.groups().build();
|
||||
client.addUserToGroup("andrea.rossi", "gcube-devsec-devVRE");
|
||||
}
|
||||
|
||||
@Test(expected=UserNotAuthorizedException.class)
|
||||
|
@ -312,6 +326,8 @@ public class TestCall {
|
|||
System.out.println("result: "+!b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* private InputStream getThumbnailAsPng(ImagePlus img, int thumbWidth,
|
||||
int thumbHeight) throws IOException {
|
||||
|
||||
|
|
Loading…
Reference in New Issue